From bed7ac0991f08b953f3ce0d57b43e6531bfc8268 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Tue, 28 Jun 2022 09:08:09 +0530 Subject: [PATCH 01/10] feat: add deprecation warnings for legacy API in `RuleTester` --- lib/rule-tester/rule-tester.js | 15 +++ tests/fixtures/testers/rule-tester/no-var.js | 3 +- tests/lib/rule-tester/rule-tester.js | 97 ++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) diff --git a/lib/rule-tester/rule-tester.js b/lib/rule-tester/rule-tester.js index 398f210135b..8a05202f0a2 100644 --- a/lib/rule-tester/rule-tester.js +++ b/lib/rule-tester/rule-tester.js @@ -521,6 +521,21 @@ class RuleTester { ].concat(scenarioErrors).join("\n")); } + if (typeof rule === "function") { + util.deprecate( + () => {}, + `"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules`, + "DEP_ESLINT_LEGACY_RULE_API" + )(); + } + + if (typeof rule === "object" && rule.meta && typeof rule.meta.schema === "undefined") { + util.deprecate( + () => {}, + `"${ruleName}" rule is using the object-style format but is missing the "meta.schema" property. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`, + "DEP_ESLINT_MISSING_RULE_SCHEMA" + )(); + } linter.defineRule(ruleName, Object.assign({}, rule, { diff --git a/tests/fixtures/testers/rule-tester/no-var.js b/tests/fixtures/testers/rule-tester/no-var.js index 5841f15bfa1..f355d626f41 100644 --- a/tests/fixtures/testers/rule-tester/no-var.js +++ b/tests/fixtures/testers/rule-tester/no-var.js @@ -12,7 +12,8 @@ module.exports = { meta: { - fixable: "code" + fixable: "code", + shema: [] }, create(context) { diff --git a/tests/lib/rule-tester/rule-tester.js b/tests/lib/rule-tester/rule-tester.js index ba12bdc38a2..4bdf7f41681 100644 --- a/tests/lib/rule-tester/rule-tester.js +++ b/tests/lib/rule-tester/rule-tester.js @@ -9,6 +9,7 @@ //------------------------------------------------------------------------------ const sinon = require("sinon"), EventEmitter = require("events"), + util = require("util"), { RuleTester } = require("../../../lib/rule-tester"), assert = require("chai").assert, nodeAssert = require("assert"), @@ -2295,6 +2296,102 @@ describe("RuleTester", () => { }); }); + describe("deprecations", () => { + it("should log a deprecation warning when using the legacy function-style API for rule", () => { + + /** + * Legacy-format rule (a function instead of an object with `create` method). + * @param {RuleContext} context The ESLint rule context object. + * @returns {Object} Listeners. + */ + function functionStyleRule(context) { + return { + Program(node) { + context.report({ node, message: "bad" }); + } + }; + } + + const spy = sinon.spy(util, "deprecate"); + + ruleTester.run("functionStyleRule", functionStyleRule, { + valid: [], + invalid: [ + { code: "var foo = bar;", errors: 1 } + ] + }); + + assert.strictEqual(spy.callCount, 1, "calls `util.deprecate()` once"); + assert.strictEqual( + spy.getCall(0).args[1], + "\"functionStyleRule\" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules" + ); + assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_LEGACY_RULE_API"); + + spy.restore(); + }); + + it("should log a deprecation warning when schema is not defined for the rule", () => { + const ruleWithNoSchema = { + meta: { + type: "suggestion" + }, + create(context) { + return { + Program(node) { + context.report({ node, message: "bad" }); + } + }; + } + }; + + const spy = sinon.spy(util, "deprecate"); + + ruleTester.run("ruleWithNoOptions", ruleWithNoSchema, { + valid: [], + invalid: [ + { code: "var foo = bar;", options: [{ foo: true }], errors: 1 } + ] + }); + + assert.strictEqual(spy.callCount, 1, "calls `console.warn` once"); + assert.strictEqual( + spy.getCall(0).args[1], + "\"ruleWithNoOptions\" rule is using the object-style format but is missing the \"meta.schema\" property. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" + ); + assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_MISSING_RULE_SCHEMA"); + + spy.restore(); + }); + + it("should not log a deprecation warning when schema is an empty array", () => { + const ruleWithEmptySchema = { + meta: { + type: "suggestion", + schema: [] + }, + create(context) { + return { + Program(node) { + context.report({ node, message: "bad" }); + } + }; + } + }; + + const spy = sinon.spy(util, "deprecate"); + + ruleTester.run("ruleWithNoOptions", ruleWithEmptySchema, { + valid: [], + invalid: [{ code: "var foo = bar;", errors: 1 }] + }); + + assert.strictEqual(spy.callCount, 0, "never calls `util.deprecate`"); + + spy.restore(); + }); + }); + /** * Asserts that a particular value will be emitted from an EventEmitter. * @param {EventEmitter} emitter The emitter that should emit a value From 462ea92c6877f600c5f993fd6ee94e1e7ab550c8 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Wed, 29 Jun 2022 08:28:23 +0530 Subject: [PATCH 02/10] fix: use unique deprecation code for rules --- lib/rule-tester/rule-tester.js | 17 ++++++++--------- tests/lib/rule-tester/rule-tester.js | 14 +++++++------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/rule-tester/rule-tester.js b/lib/rule-tester/rule-tester.js index 8a05202f0a2..b64a986267d 100644 --- a/lib/rule-tester/rule-tester.js +++ b/lib/rule-tester/rule-tester.js @@ -525,15 +525,7 @@ class RuleTester { util.deprecate( () => {}, `"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules`, - "DEP_ESLINT_LEGACY_RULE_API" - )(); - } - - if (typeof rule === "object" && rule.meta && typeof rule.meta.schema === "undefined") { - util.deprecate( - () => {}, - `"${ruleName}" rule is using the object-style format but is missing the "meta.schema" property. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`, - "DEP_ESLINT_MISSING_RULE_SCHEMA" + `DEP_ESLINT_LEGACY_RULE_API_${ruleName.replace(/-/giu, "_").toUpperCase()}` )(); } @@ -593,6 +585,13 @@ class RuleTester { if (hasOwnProperty(item, "options")) { assert(Array.isArray(item.options), "options must be an array"); + if (item.options.length > 0 && typeof rule === "object" && rule.meta && typeof rule.meta.schema === "undefined") { + util.deprecate( + () => {}, + `"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`, + `DEP_ESLINT_MISSING_SCHEMA_${ruleName.replace(/-/giu, "_").toUpperCase()}` + )(); + } config.rules[ruleName] = [1].concat(item.options); } else { config.rules[ruleName] = 1; diff --git a/tests/lib/rule-tester/rule-tester.js b/tests/lib/rule-tester/rule-tester.js index 4bdf7f41681..4f04891e94d 100644 --- a/tests/lib/rule-tester/rule-tester.js +++ b/tests/lib/rule-tester/rule-tester.js @@ -2314,7 +2314,7 @@ describe("RuleTester", () => { const spy = sinon.spy(util, "deprecate"); - ruleTester.run("functionStyleRule", functionStyleRule, { + ruleTester.run("function-style-rule", functionStyleRule, { valid: [], invalid: [ { code: "var foo = bar;", errors: 1 } @@ -2324,9 +2324,9 @@ describe("RuleTester", () => { assert.strictEqual(spy.callCount, 1, "calls `util.deprecate()` once"); assert.strictEqual( spy.getCall(0).args[1], - "\"functionStyleRule\" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules" + "\"function-style-rule\" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules" ); - assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_LEGACY_RULE_API"); + assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_LEGACY_RULE_API_FUNCTION_STYLE_RULE"); spy.restore(); }); @@ -2347,7 +2347,7 @@ describe("RuleTester", () => { const spy = sinon.spy(util, "deprecate"); - ruleTester.run("ruleWithNoOptions", ruleWithNoSchema, { + ruleTester.run("rule-with-no-options", ruleWithNoSchema, { valid: [], invalid: [ { code: "var foo = bar;", options: [{ foo: true }], errors: 1 } @@ -2357,9 +2357,9 @@ describe("RuleTester", () => { assert.strictEqual(spy.callCount, 1, "calls `console.warn` once"); assert.strictEqual( spy.getCall(0).args[1], - "\"ruleWithNoOptions\" rule is using the object-style format but is missing the \"meta.schema\" property. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" + "\"rule-with-no-options\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" ); - assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_MISSING_RULE_SCHEMA"); + assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_MISSING_SCHEMA_RULE_WITH_NO_OPTIONS"); spy.restore(); }); @@ -2381,7 +2381,7 @@ describe("RuleTester", () => { const spy = sinon.spy(util, "deprecate"); - ruleTester.run("ruleWithNoOptions", ruleWithEmptySchema, { + ruleTester.run("rule-with-no-options", ruleWithEmptySchema, { valid: [], invalid: [{ code: "var foo = bar;", errors: 1 }] }); From 7eee725a3af2794c595b5bc5a4af54a76752a865 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 2 Jul 2022 10:47:35 +0530 Subject: [PATCH 03/10] refactor: avoid using deprecation codes --- lib/rule-tester/rule-tester.js | 50 ++++++++++++++++++++------ tests/lib/rule-tester/rule-tester.js | 53 +++++++++++++++++++--------- 2 files changed, 76 insertions(+), 27 deletions(-) diff --git a/lib/rule-tester/rule-tester.js b/lib/rule-tester/rule-tester.js index b64a986267d..1355e0458df 100644 --- a/lib/rule-tester/rule-tester.js +++ b/lib/rule-tester/rule-tester.js @@ -305,6 +305,36 @@ function getCommentsDeprecation() { ); } +/** + * Emit a deprecation warning if function-style format is being used. + * @param {string} ruleName Name of the rule. + * @returns {void} + */ +function emitLegacyRuleAPIWarning(ruleName) { + if (!emitLegacyRuleAPIWarning[`warned-${ruleName}`]) { + emitLegacyRuleAPIWarning[`warned-${ruleName}`] = true; + util.deprecate( + () => {}, + `"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules` + )(); + } +} + +/** + * Emit a deprecation warning if rule has options but is missing the "meta.schema" property + * @param {string} ruleName Name of the rule. + * @returns {void} + */ +function emitMissingSchemaWarning(ruleName) { + if (!emitMissingSchemaWarning[`warned-${ruleName}`]) { + emitMissingSchemaWarning[`warned-${ruleName}`] = true; + util.deprecate( + () => {}, + `"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas` + )(); + } +} + //------------------------------------------------------------------------------ // Public Interface //------------------------------------------------------------------------------ @@ -522,11 +552,7 @@ class RuleTester { } if (typeof rule === "function") { - util.deprecate( - () => {}, - `"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules`, - `DEP_ESLINT_LEGACY_RULE_API_${ruleName.replace(/-/giu, "_").toUpperCase()}` - )(); + emitLegacyRuleAPIWarning(ruleName); } linter.defineRule(ruleName, Object.assign({}, rule, { @@ -585,12 +611,14 @@ class RuleTester { if (hasOwnProperty(item, "options")) { assert(Array.isArray(item.options), "options must be an array"); - if (item.options.length > 0 && typeof rule === "object" && rule.meta && typeof rule.meta.schema === "undefined") { - util.deprecate( - () => {}, - `"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`, - `DEP_ESLINT_MISSING_SCHEMA_${ruleName.replace(/-/giu, "_").toUpperCase()}` - )(); + if ( + item.options.length > 0 && + typeof rule === "object" && + ( + !rule.meta || (rule.meta && typeof rule.meta.schema === "undefined") + ) + ) { + emitMissingSchemaWarning(ruleName); } config.rules[ruleName] = [1].concat(item.options); } else { diff --git a/tests/lib/rule-tester/rule-tester.js b/tests/lib/rule-tester/rule-tester.js index 4f04891e94d..a965fbca5d7 100644 --- a/tests/lib/rule-tester/rule-tester.js +++ b/tests/lib/rule-tester/rule-tester.js @@ -2297,6 +2297,16 @@ describe("RuleTester", () => { }); describe("deprecations", () => { + let spy; + + beforeEach(() => { + spy = sinon.spy(util, "deprecate"); + }); + + afterEach(() => { + spy.restore(); + }); + it("should log a deprecation warning when using the legacy function-style API for rule", () => { /** @@ -2312,8 +2322,6 @@ describe("RuleTester", () => { }; } - const spy = sinon.spy(util, "deprecate"); - ruleTester.run("function-style-rule", functionStyleRule, { valid: [], invalid: [ @@ -2326,9 +2334,31 @@ describe("RuleTester", () => { spy.getCall(0).args[1], "\"function-style-rule\" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules" ); - assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_LEGACY_RULE_API_FUNCTION_STYLE_RULE"); + }); - spy.restore(); + it("should log a deprecation warning when meta is not defined for the rule", () => { + const ruleWithNoMeta = { + create(context) { + return { + Program(node) { + context.report({ node, message: "bad" }); + } + }; + } + }; + + ruleTester.run("rule-with-no-meta", ruleWithNoMeta, { + valid: [], + invalid: [ + { code: "var foo = bar;", options: [{ foo: true }], errors: 1 } + ] + }); + + assert.strictEqual(spy.callCount, 1, "calls `util.deprecate` once"); + assert.strictEqual( + spy.getCall(0).args[1], + "\"rule-with-no-meta\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" + ); }); it("should log a deprecation warning when schema is not defined for the rule", () => { @@ -2345,23 +2375,18 @@ describe("RuleTester", () => { } }; - const spy = sinon.spy(util, "deprecate"); - - ruleTester.run("rule-with-no-options", ruleWithNoSchema, { + ruleTester.run("rule-with-no-schema", ruleWithNoSchema, { valid: [], invalid: [ { code: "var foo = bar;", options: [{ foo: true }], errors: 1 } ] }); - assert.strictEqual(spy.callCount, 1, "calls `console.warn` once"); + assert.strictEqual(spy.callCount, 1, "calls `util.deprecate` once"); assert.strictEqual( spy.getCall(0).args[1], - "\"rule-with-no-options\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" + "\"rule-with-no-schema\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" ); - assert.strictEqual(spy.getCall(0).args[2], "DEP_ESLINT_MISSING_SCHEMA_RULE_WITH_NO_OPTIONS"); - - spy.restore(); }); it("should not log a deprecation warning when schema is an empty array", () => { @@ -2379,16 +2404,12 @@ describe("RuleTester", () => { } }; - const spy = sinon.spy(util, "deprecate"); - ruleTester.run("rule-with-no-options", ruleWithEmptySchema, { valid: [], invalid: [{ code: "var foo = bar;", errors: 1 }] }); assert.strictEqual(spy.callCount, 0, "never calls `util.deprecate`"); - - spy.restore(); }); }); From 1a723c196f33cde7b65326cfb2c6fdeebbb49fa5 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Tue, 5 Jul 2022 18:09:00 +0530 Subject: [PATCH 04/10] refactor: use object-style syntax --- .../rule-tester/modify-ast-at-first.js | 52 +++++++------- .../testers/rule-tester/modify-ast-at-last.js | 52 +++++++------- .../testers/rule-tester/modify-ast.js | 22 +++--- tests/fixtures/testers/rule-tester/no-eval.js | 28 ++++---- .../testers/rule-tester/no-invalid-args.js | 28 +++++--- .../testers/rule-tester/no-invalid-schema.js | 34 +++++----- .../rule-tester/no-schema-violation.js | 35 +++++----- .../testers/rule-tester/no-test-filename | 24 ++++--- .../testers/rule-tester/no-test-global.js | 34 ++++++---- .../testers/rule-tester/no-test-settings.js | 29 +++++--- tests/fixtures/testers/rule-tester/no-var.js | 5 +- tests/lib/rule-tester/rule-tester.js | 67 ------------------- 12 files changed, 196 insertions(+), 214 deletions(-) diff --git a/tests/fixtures/testers/rule-tester/modify-ast-at-first.js b/tests/fixtures/testers/rule-tester/modify-ast-at-first.js index 831d4a06ca7..a7a80f1f16f 100644 --- a/tests/fixtures/testers/rule-tester/modify-ast-at-first.js +++ b/tests/fixtures/testers/rule-tester/modify-ast-at-first.js @@ -9,30 +9,36 @@ // Rule Definition //------------------------------------------------------------------------------ -module.exports = function(context) { - return { - "Program": function(node) { - node.body.push({ - "type": "Identifier", - "name": "modified", - "range": [0, 8], - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 8 +module.exports = { + meta: { + type: "problem", + schema: [] + }, + create(context) { + return { + "Program": function(node) { + node.body.push({ + "type": "Identifier", + "name": "modified", + "range": [0, 8], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } } - } - }); - }, + }); + }, - "Identifier": function(node) { - if (node.name === "bar") { - context.report({message: "error", node: node}); + "Identifier": function(node) { + if (node.name === "bar") { + context.report({message: "error", node: node}); + } } - } - }; + }; + }, }; diff --git a/tests/fixtures/testers/rule-tester/modify-ast-at-last.js b/tests/fixtures/testers/rule-tester/modify-ast-at-last.js index f093b191c3c..7c7c0c87939 100644 --- a/tests/fixtures/testers/rule-tester/modify-ast-at-last.js +++ b/tests/fixtures/testers/rule-tester/modify-ast-at-last.js @@ -9,30 +9,36 @@ // Rule Definition //------------------------------------------------------------------------------ -module.exports = function(context) { - return { - "Program:exit": function(node) { - node.body.push({ - "type": "Identifier", - "name": "modified", - "range": [0, 8], - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 8 +module.exports = { + meta: { + type: "problem", + schema: [] + }, + create(context) { + return { + "Program:exit": function(node) { + node.body.push({ + "type": "Identifier", + "name": "modified", + "range": [0, 8], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } } - } - }); - }, + }); + }, - "Identifier": function(node) { - if (node.name === "bar") { - context.report({message: "error", node: node}); + "Identifier": function(node) { + if (node.name === "bar") { + context.report({message: "error", node: node}); + } } - } - }; + }; + }, }; diff --git a/tests/fixtures/testers/rule-tester/modify-ast.js b/tests/fixtures/testers/rule-tester/modify-ast.js index 82a7c48ffc5..45f46a662e4 100644 --- a/tests/fixtures/testers/rule-tester/modify-ast.js +++ b/tests/fixtures/testers/rule-tester/modify-ast.js @@ -9,14 +9,20 @@ // Rule Definition //------------------------------------------------------------------------------ -module.exports = function(context) { - return { - "Identifier": function(node) { - node.name += "!"; +module.exports = { + meta: { + type: "problem", + schema: [] + }, + create(context) { + return { + "Identifier": function(node) { + node.name += "!"; - if (node.name === "bar!") { - context.report({message: "error", node: node}); + if (node.name === "bar!") { + context.report({message: "error", node: node}); + } } - } - }; + }; + }, }; diff --git a/tests/fixtures/testers/rule-tester/no-eval.js b/tests/fixtures/testers/rule-tester/no-eval.js index 0d57cb6cd7b..dc6e869888e 100644 --- a/tests/fixtures/testers/rule-tester/no-eval.js +++ b/tests/fixtures/testers/rule-tester/no-eval.js @@ -3,20 +3,24 @@ * @author Nicholas C. Zakas */ +"use strict"; + //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ -module.exports = function(context) { - - "use strict"; - - return { - "CallExpression": function(node) { - if (node.callee.name === "eval") { - context.report(node, "eval sucks."); - } - } - }; - +module.exports = { + meta: { + type: "problem", + schema: [], + }, + create(context) { + return { + CallExpression: function (node) { + if (node.callee.name === "eval") { + context.report(node, "eval sucks."); + } + }, + }; + }, }; diff --git a/tests/fixtures/testers/rule-tester/no-invalid-args.js b/tests/fixtures/testers/rule-tester/no-invalid-args.js index 4c2e7015cbb..e0466b6df1c 100644 --- a/tests/fixtures/testers/rule-tester/no-invalid-args.js +++ b/tests/fixtures/testers/rule-tester/no-invalid-args.js @@ -3,20 +3,28 @@ * @author Mathias Schreck */ +"use strict"; + //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ -module.exports = function(context) { - "use strict"; - - var config = context.options[0]; +module.exports = { + meta: { + fixable: "code", + schema: [{ + type: "boolean" + }] + }, + create(context) { + var config = context.options[0]; - return { - "Program": function(node) { - if (config === true) { - context.report(node, "Invalid args"); + return { + "Program": function(node) { + if (config === true) { + context.report(node, "Invalid args"); + } } - } - }; + }; + } }; diff --git a/tests/fixtures/testers/rule-tester/no-invalid-schema.js b/tests/fixtures/testers/rule-tester/no-invalid-schema.js index fdf290dc62e..affe38053ab 100644 --- a/tests/fixtures/testers/rule-tester/no-invalid-schema.js +++ b/tests/fixtures/testers/rule-tester/no-invalid-schema.js @@ -3,26 +3,26 @@ * @author Brandon Mills */ +"use strict"; + //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ -module.exports = function(context) { - "use strict"; - - var config = context.options[0]; - - return { - "Program": function(node) { - if (config) { - context.report(node, "Expected nothing."); +module.exports = { + meta: { + type: "problem", + schema: [{ + "enum": [] + }] + }, + create(context) { + return { + "Program": function(node) { + if (config) { + context.report(node, "Expected nothing."); + } } - } - }; + }; + }, }; - -module.exports.schema = [ - { - "enum": [] - } -]; diff --git a/tests/fixtures/testers/rule-tester/no-schema-violation.js b/tests/fixtures/testers/rule-tester/no-schema-violation.js index 2a9f65e2161..7876f25305b 100644 --- a/tests/fixtures/testers/rule-tester/no-schema-violation.js +++ b/tests/fixtures/testers/rule-tester/no-schema-violation.js @@ -3,26 +3,27 @@ * @author Brandon Mills */ +"use strict"; + //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ -module.exports = function(context) { - "use strict"; - - var config = context.options[0]; - - return { - "Program": function(node) { - if (config && config !== "foo") { - context.report(node, "Expected foo."); +module.exports = { + meta: { + type: "problem", + schema: [{ + "enum": ["foo"] + }] + }, + create(context) { + const config = context.options[0]; + return { + "Program": function(node) { + if (config && config !== "foo") { + context.report(node, "Expected foo."); + } } - } - }; + }; + }, }; - -module.exports.schema = [ - { - "enum": ["foo"] - } -]; diff --git a/tests/fixtures/testers/rule-tester/no-test-filename b/tests/fixtures/testers/rule-tester/no-test-filename index 752c41f0dbf..add4edff325 100644 --- a/tests/fixtures/testers/rule-tester/no-test-filename +++ b/tests/fixtures/testers/rule-tester/no-test-filename @@ -3,18 +3,24 @@ * @author Stefan Lau */ +"use strict"; + //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ -module.exports = function(context) { - "use strict"; - - return { - "Program": function(node) { - if (context.getFilename() === '') { - context.report(node, "Filename test was not defined."); +module.exports = { + meta: { + fixable: "code", + schema: [] + }, + create(context) { + return { + "Program": function(node) { + if (context.getFilename() === '') { + context.report(node, "Filename test was not defined."); + } } - } - }; + }; + } }; diff --git a/tests/fixtures/testers/rule-tester/no-test-global.js b/tests/fixtures/testers/rule-tester/no-test-global.js index b5fa4c3bf92..6703cc62100 100644 --- a/tests/fixtures/testers/rule-tester/no-test-global.js +++ b/tests/fixtures/testers/rule-tester/no-test-global.js @@ -7,21 +7,27 @@ // Rule Definition //------------------------------------------------------------------------------ -module.exports = function(context) { - "use strict"; +"use strict"; - return { - "Program": function(node) { - var globals = context.getScope().variables.map(function (variable) { - return variable.name; - }); +module.exports = { + meta: { + type: "problem", + schema: [], + }, + create(context) { + return { + "Program": function(node) { + var globals = context.getScope().variables.map(function (variable) { + return variable.name; + }); - if (globals.indexOf("test") === -1) { - context.report(node, "Global variable test was not defined."); + if (globals.indexOf("test") === -1) { + context.report(node, "Global variable test was not defined."); + } + if (globals.indexOf("foo") !== -1) { + context.report(node, "Global variable foo should not be used."); + } } - if (globals.indexOf("foo") !== -1) { - context.report(node, "Global variable foo should not be used."); - } - } - }; + }; + }, }; diff --git a/tests/fixtures/testers/rule-tester/no-test-settings.js b/tests/fixtures/testers/rule-tester/no-test-settings.js index 07ecfa7bca6..a67ebc23ff5 100644 --- a/tests/fixtures/testers/rule-tester/no-test-settings.js +++ b/tests/fixtures/testers/rule-tester/no-test-settings.js @@ -3,18 +3,27 @@ * @author Ilya Volodin */ +"use strict"; + //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ -module.exports = function(context) { - "use strict"; - - return { - "Program": function(node) { - if (!context.settings || !context.settings.test) { - context.report(node, "Global settings test was not defined."); - } - } - }; +module.exports = { + meta: { + type: "problem", + schema: [], + }, + create(context) { + return { + Program: function (node) { + if (!context.settings || !context.settings.test) { + context.report( + node, + "Global settings test was not defined." + ); + } + }, + }; + }, }; diff --git a/tests/fixtures/testers/rule-tester/no-var.js b/tests/fixtures/testers/rule-tester/no-var.js index f355d626f41..96a410fe78a 100644 --- a/tests/fixtures/testers/rule-tester/no-var.js +++ b/tests/fixtures/testers/rule-tester/no-var.js @@ -10,14 +10,11 @@ "use strict"; module.exports = { - meta: { fixable: "code", - shema: [] + schema: [] }, - create(context) { - var sourceCode = context.getSourceCode(); return { diff --git a/tests/lib/rule-tester/rule-tester.js b/tests/lib/rule-tester/rule-tester.js index a965fbca5d7..5dddb43abad 100644 --- a/tests/lib/rule-tester/rule-tester.js +++ b/tests/lib/rule-tester/rule-tester.js @@ -1711,73 +1711,6 @@ describe("RuleTester", () => { }, "Error must specify 'messageId' if 'data' is used."); }); - // fixable rules with or without `meta` property - it("should not throw an error if a rule that has `meta.fixable` produces fixes", () => { - const replaceProgramWith5Rule = { - meta: { - fixable: "code" - }, - create(context) { - return { - Program(node) { - context.report({ node, message: "bad", fix: fixer => fixer.replaceText(node, "5") }); - } - }; - } - }; - - ruleTester.run("replaceProgramWith5", replaceProgramWith5Rule, { - valid: [], - invalid: [ - { code: "var foo = bar;", output: "5", errors: 1 } - ] - }); - }); - it("should throw an error if a new-format rule that doesn't have `meta` produces fixes", () => { - const replaceProgramWith5Rule = { - create(context) { - return { - Program(node) { - context.report({ node, message: "bad", fix: fixer => fixer.replaceText(node, "5") }); - } - }; - } - }; - - assert.throws(() => { - ruleTester.run("replaceProgramWith5", replaceProgramWith5Rule, { - valid: [], - invalid: [ - { code: "var foo = bar;", output: "5", errors: 1 } - ] - }); - }, /Fixable rules must set the `meta\.fixable` property/u); - }); - it("should throw an error if a legacy-format rule produces fixes", () => { - - /** - * Legacy-format rule (a function instead of an object with `create` method). - * @param {RuleContext} context The ESLint rule context object. - * @returns {Object} Listeners. - */ - function replaceProgramWith5Rule(context) { - return { - Program(node) { - context.report({ node, message: "bad", fix: fixer => fixer.replaceText(node, "5") }); - } - }; - } - - assert.throws(() => { - ruleTester.run("replaceProgramWith5", replaceProgramWith5Rule, { - valid: [], - invalid: [ - { code: "var foo = bar;", output: "5", errors: 1 } - ] - }); - }, /Fixable rules must set the `meta\.fixable` property/u); - }); - describe("suggestions", () => { it("should pass with valid suggestions (tested using desc)", () => { ruleTester.run("suggestions-basic", require("../../fixtures/testers/rule-tester/suggestions").basic, { From 967ffb9fe1a7af3a36b1d38717e4688be802d3e6 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Tue, 5 Jul 2022 18:16:56 +0530 Subject: [PATCH 05/10] refactor: use process.emitWarning() --- lib/rule-tester/rule-tester.js | 16 ++++++++-------- tests/lib/rule-tester/rule-tester.js | 17 ++++++++--------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/rule-tester/rule-tester.js b/lib/rule-tester/rule-tester.js index 1355e0458df..80bbef2a921 100644 --- a/lib/rule-tester/rule-tester.js +++ b/lib/rule-tester/rule-tester.js @@ -313,10 +313,10 @@ function getCommentsDeprecation() { function emitLegacyRuleAPIWarning(ruleName) { if (!emitLegacyRuleAPIWarning[`warned-${ruleName}`]) { emitLegacyRuleAPIWarning[`warned-${ruleName}`] = true; - util.deprecate( - () => {}, - `"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules` - )(); + process.emitWarning( + `"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules`, + "DeprecationWarning" + ); } } @@ -328,10 +328,10 @@ function emitLegacyRuleAPIWarning(ruleName) { function emitMissingSchemaWarning(ruleName) { if (!emitMissingSchemaWarning[`warned-${ruleName}`]) { emitMissingSchemaWarning[`warned-${ruleName}`] = true; - util.deprecate( - () => {}, - `"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas` - )(); + process.emitWarning( + `"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`, + "DeprecationWarning" + ); } } diff --git a/tests/lib/rule-tester/rule-tester.js b/tests/lib/rule-tester/rule-tester.js index 5dddb43abad..dc7e5c08b65 100644 --- a/tests/lib/rule-tester/rule-tester.js +++ b/tests/lib/rule-tester/rule-tester.js @@ -9,7 +9,6 @@ //------------------------------------------------------------------------------ const sinon = require("sinon"), EventEmitter = require("events"), - util = require("util"), { RuleTester } = require("../../../lib/rule-tester"), assert = require("chai").assert, nodeAssert = require("assert"), @@ -2233,7 +2232,7 @@ describe("RuleTester", () => { let spy; beforeEach(() => { - spy = sinon.spy(util, "deprecate"); + spy = sinon.spy(process, "emitWarning"); }); afterEach(() => { @@ -2262,9 +2261,9 @@ describe("RuleTester", () => { ] }); - assert.strictEqual(spy.callCount, 1, "calls `util.deprecate()` once"); + assert.strictEqual(spy.callCount, 1, "calls `process.emitWarning()` once"); assert.strictEqual( - spy.getCall(0).args[1], + spy.getCall(0).args[0], "\"function-style-rule\" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules" ); }); @@ -2287,9 +2286,9 @@ describe("RuleTester", () => { ] }); - assert.strictEqual(spy.callCount, 1, "calls `util.deprecate` once"); + assert.strictEqual(spy.callCount, 1, "calls `process.emitWarning()` once"); assert.strictEqual( - spy.getCall(0).args[1], + spy.getCall(0).args[0], "\"rule-with-no-meta\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" ); }); @@ -2315,9 +2314,9 @@ describe("RuleTester", () => { ] }); - assert.strictEqual(spy.callCount, 1, "calls `util.deprecate` once"); + assert.strictEqual(spy.callCount, 1, "calls `process.emitWarning()` once"); assert.strictEqual( - spy.getCall(0).args[1], + spy.getCall(0).args[0], "\"rule-with-no-schema\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" ); }); @@ -2342,7 +2341,7 @@ describe("RuleTester", () => { invalid: [{ code: "var foo = bar;", errors: 1 }] }); - assert.strictEqual(spy.callCount, 0, "never calls `util.deprecate`"); + assert.strictEqual(spy.callCount, 0, "never calls `process.emitWarning()`"); }); }); From c96ef3d3701d0fe29fceca97dde8bbdabedd907d Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 7 Jul 2022 17:47:38 +0530 Subject: [PATCH 06/10] test: add more cases --- tests/lib/rule-tester/rule-tester.js | 151 ++++++++++++++++++++------- 1 file changed, 114 insertions(+), 37 deletions(-) diff --git a/tests/lib/rule-tester/rule-tester.js b/tests/lib/rule-tester/rule-tester.js index dc7e5c08b65..bccfb1817a3 100644 --- a/tests/lib/rule-tester/rule-tester.js +++ b/tests/lib/rule-tester/rule-tester.js @@ -2229,14 +2229,35 @@ describe("RuleTester", () => { }); describe("deprecations", () => { - let spy; + let processStub; + const ruleWithNoSchema = { + meta: { + type: "suggestion" + }, + create(context) { + return { + Program(node) { + context.report({ node, message: "bad" }); + } + }; + } + }; + const ruleWithNoMeta = { + create(context) { + return { + Program(node) { + context.report({ node, message: "bad" }); + } + }; + } + }; beforeEach(() => { - spy = sinon.spy(process, "emitWarning"); + processStub = sinon.stub(process, "emitWarning"); }); afterEach(() => { - spy.restore(); + processStub.restore(); }); it("should log a deprecation warning when using the legacy function-style API for rule", () => { @@ -2261,42 +2282,57 @@ describe("RuleTester", () => { ] }); - assert.strictEqual(spy.callCount, 1, "calls `process.emitWarning()` once"); - assert.strictEqual( - spy.getCall(0).args[0], - "\"function-style-rule\" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules" + assert.strictEqual(processStub.callCount, 1, "calls `process.emitWarning()` once"); + assert.deepStrictEqual( + processStub.getCall(0).args, + [ + "\"function-style-rule\" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules", + "DeprecationWarning" + ] ); }); it("should log a deprecation warning when meta is not defined for the rule", () => { - const ruleWithNoMeta = { - create(context) { - return { - Program(node) { - context.report({ node, message: "bad" }); - } - }; - } - }; - - ruleTester.run("rule-with-no-meta", ruleWithNoMeta, { + ruleTester.run("rule-with-no-meta-1", ruleWithNoMeta, { valid: [], invalid: [ { code: "var foo = bar;", options: [{ foo: true }], errors: 1 } ] }); - assert.strictEqual(spy.callCount, 1, "calls `process.emitWarning()` once"); - assert.strictEqual( - spy.getCall(0).args[0], - "\"rule-with-no-meta\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" + assert.strictEqual(processStub.callCount, 1, "calls `process.emitWarning()` once"); + assert.deepStrictEqual( + processStub.getCall(0).args, + [ + "\"rule-with-no-meta-1\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas", + "DeprecationWarning" + ] ); }); it("should log a deprecation warning when schema is not defined for the rule", () => { - const ruleWithNoSchema = { + ruleTester.run("rule-with-no-schema-1", ruleWithNoSchema, { + valid: [], + invalid: [ + { code: "var foo = bar;", options: [{ foo: true }], errors: 1 } + ] + }); + + assert.strictEqual(processStub.callCount, 1, "calls `process.emitWarning()` once"); + assert.deepStrictEqual( + processStub.getCall(0).args, + [ + "\"rule-with-no-schema-1\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas", + "DeprecationWarning" + ] + ); + }); + + it("should not log a deprecation warning when schema is an empty array", () => { + const ruleWithEmptySchema = { meta: { - type: "suggestion" + type: "suggestion", + schema: [] }, create(context) { return { @@ -2307,25 +2343,32 @@ describe("RuleTester", () => { } }; - ruleTester.run("rule-with-no-schema", ruleWithNoSchema, { + ruleTester.run("rule-with-no-options", ruleWithEmptySchema, { + valid: [], + invalid: [{ code: "var foo = bar;", errors: 1 }] + }); + + assert.strictEqual(processStub.callCount, 0, "never calls `process.emitWarning()`"); + }); + + it("When the rule is an object-style rule, the legacy rule API warning is not emitted", () => { + ruleTester.run("rule-with-no-schema-2", ruleWithNoSchema, { valid: [], invalid: [ - { code: "var foo = bar;", options: [{ foo: true }], errors: 1 } + { code: "var foo = bar;", errors: 1 } ] }); - assert.strictEqual(spy.callCount, 1, "calls `process.emitWarning()` once"); - assert.strictEqual( - spy.getCall(0).args[0], - "\"rule-with-no-schema\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas" - ); + assert.strictEqual(processStub.callCount, 0, "never calls `process.emitWarning()`"); }); - it("should not log a deprecation warning when schema is an empty array", () => { - const ruleWithEmptySchema = { + it("When the rule has meta.schema and there are test cases with options, the missing schema warning is not emitted", () => { + const ruleWithSchema = { meta: { type: "suggestion", - schema: [] + schema: [{ + type: "boolean" + }] }, create(context) { return { @@ -2336,12 +2379,46 @@ describe("RuleTester", () => { } }; - ruleTester.run("rule-with-no-options", ruleWithEmptySchema, { + ruleTester.run("rule-with-schema", ruleWithSchema, { valid: [], - invalid: [{ code: "var foo = bar;", errors: 1 }] + invalid: [ + { code: "var foo = bar;", options: [true], errors: 1 } + ] + }); + + assert.strictEqual(processStub.callCount, 0, "never calls `process.emitWarning()`"); + }); + + it("When the rule does not have meta, but there are no test cases with options, the missing schema warning is not emitted", () => { + ruleTester.run("rule-with-no-meta-2", ruleWithNoMeta, { + valid: [], + invalid: [ + { code: "var foo = bar;", errors: 1 } + ] + }); + + assert.strictEqual(processStub.callCount, 0, "never calls `process.emitWarning()`"); + }); + + it("When the rule has meta without meta.schema, but there are no test cases with options, the missing schema warning is not emitted", () => { + ruleTester.run("rule-with-no-schema-3", ruleWithNoSchema, { + valid: [], + invalid: [ + { code: "var foo = bar;", errors: 1 } + ] + }); + + assert.strictEqual(processStub.callCount, 0, "never calls `process.emitWarning()`"); + }); + it("When the rule has meta without meta.schema, and some test cases have options property but it's an empty array, the missing schema warning is not emitted", () => { + ruleTester.run("rule-with-no-schema-4", ruleWithNoSchema, { + valid: [], + invalid: [ + { code: "var foo = bar;", options: [], errors: 1 } + ] }); - assert.strictEqual(spy.callCount, 0, "never calls `process.emitWarning()`"); + assert.strictEqual(processStub.callCount, 0, "never calls `process.emitWarning()`"); }); }); From 67f88acbc0a1b0bb619e5fd951c4d558e770795e Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 9 Jul 2022 14:32:39 +0530 Subject: [PATCH 07/10] fix: improve check for missing schema --- lib/rule-tester/rule-tester.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rule-tester/rule-tester.js b/lib/rule-tester/rule-tester.js index 80bbef2a921..fe0e468916b 100644 --- a/lib/rule-tester/rule-tester.js +++ b/lib/rule-tester/rule-tester.js @@ -615,7 +615,7 @@ class RuleTester { item.options.length > 0 && typeof rule === "object" && ( - !rule.meta || (rule.meta && typeof rule.meta.schema === "undefined") + !rule.meta || (rule.meta && (typeof rule.meta.schema === "undefined" || rule.meta.schema === null)) ) ) { emitMissingSchemaWarning(ruleName); From 6e8a9b8d8dddd8d786fd58c9d41b7c5cc24bf7fa Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 22 Jul 2022 08:55:41 +0530 Subject: [PATCH 08/10] refactor: update fixtures --- tests/fixtures/testers/rule-tester/no-invalid-args.js | 2 +- tests/fixtures/testers/rule-tester/no-test-filename | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/testers/rule-tester/no-invalid-args.js b/tests/fixtures/testers/rule-tester/no-invalid-args.js index e0466b6df1c..d1eb2ad7199 100644 --- a/tests/fixtures/testers/rule-tester/no-invalid-args.js +++ b/tests/fixtures/testers/rule-tester/no-invalid-args.js @@ -11,7 +11,7 @@ module.exports = { meta: { - fixable: "code", + type: "problem", schema: [{ type: "boolean" }] diff --git a/tests/fixtures/testers/rule-tester/no-test-filename b/tests/fixtures/testers/rule-tester/no-test-filename index add4edff325..b3cde257352 100644 --- a/tests/fixtures/testers/rule-tester/no-test-filename +++ b/tests/fixtures/testers/rule-tester/no-test-filename @@ -11,7 +11,7 @@ module.exports = { meta: { - fixable: "code", + type: "problem", schema: [] }, create(context) { From b23b8c13c2ad731b2b30d810b2928d2c84c2b035 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 23 Jul 2022 08:51:03 +0530 Subject: [PATCH 09/10] test: add test cases when schema is undefined or null --- tests/lib/rule-tester/rule-tester.js | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/lib/rule-tester/rule-tester.js b/tests/lib/rule-tester/rule-tester.js index bccfb1817a3..42ccf0ed503 100644 --- a/tests/lib/rule-tester/rule-tester.js +++ b/tests/lib/rule-tester/rule-tester.js @@ -2328,6 +2328,70 @@ describe("RuleTester", () => { ); }); + it("should log a deprecation warning when schema is `undefined`", () => { + const ruleWithUndefinedSchema = { + meta: { + type: "problem", + schema: undefined + }, + create(context) { + return { + Program(node) { + context.report({ node, message: "bad" }); + } + }; + } + }; + + ruleTester.run("rule-with-undefined-schema", ruleWithUndefinedSchema, { + valid: [], + invalid: [ + { code: "var foo = bar;", options: [{ foo: true }], errors: 1 } + ] + }); + + assert.strictEqual(processStub.callCount, 1, "calls `process.emitWarning()` once"); + assert.deepStrictEqual( + processStub.getCall(0).args, + [ + "\"rule-with-undefined-schema\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas", + "DeprecationWarning" + ] + ); + }); + + it("should log a deprecation warning when schema is `null`", () => { + const ruleWithNullSchema = { + meta: { + type: "problem", + schema: null + }, + create(context) { + return { + Program(node) { + context.report({ node, message: "bad" }); + } + }; + } + }; + + ruleTester.run("rule-with-null-schema", ruleWithNullSchema, { + valid: [], + invalid: [ + { code: "var foo = bar;", options: [{ foo: true }], errors: 1 } + ] + }); + + assert.strictEqual(processStub.callCount, 1, "calls `process.emitWarning()` once"); + assert.deepStrictEqual( + processStub.getCall(0).args, + [ + "\"rule-with-null-schema\" rule has options but is missing the \"meta.schema\" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas", + "DeprecationWarning" + ] + ); + }); + it("should not log a deprecation warning when schema is an empty array", () => { const ruleWithEmptySchema = { meta: { From 9bdb8fa553a2bb3fdc187000b722e24ff7d90b71 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 23 Jul 2022 09:10:28 +0530 Subject: [PATCH 10/10] fix: lint --- tests/lib/rule-tester/rule-tester.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/rule-tester/rule-tester.js b/tests/lib/rule-tester/rule-tester.js index 42ccf0ed503..0e35258750c 100644 --- a/tests/lib/rule-tester/rule-tester.js +++ b/tests/lib/rule-tester/rule-tester.js @@ -2332,6 +2332,7 @@ describe("RuleTester", () => { const ruleWithUndefinedSchema = { meta: { type: "problem", + // eslint-disable-next-line no-undefined -- intentioally added for test case schema: undefined }, create(context) {