diff --git a/tests/index.js b/tests/index.js index 9f7a052943..3539f48136 100644 --- a/tests/index.js +++ b/tests/index.js @@ -10,6 +10,7 @@ const plugin = require('..'); const index = require('../lib/rules'); const ruleFiles = fs.readdirSync(path.resolve(__dirname, '../lib/rules/')) + .filter((f) => f.endsWith('.js')) .map((f) => path.basename(f, '.js')) .filter((f) => f !== 'index'); diff --git a/tests/lib/rules/jsx-uses-react.js b/tests/lib/rules/jsx-uses-react.js index 3a8e39013c..381b44bc89 100644 --- a/tests/lib/rules/jsx-uses-react.js +++ b/tests/lib/rules/jsx-uses-react.js @@ -60,28 +60,67 @@ ruleTester.run('no-unused-vars', rule, { invalid: parsers.all([ { code: '/*eslint react/jsx-uses-react:1*/ var React;', - errors: [{ message: '\'React\' is defined but never used.' }], + errors: [{ + message: '\'React\' is defined but never used.', + suggestions: [{ + messageId: 'removeVar', + output: '/*eslint react/jsx-uses-react:1*/ ', + }], + }], }, { code: '/*eslint react/jsx-uses-react:1*/ /** @jsx Foo */ var React;
;', - errors: [{ message: '\'React\' is defined but never used.' }], + errors: [{ + message: '\'React\' is defined but never used.', + suggestions: [{ + messageId: 'removeVar', + output: '/*eslint react/jsx-uses-react:1*/ /** @jsx Foo */ ;', + }], + }], }, { code: '/*eslint react/jsx-uses-react:1*/ var React; ;', - errors: [{ message: '\'React\' is defined but never used.' }], + errors: [{ + message: '\'React\' is defined but never used.', + suggestions: [{ + messageId: 'removeVar', + output: '/*eslint react/jsx-uses-react:1*/ ;', + }], + }], settings, }, { code: '/*eslint react/jsx-uses-react:1*/ var Frag; <>>;', - errors: [{ message: '\'Frag\' is defined but never used.' }], + errors: [{ + message: '\'Frag\' is defined but never used.', + suggestions: [{ + messageId: 'removeVar', + output: '/*eslint react/jsx-uses-react:1*/ <>>;', + }], + }], features: ['fragment'], settings: { react: { fragment: 'Fragment' } }, }, { code: '/*eslint react/jsx-uses-react:1*/ var React; <>>;', features: ['fragment'], - errors: [{ message: '\'React\' is defined but never used.' }], + errors: [{ + message: '\'React\' is defined but never used.', + suggestions: [{ + messageId: 'removeVar', + output: '/*eslint react/jsx-uses-react:1*/ <>>;', + }], + }], settings, }, - ].map(parsers.disableNewTS)), + ].map(parsers.disableNewTS).map((test) => { + if (!rule.meta.hasSuggestions) { + test.errors = test.errors.map((error) => { + // https://github.com/eslint/eslint/pull/18352 added suggestions to no-unused-vars in eslint v9.17.0 + delete error.suggestions; + return error; + }); + } + return test; + })), }); diff --git a/tests/lib/rules/jsx-uses-vars.js b/tests/lib/rules/jsx-uses-vars.js index 00f801fd65..8b9db2a956 100644 --- a/tests/lib/rules/jsx-uses-vars.js +++ b/tests/lib/rules/jsx-uses-vars.js @@ -10,6 +10,7 @@ // ----------------------------------------------------------------------------- const ruleNoUnusedVars = require('../../helpers/getESLintCoreRule')('no-unused-vars'); + const rulePreferConst = require('../../helpers/getESLintCoreRule')('prefer-const'); const RuleTester = require('../../helpers/ruleTester'); @@ -136,7 +137,13 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { invalid: parsers.all([ { code: '/* eslint react/jsx-uses-vars: 1 */ var App;', - errors: [{ message: '\'App\' is defined but never used.' }], + errors: [{ + message: '\'App\' is defined but never used.', + suggestions: [{ + messageId: 'removeVar', + output: '/* eslint react/jsx-uses-vars: 1 */ ', + }], + }], }, { code: ` @@ -145,7 +152,18 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { var unused; React.render(