From c9b60a6d556cce989928bbab21586c44fd12bd6a Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Tue, 21 May 2024 01:38:00 +0200 Subject: [PATCH 1/7] [Tests] remove duplicate tests --- tests/lib/rules/destructuring-assignment.js | 12 ------- tests/lib/rules/display-name.js | 33 ------------------- tests/lib/rules/forbid-component-props.js | 15 --------- tests/lib/rules/jsx-curly-brace-presence.js | 6 ---- tests/lib/rules/jsx-curly-spacing.js | 8 ----- tests/lib/rules/jsx-handler-names.js | 2 +- tests/lib/rules/jsx-no-leaked-render.js | 8 ----- .../lib/rules/jsx-one-expression-per-line.js | 20 ----------- tests/lib/rules/jsx-wrap-multilines.js | 10 ------ .../no-redundant-should-component-update.js | 10 ------ tests/lib/rules/prop-types.js | 30 ----------------- tests/lib/rules/react-in-jsx-scope.js | 3 -- tests/lib/rules/require-default-props.js | 24 -------------- 13 files changed, 1 insertion(+), 180 deletions(-) diff --git a/tests/lib/rules/destructuring-assignment.js b/tests/lib/rules/destructuring-assignment.js index 18c88e1cfe..dd3b6e94f9 100644 --- a/tests/lib/rules/destructuring-assignment.js +++ b/tests/lib/rules/destructuring-assignment.js @@ -374,18 +374,6 @@ ruleTester.run('destructuring-assignment', rule, { code: ` import { useContext } from 'react'; - const MyComponent = (props) => { - const {foo} = useContext(aContext); - return
{foo}
- }; - `, - options: ['always'], - settings: { react: { version: '16.9.0' } }, - }, - { - code: ` - import { useContext } from 'react'; - const MyComponent = (props) => { const foo = useContext(aContext); return
{foo.test}
diff --git a/tests/lib/rules/display-name.js b/tests/lib/rules/display-name.js index da73207a5c..00d8c6e26f 100644 --- a/tests/lib/rules/display-name.js +++ b/tests/lib/rules/display-name.js @@ -369,39 +369,6 @@ ruleTester.run('display-name', rule, { }; `, }, - { - code: ` - import React, {createElement} from "react"; - const SomeComponent = (props) => { - const {foo, bar} = props; - return someComponentFactory({ - onClick: () => foo(bar("x")) - }); - }; - `, - }, - { - code: ` - import React, {Component} from "react"; - function someDecorator(ComposedComponent) { - return class MyDecorator extends Component { - render() {return ;} - }; - } - module.exports = someDecorator; - `, - }, - { - code: ` - import React, {Component} from "react"; - function someDecorator(ComposedComponent) { - return class MyDecorator extends Component { - render() {return ;} - }; - } - module.exports = someDecorator; - `, - }, { code: ` const element = ( diff --git a/tests/lib/rules/forbid-component-props.js b/tests/lib/rules/forbid-component-props.js index 5f1aa7e68d..fbe4501c6e 100644 --- a/tests/lib/rules/forbid-component-props.js +++ b/tests/lib/rules/forbid-component-props.js @@ -166,21 +166,6 @@ ruleTester.run('forbid-component-props', rule, { }, ], }, - { - code: ` - const item = (); - `, - options: [ - { - forbid: [ - { - propName: 'className', - disallowedFor: ['ReactModal'], - }, - ], - }, - ], - }, { code: ` diff --git a/tests/lib/rules/jsx-curly-brace-presence.js b/tests/lib/rules/jsx-curly-brace-presence.js index 616ffba21d..c2a8a9c1d9 100755 --- a/tests/lib/rules/jsx-curly-brace-presence.js +++ b/tests/lib/rules/jsx-curly-brace-presence.js @@ -657,12 +657,6 @@ ruleTester.run('jsx-curly-brace-presence', rule, { options: [{ props: 'always' }], errors: [{ messageId: 'missingCurly' }], }, - { - code: `foo`, - output: `foo`, - options: [{ props: 'always' }], - errors: [{ messageId: 'missingCurly' }], - }, { code: 'foo bar ', output: `{"foo bar "}`, diff --git a/tests/lib/rules/jsx-curly-spacing.js b/tests/lib/rules/jsx-curly-spacing.js index 3eec41b99a..89571a51f8 100644 --- a/tests/lib/rules/jsx-curly-spacing.js +++ b/tests/lib/rules/jsx-curly-spacing.js @@ -756,14 +756,6 @@ ruleTester.run('jsx-curly-spacing', rule, { `, options: ['always'], }, - { - code: ` - ; - `, - options: ['always'], - }, { code: ` ', + code: '', errors: [ { messageId: 'badPropKey', diff --git a/tests/lib/rules/jsx-no-leaked-render.js b/tests/lib/rules/jsx-no-leaked-render.js index a6742a29cd..a86513addb 100644 --- a/tests/lib/rules/jsx-no-leaked-render.js +++ b/tests/lib/rules/jsx-no-leaked-render.js @@ -126,14 +126,6 @@ ruleTester.run('jsx-no-leaked-render', rule, { `, options: [{ validStrategies: ['coerce', 'ternary'] }], }, - { - code: ` - const Component = ({ elements, count }) => { - return
{!!count && }
- } - `, - options: [{ validStrategies: ['coerce'] }], - }, // Fixes for: // - https://github.com/jsx-eslint/eslint-plugin-react/issues/3292 diff --git a/tests/lib/rules/jsx-one-expression-per-line.js b/tests/lib/rules/jsx-one-expression-per-line.js index 62afc430d4..344cc15c4b 100644 --- a/tests/lib/rules/jsx-one-expression-per-line.js +++ b/tests/lib/rules/jsx-one-expression-per-line.js @@ -937,26 +937,6 @@ foo - - `, - errors: [ - { - messageId: 'moveToNewLine', - data: { descriptor: 'Foo' }, - }, - ], - parserOptions, - }, - { - code: ` - - - `, - output: ` - - `, errors: [ diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index 36efd2f8f5..86cdc1ce2d 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -1393,16 +1393,6 @@ ruleTester.run('jsx-wrap-multilines', rule, { { messageId: 'parensOnNewLines' }, ], }, - { - code: DECLARATION_TERNARY_PAREN_FRAGMENT, - features: ['fragment'], - output: addNewLineSymbols(DECLARATION_TERNARY_PAREN_FRAGMENT), - options: [{ declaration: 'parens-new-line' }], - errors: [ - { messageId: 'parensOnNewLines' }, - { messageId: 'parensOnNewLines' }, - ], - }, { code: ASSIGNMENT_TERNARY_NO_PAREN, output: addNewLineSymbols(ASSIGNMENT_TERNARY_PAREN), diff --git a/tests/lib/rules/no-redundant-should-component-update.js b/tests/lib/rules/no-redundant-should-component-update.js index 88e5a3e519..413e6699e7 100644 --- a/tests/lib/rules/no-redundant-should-component-update.js +++ b/tests/lib/rules/no-redundant-should-component-update.js @@ -37,16 +37,6 @@ ruleTester.run('no-redundant-should-component-update', rule, { `, parserOptions, }, - { - code: ` - class Foo extends React.Component { - shouldComponentUpdate() { - return true; - } - } - `, - parserOptions, - }, { code: ` class Foo extends React.Component { diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 638861e2bb..3f90c8a67d 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -1588,15 +1588,6 @@ ruleTester.run('prop-types', rule, { } `, }, - { - // Async generator functions can't be components. - code: ` - var Hello = async function* (props) { - yield null; - return
Hello {props.name}
; - } - `, - }, { // Flow annotations with variance code: ` @@ -5320,27 +5311,6 @@ ruleTester.run('prop-types', rule, { }, ], }, - { - code: ` - class Test extends Foo.Component { - render() { - return ( -
{this.props.firstname} {this.props.lastname}
- ); - } - } - Test.propTypes = { - firstname: PropTypes.string - }; - `, - settings, - errors: [ - { - messageId: 'missingPropType', - data: { name: 'lastname' }, - }, - ], - }, { code: ` class Test extends Foo.Component { diff --git a/tests/lib/rules/react-in-jsx-scope.js b/tests/lib/rules/react-in-jsx-scope.js index bc82a6c44f..c203c665ba 100644 --- a/tests/lib/rules/react-in-jsx-scope.js +++ b/tests/lib/rules/react-in-jsx-scope.js @@ -44,9 +44,6 @@ ruleTester.run('react-in-jsx-scope', rule, { { code: 'var React; ;' }, { code: 'var React, App, a=1; ;' }, { code: 'var React, App, a=1; function elem() { return ; }' }, - { - code: 'var React, App; ;', - }, { code: '/** @jsx Foo */ var Foo, App; ;' }, { code: '/** @jsx Foo.Bar */ var Foo, App; ;' }, { diff --git a/tests/lib/rules/require-default-props.js b/tests/lib/rules/require-default-props.js index 8ba5d53d7c..4c68b92f65 100644 --- a/tests/lib/rules/require-default-props.js +++ b/tests/lib/rules/require-default-props.js @@ -3019,30 +3019,6 @@ ruleTester.run('require-default-props', rule, { }, ], }, - { - code: ` - function MyStatelessComponent({ foo, bar }) { - return
{foo}{bar}
; - } - MyStatelessComponent.propTypes = { - foo: PropTypes.string, - bar: PropTypes.string.isRequired - }; - MyStatelessComponent.propTypes.baz = React.propTypes.string; - `, - errors: [ - { - messageId: 'shouldHaveDefault', - data: { name: 'foo' }, - line: 6, - }, - { - messageId: 'shouldHaveDefault', - data: { name: 'baz' }, - line: 9, - }, - ], - }, { code: ` From 84781c786d117f732eeb09345fcfbcaf2daec1f0 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Mon, 20 May 2024 21:01:10 +0200 Subject: [PATCH 2/7] [Tests] `hook-use-state`: test suggestions with `messageId` instead of `desc` --- tests/lib/rules/hook-use-state.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/lib/rules/hook-use-state.js b/tests/lib/rules/hook-use-state.js index 1cadaf8a1a..b5a4cd796d 100644 --- a/tests/lib/rules/hook-use-state.js +++ b/tests/lib/rules/hook-use-state.js @@ -311,6 +311,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { + messageId: 'suggestPair', output: ` import { useState } from 'react' function useColor() { @@ -334,7 +335,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { - desc: 'Replace useState call with useMemo', + messageId: 'suggestMemo', output: ` import { useState, useMemo } from 'react' function useColor(initialColor) { @@ -343,7 +344,7 @@ const tests = { `, }, { - desc: 'Destructure useState call into value + setter pair', + messageId: 'suggestPair', output: ` import { useState } from 'react' function useColor(initialColor) { @@ -366,7 +367,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { - desc: 'Replace useState call with useMemo', + messageId: 'suggestMemo', output: ` import { useState, useMemo as useMemoAlternative } from 'react' function useColor(initialColor) { @@ -375,7 +376,7 @@ const tests = { `, }, { - desc: 'Destructure useState call into value + setter pair', + messageId: 'suggestPair', output: ` import { useState, useMemo as useMemoAlternative } from 'react' function useColor(initialColor) { @@ -398,7 +399,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { - desc: 'Replace useState call with useMemo', + messageId: 'suggestMemo', output: ` import React from 'react' function useColor(initialColor) { @@ -407,7 +408,7 @@ const tests = { `, }, { - desc: 'Destructure useState call into value + setter pair', + messageId: 'suggestPair', output: ` import React from 'react' function useColor(initialColor) { @@ -432,6 +433,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { + messageId: 'suggestPair', output: ` import { useState } from 'react' function useColor() { @@ -457,6 +459,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { + messageId: 'suggestPair', output: ` import { useState } from 'react' function useColor() { @@ -486,6 +489,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { + messageId: 'suggestPair', output: ` import { useState } from 'react' const [color, setColor] = useState() @@ -505,6 +509,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { + messageId: 'suggestPair', output: ` import { useState } from 'react' const [color, setColor] = useState() @@ -561,6 +566,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { + messageId: 'suggestPair', output: ` import { useState } from 'react' const [color, setColor] = useState() @@ -584,6 +590,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { + messageId: 'suggestPair', output: ` import { useState } from 'react' function useColor() { @@ -610,6 +617,7 @@ const tests = { message: 'useState call is not destructured into value + setter pair', suggestions: [ { + messageId: 'suggestPair', output: ` import React from 'react' function useColor() { From 0effd6247ccc1c41d6b2d7753af4a84cc4b95d3c Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Sun, 19 May 2024 20:49:53 +0200 Subject: [PATCH 3/7] [Tests] test rules with ESLint v9 --- .github/workflows/node-18+.yml | 1 + tests/helpers/ruleTester.js | 109 ++++++++++++++++++ tests/lib/rules/boolean-prop-naming.js | 2 +- tests/lib/rules/button-has-type.js | 2 +- .../checked-requires-onchange-or-readonly.js | 2 +- .../rules/default-props-match-prop-types.js | 2 +- tests/lib/rules/destructuring-assignment.js | 2 +- tests/lib/rules/display-name.js | 2 +- tests/lib/rules/forbid-component-props.js | 2 +- tests/lib/rules/forbid-dom-props.js | 2 +- tests/lib/rules/forbid-elements.js | 2 +- tests/lib/rules/forbid-foreign-prop-types.js | 2 +- tests/lib/rules/forbid-prop-types.js | 2 +- .../rules/function-component-definition.js | 2 +- tests/lib/rules/hook-use-state.js | 2 +- tests/lib/rules/iframe-missing-sandbox.js | 2 +- tests/lib/rules/jsx-boolean-value.js | 2 +- tests/lib/rules/jsx-child-element-spacing.js | 2 +- .../lib/rules/jsx-closing-bracket-location.js | 2 +- tests/lib/rules/jsx-closing-tag-location.js | 2 +- tests/lib/rules/jsx-curly-brace-presence.js | 2 +- tests/lib/rules/jsx-curly-newline.js | 2 +- tests/lib/rules/jsx-curly-spacing.js | 2 +- tests/lib/rules/jsx-equals-spacing.js | 2 +- tests/lib/rules/jsx-filename-extension.js | 2 +- tests/lib/rules/jsx-first-prop-new-line.js | 2 +- tests/lib/rules/jsx-fragments.js | 2 +- tests/lib/rules/jsx-handler-names.js | 2 +- tests/lib/rules/jsx-indent-props.js | 2 +- tests/lib/rules/jsx-indent.js | 2 +- tests/lib/rules/jsx-key.js | 2 +- tests/lib/rules/jsx-max-depth.js | 2 +- tests/lib/rules/jsx-max-props-per-line.js | 2 +- tests/lib/rules/jsx-newline.js | 2 +- tests/lib/rules/jsx-no-bind.js | 2 +- tests/lib/rules/jsx-no-comment-textnodes.js | 2 +- .../jsx-no-constructed-context-values.js | 2 +- tests/lib/rules/jsx-no-duplicate-props.js | 2 +- tests/lib/rules/jsx-no-leaked-render.js | 2 +- tests/lib/rules/jsx-no-literals.js | 2 +- tests/lib/rules/jsx-no-script-url.js | 2 +- tests/lib/rules/jsx-no-target-blank.js | 2 +- tests/lib/rules/jsx-no-undef.js | 16 ++- tests/lib/rules/jsx-no-useless-fragment.js | 2 +- .../lib/rules/jsx-one-expression-per-line.js | 2 +- tests/lib/rules/jsx-pascal-case.js | 2 +- tests/lib/rules/jsx-props-no-multi-spaces.js | 2 +- tests/lib/rules/jsx-props-no-spread-multi.js | 2 +- tests/lib/rules/jsx-props-no-spreading.js | 2 +- tests/lib/rules/jsx-sort-default-props.js | 2 +- tests/lib/rules/jsx-sort-props.js | 2 +- tests/lib/rules/jsx-space-before-closing.js | 2 +- tests/lib/rules/jsx-tag-spacing.js | 2 +- tests/lib/rules/jsx-uses-react.js | 28 ++--- tests/lib/rules/jsx-uses-vars.js | 54 ++++----- tests/lib/rules/jsx-wrap-multilines.js | 2 +- .../lib/rules/no-access-state-in-setstate.js | 2 +- .../lib/rules/no-adjacent-inline-elements.js | 2 +- tests/lib/rules/no-array-index-key.js | 2 +- .../lib/rules/no-arrow-function-lifecycle.js | 2 +- tests/lib/rules/no-children-prop.js | 2 +- tests/lib/rules/no-danger-with-children.js | 2 +- tests/lib/rules/no-danger.js | 2 +- tests/lib/rules/no-deprecated.js | 2 +- tests/lib/rules/no-did-mount-set-state.js | 2 +- tests/lib/rules/no-did-update-set-state.js | 2 +- tests/lib/rules/no-direct-mutation-state.js | 2 +- tests/lib/rules/no-find-dom-node.js | 2 +- tests/lib/rules/no-invalid-html-attribute.js | 2 +- tests/lib/rules/no-is-mounted.js | 2 +- tests/lib/rules/no-multi-comp.js | 2 +- tests/lib/rules/no-namespace.js | 2 +- .../rules/no-object-type-as-default-prop.js | 2 +- .../no-redundant-should-component-update.js | 2 +- tests/lib/rules/no-render-return-value.js | 2 +- tests/lib/rules/no-set-state.js | 2 +- tests/lib/rules/no-string-refs.js | 2 +- tests/lib/rules/no-this-in-sfc.js | 2 +- tests/lib/rules/no-typos.js | 2 +- tests/lib/rules/no-unescaped-entities.js | 2 +- tests/lib/rules/no-unknown-property.js | 2 +- tests/lib/rules/no-unsafe.js | 2 +- .../rules/no-unstable-nested-components.js | 2 +- .../no-unused-class-component-methods.js | 2 +- tests/lib/rules/no-unused-prop-types.js | 2 +- tests/lib/rules/no-unused-state.js | 2 +- tests/lib/rules/no-will-update-set-state.js | 2 +- tests/lib/rules/prefer-es6-class.js | 2 +- tests/lib/rules/prefer-exact-props.js | 2 +- tests/lib/rules/prefer-read-only-props.js | 2 +- tests/lib/rules/prefer-stateless-function.js | 2 +- tests/lib/rules/prop-types.js | 2 +- tests/lib/rules/react-in-jsx-scope.js | 2 +- tests/lib/rules/require-default-props.js | 2 +- tests/lib/rules/require-optimization.js | 2 +- tests/lib/rules/require-render-return.js | 2 +- tests/lib/rules/self-closing-comp.js | 2 +- tests/lib/rules/sort-comp.js | 2 +- tests/lib/rules/sort-default-props.js | 2 +- tests/lib/rules/sort-prop-types.js | 2 +- tests/lib/rules/state-in-constructor.js | 2 +- tests/lib/rules/static-property-placement.js | 2 +- tests/lib/rules/style-prop-object.js | 2 +- .../rules/void-dom-elements-no-children.js | 2 +- tests/util/Components.js | 4 +- 105 files changed, 263 insertions(+), 147 deletions(-) create mode 100644 tests/helpers/ruleTester.js diff --git a/.github/workflows/node-18+.yml b/.github/workflows/node-18+.yml index e27cb0e7bf..7dcb4daff5 100644 --- a/.github/workflows/node-18+.yml +++ b/.github/workflows/node-18+.yml @@ -26,6 +26,7 @@ jobs: matrix: node-version: ${{ fromJson(needs.matrix.outputs.latest) }} eslint: + - 9 - 8 - 7 - 6 diff --git a/tests/helpers/ruleTester.js b/tests/helpers/ruleTester.js new file mode 100644 index 0000000000..f754c13e04 --- /dev/null +++ b/tests/helpers/ruleTester.js @@ -0,0 +1,109 @@ +'use strict'; + +const ESLintRuleTester = require('eslint').RuleTester; +const semver = require('semver'); +const eslintPkg = require('eslint/package.json'); + +// `item` can be a config passed to the constructor, or a test case object/string +function convertToFlat(item, plugins) { + if (typeof item === 'string') { + return item; + } + + if (typeof item !== 'object' || item === null) { + throw new TypeError('Invalid value for "item" option. Expected an object or a string.'); + } + + const newItem = Object.assign({}, item, { languageOptions: {} }); + + if (newItem.parserOptions) { + newItem.languageOptions.parserOptions = newItem.parserOptions; + + if (newItem.parserOptions.ecmaVersion) { + newItem.languageOptions.ecmaVersion = newItem.parserOptions.ecmaVersion; + } + + if (newItem.parserOptions.sourceType) { + newItem.languageOptions.sourceType = newItem.parserOptions.sourceType; + } + + delete newItem.parserOptions; + } + + if (newItem.parser) { + newItem.languageOptions.parser = require(newItem.parser); // eslint-disable-line global-require, import/no-dynamic-require + delete newItem.parser; + } + + if (newItem.globals) { + newItem.languageOptions.globals = newItem.globals; + delete newItem.globals; + } + + if (plugins) { + newItem.plugins = plugins; + } + + return newItem; +} + +let RuleTester = ESLintRuleTester; + +if (semver.major(eslintPkg.version) >= 9) { + const PLUGINS = Symbol('eslint-plugin-react plugins'); + const RULE_DEFINER = Symbol.for('react.RuleTester.RuleDefiner'); + + RuleTester = class extends ESLintRuleTester { + constructor(config) { + if ((typeof config !== 'object' && typeof config !== 'undefined') || config === null) { + throw new TypeError('Invalid value for "config" option. Expected an object or undefined.'); + } + + const newConfig = convertToFlat(config || {}); + + if (!newConfig.languageOptions.ecmaVersion) { + newConfig.languageOptions.ecmaVersion = 5; // old default + } + + if (!newConfig.languageOptions.sourceType) { + newConfig.languageOptions.sourceType = 'script'; // old default + } + + super(newConfig); + + this[RULE_DEFINER] = { + defineRule: (ruleId, rule) => { + if (!this[PLUGINS]) { + this[PLUGINS] = {}; + } + + const ruleIdSplit = ruleId.split('/'); + + if (ruleIdSplit.length !== 2) { + throw new Error('ruleId should be in the format: plugin-name/rule-name'); + } + + const pluginName = ruleIdSplit[0]; + const ruleName = ruleIdSplit[1]; + + if (!this[PLUGINS][pluginName]) { + this[PLUGINS][pluginName] = { rules: {} }; + } + + this[PLUGINS][pluginName].rules[ruleName] = rule; + }, + }; + } + + run(ruleName, rule, tests) { + const newTests = { + valid: tests.valid.map((test) => convertToFlat(test, this[PLUGINS])), + invalid: tests.invalid.map((test) => convertToFlat(test, this[PLUGINS])), + }; + + super.run(ruleName, rule, newTests); + } + }; +} + +module.exports = RuleTester; diff --git a/tests/lib/rules/boolean-prop-naming.js b/tests/lib/rules/boolean-prop-naming.js index 10ff9097f2..ac592361cd 100644 --- a/tests/lib/rules/boolean-prop-naming.js +++ b/tests/lib/rules/boolean-prop-naming.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/boolean-prop-naming'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/button-has-type.js b/tests/lib/rules/button-has-type.js index fb16f28aa5..1f9819ada8 100644 --- a/tests/lib/rules/button-has-type.js +++ b/tests/lib/rules/button-has-type.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/button-has-type'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/checked-requires-onchange-or-readonly.js b/tests/lib/rules/checked-requires-onchange-or-readonly.js index 93e08ef60e..1f8bb551db 100644 --- a/tests/lib/rules/checked-requires-onchange-or-readonly.js +++ b/tests/lib/rules/checked-requires-onchange-or-readonly.js @@ -5,7 +5,7 @@ 'use strict'; -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/checked-requires-onchange-or-readonly'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/default-props-match-prop-types.js b/tests/lib/rules/default-props-match-prop-types.js index 9759fad635..fdc86dc357 100644 --- a/tests/lib/rules/default-props-match-prop-types.js +++ b/tests/lib/rules/default-props-match-prop-types.js @@ -10,7 +10,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/default-props-match-prop-types'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/destructuring-assignment.js b/tests/lib/rules/destructuring-assignment.js index dd3b6e94f9..e1f8e85b08 100644 --- a/tests/lib/rules/destructuring-assignment.js +++ b/tests/lib/rules/destructuring-assignment.js @@ -4,9 +4,9 @@ 'use strict'; -const RuleTester = require('eslint').RuleTester; const semver = require('semver'); const eslintPkg = require('eslint/package.json'); +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/destructuring-assignment'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/display-name.js b/tests/lib/rules/display-name.js index 00d8c6e26f..18fd1ca83c 100644 --- a/tests/lib/rules/display-name.js +++ b/tests/lib/rules/display-name.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/display-name'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/forbid-component-props.js b/tests/lib/rules/forbid-component-props.js index fbe4501c6e..baf02e44a3 100644 --- a/tests/lib/rules/forbid-component-props.js +++ b/tests/lib/rules/forbid-component-props.js @@ -8,7 +8,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/forbid-component-props'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/forbid-dom-props.js b/tests/lib/rules/forbid-dom-props.js index 157e4950be..a11d39fe00 100644 --- a/tests/lib/rules/forbid-dom-props.js +++ b/tests/lib/rules/forbid-dom-props.js @@ -8,7 +8,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/forbid-dom-props'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/forbid-elements.js b/tests/lib/rules/forbid-elements.js index 0a80c3f853..d0c179b131 100644 --- a/tests/lib/rules/forbid-elements.js +++ b/tests/lib/rules/forbid-elements.js @@ -8,7 +8,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/forbid-elements'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/forbid-foreign-prop-types.js b/tests/lib/rules/forbid-foreign-prop-types.js index c7ee08d80f..000d7eb4a9 100644 --- a/tests/lib/rules/forbid-foreign-prop-types.js +++ b/tests/lib/rules/forbid-foreign-prop-types.js @@ -8,7 +8,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/forbid-foreign-prop-types'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/forbid-prop-types.js b/tests/lib/rules/forbid-prop-types.js index ad7ca97c66..67ac1b47f6 100644 --- a/tests/lib/rules/forbid-prop-types.js +++ b/tests/lib/rules/forbid-prop-types.js @@ -10,7 +10,7 @@ const babelEslintVersion = require('babel-eslint/package.json').version; const semver = require('semver'); -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/forbid-prop-types'); diff --git a/tests/lib/rules/function-component-definition.js b/tests/lib/rules/function-component-definition.js index f5282bf6f7..dda2a10ec8 100644 --- a/tests/lib/rules/function-component-definition.js +++ b/tests/lib/rules/function-component-definition.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/function-component-definition'); const parserOptions = { diff --git a/tests/lib/rules/hook-use-state.js b/tests/lib/rules/hook-use-state.js index b5a4cd796d..031ad6ce55 100644 --- a/tests/lib/rules/hook-use-state.js +++ b/tests/lib/rules/hook-use-state.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/hook-use-state'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/iframe-missing-sandbox.js b/tests/lib/rules/iframe-missing-sandbox.js index 82c4304e14..628eea3adf 100644 --- a/tests/lib/rules/iframe-missing-sandbox.js +++ b/tests/lib/rules/iframe-missing-sandbox.js @@ -8,7 +8,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/iframe-missing-sandbox'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-boolean-value.js b/tests/lib/rules/jsx-boolean-value.js index f4216f2ce1..95be0709f4 100644 --- a/tests/lib/rules/jsx-boolean-value.js +++ b/tests/lib/rules/jsx-boolean-value.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-boolean-value'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-child-element-spacing.js b/tests/lib/rules/jsx-child-element-spacing.js index 92e001acee..4788b7db49 100644 --- a/tests/lib/rules/jsx-child-element-spacing.js +++ b/tests/lib/rules/jsx-child-element-spacing.js @@ -1,6 +1,6 @@ 'use strict'; -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-child-element-spacing'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-closing-bracket-location.js b/tests/lib/rules/jsx-closing-bracket-location.js index 120f1e3638..0e20084785 100644 --- a/tests/lib/rules/jsx-closing-bracket-location.js +++ b/tests/lib/rules/jsx-closing-bracket-location.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-closing-bracket-location'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-closing-tag-location.js b/tests/lib/rules/jsx-closing-tag-location.js index 4f1b24205f..4992a2e9d8 100644 --- a/tests/lib/rules/jsx-closing-tag-location.js +++ b/tests/lib/rules/jsx-closing-tag-location.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-closing-tag-location'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-curly-brace-presence.js b/tests/lib/rules/jsx-curly-brace-presence.js index c2a8a9c1d9..4c157deb0c 100755 --- a/tests/lib/rules/jsx-curly-brace-presence.js +++ b/tests/lib/rules/jsx-curly-brace-presence.js @@ -11,9 +11,9 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; const semver = require('semver'); const eslintPkg = require('eslint/package.json'); +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-curly-brace-presence'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-curly-newline.js b/tests/lib/rules/jsx-curly-newline.js index 894e21834f..8b0a82b26a 100644 --- a/tests/lib/rules/jsx-curly-newline.js +++ b/tests/lib/rules/jsx-curly-newline.js @@ -8,7 +8,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-curly-newline'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-curly-spacing.js b/tests/lib/rules/jsx-curly-spacing.js index 89571a51f8..f7a778bbe0 100644 --- a/tests/lib/rules/jsx-curly-spacing.js +++ b/tests/lib/rules/jsx-curly-spacing.js @@ -10,7 +10,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-curly-spacing'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-equals-spacing.js b/tests/lib/rules/jsx-equals-spacing.js index a4e3db95ea..843372d3cd 100644 --- a/tests/lib/rules/jsx-equals-spacing.js +++ b/tests/lib/rules/jsx-equals-spacing.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-equals-spacing'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-filename-extension.js b/tests/lib/rules/jsx-filename-extension.js index e924d2ede4..adf3c78e79 100644 --- a/tests/lib/rules/jsx-filename-extension.js +++ b/tests/lib/rules/jsx-filename-extension.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-filename-extension'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-first-prop-new-line.js b/tests/lib/rules/jsx-first-prop-new-line.js index 3cf963caf8..b53c9ee05b 100644 --- a/tests/lib/rules/jsx-first-prop-new-line.js +++ b/tests/lib/rules/jsx-first-prop-new-line.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-first-prop-new-line'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-fragments.js b/tests/lib/rules/jsx-fragments.js index 2807a15f75..6ed7302a47 100644 --- a/tests/lib/rules/jsx-fragments.js +++ b/tests/lib/rules/jsx-fragments.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-fragments'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-handler-names.js b/tests/lib/rules/jsx-handler-names.js index 20df6106fb..47adbe85ae 100644 --- a/tests/lib/rules/jsx-handler-names.js +++ b/tests/lib/rules/jsx-handler-names.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-handler-names'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-indent-props.js b/tests/lib/rules/jsx-indent-props.js index a826fbd094..2e4a618b81 100644 --- a/tests/lib/rules/jsx-indent-props.js +++ b/tests/lib/rules/jsx-indent-props.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-indent-props'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-indent.js b/tests/lib/rules/jsx-indent.js index 9483279f68..95e98ac2da 100644 --- a/tests/lib/rules/jsx-indent.js +++ b/tests/lib/rules/jsx-indent.js @@ -9,9 +9,9 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; const semver = require('semver'); const eslintVersion = require('eslint/package.json').version; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-indent'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-key.js b/tests/lib/rules/jsx-key.js index 748e9a2fd9..2c5ba7a5c1 100644 --- a/tests/lib/rules/jsx-key.js +++ b/tests/lib/rules/jsx-key.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-key'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-max-depth.js b/tests/lib/rules/jsx-max-depth.js index 2aefb31e95..9b83b02cde 100644 --- a/tests/lib/rules/jsx-max-depth.js +++ b/tests/lib/rules/jsx-max-depth.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-max-depth'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-max-props-per-line.js b/tests/lib/rules/jsx-max-props-per-line.js index 706388bc32..88ac920493 100644 --- a/tests/lib/rules/jsx-max-props-per-line.js +++ b/tests/lib/rules/jsx-max-props-per-line.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-max-props-per-line'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-newline.js b/tests/lib/rules/jsx-newline.js index 201656f81e..1090dff063 100644 --- a/tests/lib/rules/jsx-newline.js +++ b/tests/lib/rules/jsx-newline.js @@ -10,7 +10,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-newline'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-no-bind.js b/tests/lib/rules/jsx-no-bind.js index 100c6feb21..71e3e63717 100644 --- a/tests/lib/rules/jsx-no-bind.js +++ b/tests/lib/rules/jsx-no-bind.js @@ -10,7 +10,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-no-bind'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-no-comment-textnodes.js b/tests/lib/rules/jsx-no-comment-textnodes.js index cdb611453b..e3742eab60 100644 --- a/tests/lib/rules/jsx-no-comment-textnodes.js +++ b/tests/lib/rules/jsx-no-comment-textnodes.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-no-comment-textnodes'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-no-constructed-context-values.js b/tests/lib/rules/jsx-no-constructed-context-values.js index c8c9dee995..54ef9f3fc8 100644 --- a/tests/lib/rules/jsx-no-constructed-context-values.js +++ b/tests/lib/rules/jsx-no-constructed-context-values.js @@ -10,7 +10,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-no-constructed-context-values'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-no-duplicate-props.js b/tests/lib/rules/jsx-no-duplicate-props.js index 81f2508d92..f85287a854 100644 --- a/tests/lib/rules/jsx-no-duplicate-props.js +++ b/tests/lib/rules/jsx-no-duplicate-props.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-no-duplicate-props'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-no-leaked-render.js b/tests/lib/rules/jsx-no-leaked-render.js index a86513addb..071ecd68ab 100644 --- a/tests/lib/rules/jsx-no-leaked-render.js +++ b/tests/lib/rules/jsx-no-leaked-render.js @@ -11,7 +11,7 @@ const semver = require('semver'); const eslintPkg = require('eslint/package.json'); -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-no-leaked-render'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-no-literals.js b/tests/lib/rules/jsx-no-literals.js index d547178d8b..e064b9f525 100644 --- a/tests/lib/rules/jsx-no-literals.js +++ b/tests/lib/rules/jsx-no-literals.js @@ -10,7 +10,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-no-literals'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-no-script-url.js b/tests/lib/rules/jsx-no-script-url.js index 4d0374e08e..2a2ff394bd 100644 --- a/tests/lib/rules/jsx-no-script-url.js +++ b/tests/lib/rules/jsx-no-script-url.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-no-script-url'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-no-target-blank.js b/tests/lib/rules/jsx-no-target-blank.js index 591a1a42ee..01dcb360ff 100644 --- a/tests/lib/rules/jsx-no-target-blank.js +++ b/tests/lib/rules/jsx-no-target-blank.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-no-target-blank'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-no-undef.js b/tests/lib/rules/jsx-no-undef.js index 665f0da454..84ffeb0c35 100644 --- a/tests/lib/rules/jsx-no-undef.js +++ b/tests/lib/rules/jsx-no-undef.js @@ -9,11 +9,13 @@ // Requirements // ----------------------------------------------------------------------------- -const eslint = require('eslint'); +const semver = require('semver'); +const eslintPkg = require('eslint/package.json'); +const RuleTester = require('../../helpers/ruleTester'); +const getRuleDefiner = require('../../helpers/getRuleDefiner'); +const getESLintCoreRule = require('../../helpers/getESLintCoreRule'); const rule = require('../../../lib/rules/jsx-no-undef'); -const RuleTester = eslint.RuleTester; - const parsers = require('../../helpers/parsers'); const parserOptions = { @@ -29,8 +31,12 @@ const parserOptions = { // ----------------------------------------------------------------------------- const ruleTester = new RuleTester({ parserOptions }); -const linter = ruleTester.linter || eslint.linter || eslint.Linter; -linter.defineRule('no-undef', require('../../helpers/getESLintCoreRule')('no-undef')); + +// In ESLint >= 9, it isn't possible to redefine a core rule, but it isn't necessary anyway since the core rules are certainly already available in the RuleTester/Linter +if (semver.major(eslintPkg.version) < 9) { + const ruleDefiner = getRuleDefiner(ruleTester); + ruleDefiner.defineRule('no-undef', getESLintCoreRule('no-undef')); +} ruleTester.run('jsx-no-undef', rule, { valid: parsers.all([ diff --git a/tests/lib/rules/jsx-no-useless-fragment.js b/tests/lib/rules/jsx-no-useless-fragment.js index d1b599a8b2..eb5b227bcd 100644 --- a/tests/lib/rules/jsx-no-useless-fragment.js +++ b/tests/lib/rules/jsx-no-useless-fragment.js @@ -8,7 +8,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-no-useless-fragment'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-one-expression-per-line.js b/tests/lib/rules/jsx-one-expression-per-line.js index 344cc15c4b..72615c2679 100644 --- a/tests/lib/rules/jsx-one-expression-per-line.js +++ b/tests/lib/rules/jsx-one-expression-per-line.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-one-expression-per-line'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-pascal-case.js b/tests/lib/rules/jsx-pascal-case.js index 9923131118..bc90773ef7 100644 --- a/tests/lib/rules/jsx-pascal-case.js +++ b/tests/lib/rules/jsx-pascal-case.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-pascal-case'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-props-no-multi-spaces.js b/tests/lib/rules/jsx-props-no-multi-spaces.js index 1f3597bbcf..d85573702f 100644 --- a/tests/lib/rules/jsx-props-no-multi-spaces.js +++ b/tests/lib/rules/jsx-props-no-multi-spaces.js @@ -9,9 +9,9 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; const semver = require('semver'); const eslintPkg = require('eslint/package.json'); +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-props-no-multi-spaces'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-props-no-spread-multi.js b/tests/lib/rules/jsx-props-no-spread-multi.js index 4566ef9066..2e5df66668 100644 --- a/tests/lib/rules/jsx-props-no-spread-multi.js +++ b/tests/lib/rules/jsx-props-no-spread-multi.js @@ -8,7 +8,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-props-no-spread-multi'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-props-no-spreading.js b/tests/lib/rules/jsx-props-no-spreading.js index 27fbf37170..dc9c0203ed 100644 --- a/tests/lib/rules/jsx-props-no-spreading.js +++ b/tests/lib/rules/jsx-props-no-spreading.js @@ -8,7 +8,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-props-no-spreading'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-sort-default-props.js b/tests/lib/rules/jsx-sort-default-props.js index 171b431889..15d651db3a 100644 --- a/tests/lib/rules/jsx-sort-default-props.js +++ b/tests/lib/rules/jsx-sort-default-props.js @@ -11,7 +11,7 @@ const babelEslintVersion = require('babel-eslint/package.json').version; const semver = require('semver'); -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-sort-default-props'); diff --git a/tests/lib/rules/jsx-sort-props.js b/tests/lib/rules/jsx-sort-props.js index 1dc9d270a6..797dc26650 100644 --- a/tests/lib/rules/jsx-sort-props.js +++ b/tests/lib/rules/jsx-sort-props.js @@ -9,9 +9,9 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; const semver = require('semver'); const eslintPkg = require('eslint/package.json'); +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-sort-props'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-space-before-closing.js b/tests/lib/rules/jsx-space-before-closing.js index af69bd749a..01f80be41a 100644 --- a/tests/lib/rules/jsx-space-before-closing.js +++ b/tests/lib/rules/jsx-space-before-closing.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-space-before-closing'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-tag-spacing.js b/tests/lib/rules/jsx-tag-spacing.js index 039591a7f5..cc98cb2b05 100644 --- a/tests/lib/rules/jsx-tag-spacing.js +++ b/tests/lib/rules/jsx-tag-spacing.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-tag-spacing'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/jsx-uses-react.js b/tests/lib/rules/jsx-uses-react.js index 0110be18bb..b4b596c27b 100644 --- a/tests/lib/rules/jsx-uses-react.js +++ b/tests/lib/rules/jsx-uses-react.js @@ -12,7 +12,7 @@ const eslint = require('eslint'); const rule = require('../../helpers/getESLintCoreRule')('no-unused-vars'); -const RuleTester = eslint.RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const parsers = require('../../helpers/parsers'); @@ -35,50 +35,50 @@ const settings = { // ----------------------------------------------------------------------------- const ruleTester = new RuleTester({ parserOptions }); -const linter = ruleTester.linter || eslint.linter || eslint.Linter; -linter.defineRule('jsx-uses-react', require('../../../lib/rules/jsx-uses-react')); +const ruleDefiner = ruleTester[Symbol.for('react.RuleTester.RuleDefiner')] || ruleTester.linter || eslint.linter || eslint.Linter; +ruleDefiner.defineRule('react/jsx-uses-react', require('../../../lib/rules/jsx-uses-react')); ruleTester.run('no-unused-vars', rule, { valid: parsers.all([ - { code: '/*eslint jsx-uses-react:1*/ var React;
;' }, - { code: '/*eslint jsx-uses-react:1*/ var React; (function () {
})();' }, - { code: '/*eslint jsx-uses-react:1*/ /** @jsx Foo */ var Foo;
;' }, + { code: '/*eslint react/jsx-uses-react:1*/ var React;
;' }, + { code: '/*eslint react/jsx-uses-react:1*/ var React; (function () {
})();' }, + { code: '/*eslint react/jsx-uses-react:1*/ /** @jsx Foo */ var Foo;
;' }, { - code: '/*eslint jsx-uses-react:1*/ var Foo;
;', + code: '/*eslint react/jsx-uses-react:1*/ var Foo;
;', settings, }, { - code: '/*eslint jsx-uses-react:1*/ var Frag; <>;', + code: '/*eslint react/jsx-uses-react:1*/ var Frag; <>;', settings: { react: { fragment: 'Frag' } }, features: ['fragment'], }, { - code: '/*eslint jsx-uses-react:1*/ var React; <>;', + code: '/*eslint react/jsx-uses-react:1*/ var React; <>;', features: ['fragment', 'no-ts-old'], // TODO: FIXME: fix for typescript-eslint }, ].map(parsers.disableNewTS)), invalid: parsers.all([ { - code: '/*eslint jsx-uses-react:1*/ var React;', + code: '/*eslint react/jsx-uses-react:1*/ var React;', errors: [{ message: '\'React\' is defined but never used.' }], }, { - code: '/*eslint jsx-uses-react:1*/ /** @jsx Foo */ var React;
;', + code: '/*eslint react/jsx-uses-react:1*/ /** @jsx Foo */ var React;
;', errors: [{ message: '\'React\' is defined but never used.' }], }, { - code: '/*eslint jsx-uses-react:1*/ var React;
;', + code: '/*eslint react/jsx-uses-react:1*/ var React;
;', errors: [{ message: '\'React\' is defined but never used.' }], settings, }, { - code: '/*eslint jsx-uses-react:1*/ var Frag; <>;', + code: '/*eslint react/jsx-uses-react:1*/ var Frag; <>;', errors: [{ message: '\'Frag\' is defined but never used.' }], features: ['fragment'], settings: { react: { fragment: 'Fragment' } }, }, { - code: '/*eslint jsx-uses-react:1*/ var React; <>;', + code: '/*eslint react/jsx-uses-react:1*/ var React; <>;', features: ['fragment'], errors: [{ message: '\'React\' is defined but never used.' }], settings, diff --git a/tests/lib/rules/jsx-uses-vars.js b/tests/lib/rules/jsx-uses-vars.js index 3dc9ccdaad..f9df618525 100644 --- a/tests/lib/rules/jsx-uses-vars.js +++ b/tests/lib/rules/jsx-uses-vars.js @@ -13,7 +13,7 @@ const eslint = require('eslint'); const ruleNoUnusedVars = require('../../helpers/getESLintCoreRule')('no-unused-vars'); const rulePreferConst = require('../../helpers/getESLintCoreRule')('prefer-const'); -const RuleTester = eslint.RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const parsers = require('../../helpers/parsers'); @@ -30,14 +30,14 @@ const parserOptions = { // ----------------------------------------------------------------------------- const ruleTester = new RuleTester({ parserOptions }); -const linter = ruleTester.linter || eslint.linter || eslint.Linter; -linter.defineRule('jsx-uses-vars', require('../../../lib/rules/jsx-uses-vars')); +const ruleDefiner = ruleTester[Symbol.for('react.RuleTester.RuleDefiner')] || ruleTester.linter || eslint.linter || eslint.Linter; +ruleDefiner.defineRule('react/jsx-uses-vars', require('../../../lib/rules/jsx-uses-vars')); ruleTester.run('no-unused-vars', ruleNoUnusedVars, { valid: parsers.all([ { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ function foo() { var App; var bar = React.render(); @@ -48,21 +48,21 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ var App; React.render(); `, }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ var a = 1; React.render(); `, }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ var App; function f() { return ; @@ -72,21 +72,21 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ var App; `, }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ class HelloMessage {}; `, }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ class HelloMessage { render() { var HelloMessage =
Hello
; @@ -98,7 +98,7 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ function foo() { var App = { Foo: { Bar: {} } }; var bar = React.render(); @@ -109,7 +109,7 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ function foo() { var App = { Foo: { Bar: { Baz: {} } } }; var bar = React.render(); @@ -120,14 +120,14 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ var object; React.render(); `, }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ var object; React.render(); `, @@ -135,12 +135,12 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { ].map(parsers.disableNewTS)), invalid: parsers.all([ { - code: '/* eslint jsx-uses-vars: 1 */ var App;', + code: '/* eslint react/jsx-uses-vars: 1 */ var App;', errors: [{ message: '\'App\' is defined but never used.' }], }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ var App; var unused; React.render(); @@ -149,7 +149,7 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ var App; var Hello; React.render(); @@ -162,7 +162,7 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ var Button; var Input; React.render(); @@ -171,14 +171,14 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ class unused {} `, errors: [{ message: '\'unused\' is defined but never used.' }], }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ class HelloMessage { render() { var HelloMessage =
Hello
; @@ -195,7 +195,7 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ import {Hello} from 'Hello'; function Greetings() { const Hello = require('Hello').default; @@ -212,7 +212,7 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ var lowercase; React.render(); `, @@ -220,7 +220,7 @@ ruleTester.run('no-unused-vars', ruleNoUnusedVars, { }, { code: ` - /* eslint jsx-uses-vars: 1 */ + /* eslint react/jsx-uses-vars: 1 */ function Greetings(div) { return
; } @@ -242,26 +242,26 @@ ruleTester.run('prefer-const', rulePreferConst, { invalid: parsers.all([ { code: ` - /* eslint jsx-uses-vars:1 */ + /* eslint react/jsx-uses-vars:1 */ let App =
; ; `, errors: [{ message: '\'App\' is never reassigned. Use \'const\' instead.' }], output: ` - /* eslint jsx-uses-vars:1 */ + /* eslint react/jsx-uses-vars:1 */ const App =
; ; `, }, { code: ` - /* eslint jsx-uses-vars:1 */ + /* eslint react/jsx-uses-vars:1 */ let filters = 'foo';
{filters}
; `, errors: [{ message: '\'filters\' is never reassigned. Use \'const\' instead.' }], output: ` - /* eslint jsx-uses-vars:1 */ + /* eslint react/jsx-uses-vars:1 */ const filters = 'foo';
{filters}
; `, diff --git a/tests/lib/rules/jsx-wrap-multilines.js b/tests/lib/rules/jsx-wrap-multilines.js index 86cdc1ce2d..8db8fe79d9 100644 --- a/tests/lib/rules/jsx-wrap-multilines.js +++ b/tests/lib/rules/jsx-wrap-multilines.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/jsx-wrap-multilines'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-access-state-in-setstate.js b/tests/lib/rules/no-access-state-in-setstate.js index 258821be84..bdf104d0cc 100644 --- a/tests/lib/rules/no-access-state-in-setstate.js +++ b/tests/lib/rules/no-access-state-in-setstate.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const parsers = require('../../helpers/parsers'); const rule = require('../../../lib/rules/no-access-state-in-setstate'); diff --git a/tests/lib/rules/no-adjacent-inline-elements.js b/tests/lib/rules/no-adjacent-inline-elements.js index f2da87d7da..a757fb869d 100644 --- a/tests/lib/rules/no-adjacent-inline-elements.js +++ b/tests/lib/rules/no-adjacent-inline-elements.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-adjacent-inline-elements'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-array-index-key.js b/tests/lib/rules/no-array-index-key.js index dc5364f47c..5c2974f182 100644 --- a/tests/lib/rules/no-array-index-key.js +++ b/tests/lib/rules/no-array-index-key.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const parsers = require('../../helpers/parsers'); const rule = require('../../../lib/rules/no-array-index-key'); diff --git a/tests/lib/rules/no-arrow-function-lifecycle.js b/tests/lib/rules/no-arrow-function-lifecycle.js index ac22256c2c..de2c67cbc3 100644 --- a/tests/lib/rules/no-arrow-function-lifecycle.js +++ b/tests/lib/rules/no-arrow-function-lifecycle.js @@ -6,8 +6,8 @@ 'use strict'; const semver = require('semver'); -const RuleTester = require('eslint').RuleTester; const eslintPkg = require('eslint/package.json'); +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-arrow-function-lifecycle'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-children-prop.js b/tests/lib/rules/no-children-prop.js index 93f0f4cf42..fdd7f501f8 100644 --- a/tests/lib/rules/no-children-prop.js +++ b/tests/lib/rules/no-children-prop.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-children-prop'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-danger-with-children.js b/tests/lib/rules/no-danger-with-children.js index b25397e0c6..53013f5a58 100644 --- a/tests/lib/rules/no-danger-with-children.js +++ b/tests/lib/rules/no-danger-with-children.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-danger-with-children'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-danger.js b/tests/lib/rules/no-danger.js index a6f18630d5..11618c77f7 100644 --- a/tests/lib/rules/no-danger.js +++ b/tests/lib/rules/no-danger.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-danger'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-deprecated.js b/tests/lib/rules/no-deprecated.js index d986533aa5..a523eb1b6c 100644 --- a/tests/lib/rules/no-deprecated.js +++ b/tests/lib/rules/no-deprecated.js @@ -11,7 +11,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-deprecated'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-did-mount-set-state.js b/tests/lib/rules/no-did-mount-set-state.js index c0ab3acf70..83a1e9b7b4 100644 --- a/tests/lib/rules/no-did-mount-set-state.js +++ b/tests/lib/rules/no-did-mount-set-state.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-did-mount-set-state'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-did-update-set-state.js b/tests/lib/rules/no-did-update-set-state.js index 679ba194eb..f0895531c5 100644 --- a/tests/lib/rules/no-did-update-set-state.js +++ b/tests/lib/rules/no-did-update-set-state.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-did-update-set-state'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-direct-mutation-state.js b/tests/lib/rules/no-direct-mutation-state.js index fa9f731188..ae692a20d0 100644 --- a/tests/lib/rules/no-direct-mutation-state.js +++ b/tests/lib/rules/no-direct-mutation-state.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-direct-mutation-state'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-find-dom-node.js b/tests/lib/rules/no-find-dom-node.js index 4d6890a2e1..152d7d9c58 100644 --- a/tests/lib/rules/no-find-dom-node.js +++ b/tests/lib/rules/no-find-dom-node.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-find-dom-node'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-invalid-html-attribute.js b/tests/lib/rules/no-invalid-html-attribute.js index b171d823a4..fd45ad8613 100644 --- a/tests/lib/rules/no-invalid-html-attribute.js +++ b/tests/lib/rules/no-invalid-html-attribute.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-invalid-html-attribute'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-is-mounted.js b/tests/lib/rules/no-is-mounted.js index 9fb5b7d31d..ba63e8d67e 100644 --- a/tests/lib/rules/no-is-mounted.js +++ b/tests/lib/rules/no-is-mounted.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-is-mounted'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-multi-comp.js b/tests/lib/rules/no-multi-comp.js index 37402facbe..db6f09db2c 100644 --- a/tests/lib/rules/no-multi-comp.js +++ b/tests/lib/rules/no-multi-comp.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-multi-comp'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-namespace.js b/tests/lib/rules/no-namespace.js index 1056e99d74..2d423e8ad6 100644 --- a/tests/lib/rules/no-namespace.js +++ b/tests/lib/rules/no-namespace.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-namespace'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-object-type-as-default-prop.js b/tests/lib/rules/no-object-type-as-default-prop.js index b515ef6a49..a2dc01fb85 100644 --- a/tests/lib/rules/no-object-type-as-default-prop.js +++ b/tests/lib/rules/no-object-type-as-default-prop.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const parsers = require('../../helpers/parsers'); const rule = require('../../../lib/rules/no-object-type-as-default-prop'); diff --git a/tests/lib/rules/no-redundant-should-component-update.js b/tests/lib/rules/no-redundant-should-component-update.js index 413e6699e7..7aafb1e589 100644 --- a/tests/lib/rules/no-redundant-should-component-update.js +++ b/tests/lib/rules/no-redundant-should-component-update.js @@ -8,7 +8,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-redundant-should-component-update'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-render-return-value.js b/tests/lib/rules/no-render-return-value.js index 18caa88b5c..bbd7b7f930 100644 --- a/tests/lib/rules/no-render-return-value.js +++ b/tests/lib/rules/no-render-return-value.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-render-return-value'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-set-state.js b/tests/lib/rules/no-set-state.js index 3060c8e1d1..5f67e705c5 100644 --- a/tests/lib/rules/no-set-state.js +++ b/tests/lib/rules/no-set-state.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-set-state'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-string-refs.js b/tests/lib/rules/no-string-refs.js index fba476860d..05f8bfe407 100644 --- a/tests/lib/rules/no-string-refs.js +++ b/tests/lib/rules/no-string-refs.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-string-refs'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-this-in-sfc.js b/tests/lib/rules/no-this-in-sfc.js index 2c291ce9f8..ce0abb77ba 100644 --- a/tests/lib/rules/no-this-in-sfc.js +++ b/tests/lib/rules/no-this-in-sfc.js @@ -8,7 +8,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-this-in-sfc'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-typos.js b/tests/lib/rules/no-typos.js index ee68f3407e..0aaddfd290 100644 --- a/tests/lib/rules/no-typos.js +++ b/tests/lib/rules/no-typos.js @@ -11,7 +11,7 @@ const babelEslintVersion = require('babel-eslint/package.json').version; const semver = require('semver'); const version = require('eslint/package.json').version; -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-typos'); diff --git a/tests/lib/rules/no-unescaped-entities.js b/tests/lib/rules/no-unescaped-entities.js index 2eeab50ebb..227365f5ea 100644 --- a/tests/lib/rules/no-unescaped-entities.js +++ b/tests/lib/rules/no-unescaped-entities.js @@ -20,7 +20,7 @@ try { allowsInvalidJSX = semver.satisfies(require(resolve.sync('acorn-jsx/package.json', { basedir: path.dirname(require.resolve('eslint')) })).version, '< 5.2'); } catch (e) { /**/ } -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-unescaped-entities'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-unknown-property.js b/tests/lib/rules/no-unknown-property.js index afb95ac2fb..32e6c6d6b3 100644 --- a/tests/lib/rules/no-unknown-property.js +++ b/tests/lib/rules/no-unknown-property.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-unknown-property'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-unsafe.js b/tests/lib/rules/no-unsafe.js index 66c45f1d51..3dc180be22 100644 --- a/tests/lib/rules/no-unsafe.js +++ b/tests/lib/rules/no-unsafe.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-unsafe'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-unstable-nested-components.js b/tests/lib/rules/no-unstable-nested-components.js index a27444ebfd..3e20ad648a 100644 --- a/tests/lib/rules/no-unstable-nested-components.js +++ b/tests/lib/rules/no-unstable-nested-components.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-unstable-nested-components'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-unused-class-component-methods.js b/tests/lib/rules/no-unused-class-component-methods.js index dd22101067..deccb47a07 100644 --- a/tests/lib/rules/no-unused-class-component-methods.js +++ b/tests/lib/rules/no-unused-class-component-methods.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-unused-class-component-methods'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-unused-prop-types.js b/tests/lib/rules/no-unused-prop-types.js index c80c37f4cf..943db3048e 100644 --- a/tests/lib/rules/no-unused-prop-types.js +++ b/tests/lib/rules/no-unused-prop-types.js @@ -12,7 +12,7 @@ const semver = require('semver'); const eslintPkg = require('eslint/package.json'); const babelEslintVersion = require('babel-eslint/package.json').version; -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); require('object.entries/auto'); // for node 6, eslint 5, new TS parser, `function Hello({firstname}: Props): React$Element {` cases diff --git a/tests/lib/rules/no-unused-state.js b/tests/lib/rules/no-unused-state.js index cf7d50a3cc..e08197e589 100644 --- a/tests/lib/rules/no-unused-state.js +++ b/tests/lib/rules/no-unused-state.js @@ -5,8 +5,8 @@ 'use strict'; const semver = require('semver'); -const RuleTester = require('eslint').RuleTester; const tsEslintVersion = require('@typescript-eslint/parser/package.json').version; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-unused-state'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/no-will-update-set-state.js b/tests/lib/rules/no-will-update-set-state.js index 5c3408f1df..be3895c4e6 100644 --- a/tests/lib/rules/no-will-update-set-state.js +++ b/tests/lib/rules/no-will-update-set-state.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-will-update-set-state'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/prefer-es6-class.js b/tests/lib/rules/prefer-es6-class.js index cf5530ef53..369b22ec58 100644 --- a/tests/lib/rules/prefer-es6-class.js +++ b/tests/lib/rules/prefer-es6-class.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/prefer-es6-class'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/prefer-exact-props.js b/tests/lib/rules/prefer-exact-props.js index 03563add80..697c35cfa2 100644 --- a/tests/lib/rules/prefer-exact-props.js +++ b/tests/lib/rules/prefer-exact-props.js @@ -8,7 +8,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/prefer-exact-props'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/prefer-read-only-props.js b/tests/lib/rules/prefer-read-only-props.js index 071f3568a5..bf7668042b 100644 --- a/tests/lib/rules/prefer-read-only-props.js +++ b/tests/lib/rules/prefer-read-only-props.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/prefer-read-only-props'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/prefer-stateless-function.js b/tests/lib/rules/prefer-stateless-function.js index 1d6c8c358c..5ceee4ab22 100644 --- a/tests/lib/rules/prefer-stateless-function.js +++ b/tests/lib/rules/prefer-stateless-function.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/prefer-stateless-function'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 3f90c8a67d..39dc8bad3c 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -12,7 +12,7 @@ const semver = require('semver'); const eslintPkg = require('eslint/package.json').version; const babelEslintVersion = require('babel-eslint/package.json').version; -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/prop-types'); diff --git a/tests/lib/rules/react-in-jsx-scope.js b/tests/lib/rules/react-in-jsx-scope.js index c203c665ba..6828f07ce5 100644 --- a/tests/lib/rules/react-in-jsx-scope.js +++ b/tests/lib/rules/react-in-jsx-scope.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/react-in-jsx-scope'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/require-default-props.js b/tests/lib/rules/require-default-props.js index 4c68b92f65..dd73a712e7 100644 --- a/tests/lib/rules/require-default-props.js +++ b/tests/lib/rules/require-default-props.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/require-default-props'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/require-optimization.js b/tests/lib/rules/require-optimization.js index 89ef8c3115..0df43ac2d1 100644 --- a/tests/lib/rules/require-optimization.js +++ b/tests/lib/rules/require-optimization.js @@ -5,7 +5,7 @@ 'use strict'; -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/require-optimization'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/require-render-return.js b/tests/lib/rules/require-render-return.js index d24aef80c3..364a2e7c99 100644 --- a/tests/lib/rules/require-render-return.js +++ b/tests/lib/rules/require-render-return.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/require-render-return'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/self-closing-comp.js b/tests/lib/rules/self-closing-comp.js index b9627b3427..4cd3b1c5ad 100644 --- a/tests/lib/rules/self-closing-comp.js +++ b/tests/lib/rules/self-closing-comp.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/self-closing-comp'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/sort-comp.js b/tests/lib/rules/sort-comp.js index 0461f65fd0..da8810cc10 100644 --- a/tests/lib/rules/sort-comp.js +++ b/tests/lib/rules/sort-comp.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/sort-comp'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/sort-default-props.js b/tests/lib/rules/sort-default-props.js index 8bbe6af1f5..3878a29e0b 100644 --- a/tests/lib/rules/sort-default-props.js +++ b/tests/lib/rules/sort-default-props.js @@ -11,7 +11,7 @@ const babelEslintVersion = require('babel-eslint/package.json').version; const semver = require('semver'); -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/sort-default-props'); diff --git a/tests/lib/rules/sort-prop-types.js b/tests/lib/rules/sort-prop-types.js index 7fbe1b4f97..a6157aa347 100644 --- a/tests/lib/rules/sort-prop-types.js +++ b/tests/lib/rules/sort-prop-types.js @@ -11,7 +11,7 @@ const babelEslintVersion = require('babel-eslint/package.json').version; const semver = require('semver'); const eslintPkg = require('eslint/package.json'); -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/sort-prop-types'); diff --git a/tests/lib/rules/state-in-constructor.js b/tests/lib/rules/state-in-constructor.js index 9b8791cc43..e144d4e4cb 100644 --- a/tests/lib/rules/state-in-constructor.js +++ b/tests/lib/rules/state-in-constructor.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/state-in-constructor'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/static-property-placement.js b/tests/lib/rules/static-property-placement.js index 084881b318..97b49e936b 100644 --- a/tests/lib/rules/static-property-placement.js +++ b/tests/lib/rules/static-property-placement.js @@ -16,7 +16,7 @@ const PROPERTY_ASSIGNMENT = 'property assignment'; // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/static-property-placement'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/style-prop-object.js b/tests/lib/rules/style-prop-object.js index d851fcbf9a..9381bad508 100644 --- a/tests/lib/rules/style-prop-object.js +++ b/tests/lib/rules/style-prop-object.js @@ -9,7 +9,7 @@ // Requirements // ------------------------------------------------------------------------------ -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/style-prop-object'); const parsers = require('../../helpers/parsers'); diff --git a/tests/lib/rules/void-dom-elements-no-children.js b/tests/lib/rules/void-dom-elements-no-children.js index 8e4156931d..64c4aadddb 100644 --- a/tests/lib/rules/void-dom-elements-no-children.js +++ b/tests/lib/rules/void-dom-elements-no-children.js @@ -9,7 +9,7 @@ // Requirements // ----------------------------------------------------------------------------- -const RuleTester = require('eslint').RuleTester; +const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/void-dom-elements-no-children'); const parsers = require('../../helpers/parsers'); diff --git a/tests/util/Components.js b/tests/util/Components.js index 087159e2a6..414f9a05bd 100644 --- a/tests/util/Components.js +++ b/tests/util/Components.js @@ -2,14 +2,14 @@ const assert = require('assert'); const entries = require('object.entries'); -const eslint = require('eslint'); const fromEntries = require('object.fromentries'); const values = require('object.values'); +const RuleTester = require('../helpers/ruleTester'); const Components = require('../../lib/util/Components'); const parsers = require('../helpers/parsers'); -const ruleTester = new eslint.RuleTester({ +const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018, sourceType: 'module', From e621e30be8c08da642e09f673fd66ac9865ceb0a Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Mon, 20 May 2024 11:27:48 +0200 Subject: [PATCH 4/7] add `tests/helpers/getRuleDefiner.js` --- tests/helpers/getRuleDefiner.js | 11 +++++++++++ tests/lib/rules/jsx-uses-react.js | 4 ++-- tests/lib/rules/jsx-uses-vars.js | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 tests/helpers/getRuleDefiner.js diff --git a/tests/helpers/getRuleDefiner.js b/tests/helpers/getRuleDefiner.js new file mode 100644 index 0000000000..b83c1cb59a --- /dev/null +++ b/tests/helpers/getRuleDefiner.js @@ -0,0 +1,11 @@ +'use strict'; + +const eslint = require('eslint'); + +// `ruleTester` is a RuleTester instance +const getRuleDefiner = (ruleTester) => (typeof Symbol !== 'undefined' && Symbol.for && ruleTester[Symbol.for('react.RuleTester.RuleDefiner')]) + || ruleTester.linter + || eslint.linter + || eslint.Linter; + +module.exports = getRuleDefiner; diff --git a/tests/lib/rules/jsx-uses-react.js b/tests/lib/rules/jsx-uses-react.js index b4b596c27b..3a8e39013c 100644 --- a/tests/lib/rules/jsx-uses-react.js +++ b/tests/lib/rules/jsx-uses-react.js @@ -9,10 +9,10 @@ // Requirements // ----------------------------------------------------------------------------- -const eslint = require('eslint'); const rule = require('../../helpers/getESLintCoreRule')('no-unused-vars'); const RuleTester = require('../../helpers/ruleTester'); +const getRuleDefiner = require('../../helpers/getRuleDefiner'); const parsers = require('../../helpers/parsers'); @@ -35,7 +35,7 @@ const settings = { // ----------------------------------------------------------------------------- const ruleTester = new RuleTester({ parserOptions }); -const ruleDefiner = ruleTester[Symbol.for('react.RuleTester.RuleDefiner')] || ruleTester.linter || eslint.linter || eslint.Linter; +const ruleDefiner = getRuleDefiner(ruleTester); ruleDefiner.defineRule('react/jsx-uses-react', require('../../../lib/rules/jsx-uses-react')); ruleTester.run('no-unused-vars', rule, { diff --git a/tests/lib/rules/jsx-uses-vars.js b/tests/lib/rules/jsx-uses-vars.js index f9df618525..00f801fd65 100644 --- a/tests/lib/rules/jsx-uses-vars.js +++ b/tests/lib/rules/jsx-uses-vars.js @@ -9,11 +9,11 @@ // Requirements // ----------------------------------------------------------------------------- -const eslint = require('eslint'); const ruleNoUnusedVars = require('../../helpers/getESLintCoreRule')('no-unused-vars'); const rulePreferConst = require('../../helpers/getESLintCoreRule')('prefer-const'); const RuleTester = require('../../helpers/ruleTester'); +const getRuleDefiner = require('../../helpers/getRuleDefiner'); const parsers = require('../../helpers/parsers'); @@ -30,7 +30,7 @@ const parserOptions = { // ----------------------------------------------------------------------------- const ruleTester = new RuleTester({ parserOptions }); -const ruleDefiner = ruleTester[Symbol.for('react.RuleTester.RuleDefiner')] || ruleTester.linter || eslint.linter || eslint.Linter; +const ruleDefiner = getRuleDefiner(ruleTester); ruleDefiner.defineRule('react/jsx-uses-vars', require('../../../lib/rules/jsx-uses-vars')); ruleTester.run('no-unused-vars', ruleNoUnusedVars, { From 4e3f2aeca5614d292bbf04f75ebba0b7537ebefb Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Mon, 20 May 2024 12:44:03 +0200 Subject: [PATCH 5/7] [New] support eslint v9 --- CHANGELOG.md | 2 ++ package.json | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7ca4f6713..fe16311de5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ## Unreleased ### Added +* support eslint v9 ([#3759][] @mdjermanovic) * export flat configs from plugin root and fix flat config crash ([#3694][] @bradzacher @mdjermanovic) * add [`jsx-props-no-spread-multi`] ([#3724][] @SimonSchick) +[#3759]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3759 [#3724]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3724 [#3694]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3694 diff --git a/package.json b/package.json index 72de675758..2938ae22a1 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ^4.0.0 || ^5.0.0", "aud": "^2.0.4", "babel-eslint": "^8 || ^9 || ^10.1.0", - "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8", + "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9", "eslint-config-airbnb-base": "^15.0.0", "eslint-doc-generator": "^1.7.1", "eslint-plugin-eslint-plugin": "^2.3.0 || ^3.5.3 || ^4.0.1 || ^5.0.5", @@ -79,7 +79,7 @@ "typescript-eslint-parser": "^20.1.1" }, "peerDependencies": { - "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8" + "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9" }, "engines": { "node": ">=4" From 917240b0eea85f4ed8c30532a687a12d75126356 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Mon, 20 May 2024 23:56:18 +0200 Subject: [PATCH 6/7] [Fix] `no-invalid-html-attribute`: substitute placeholders in suggestion messages --- CHANGELOG.md | 3 + lib/rules/no-invalid-html-attribute.js | 157 ++++++++----------- tests/helpers/parsers.js | 2 +- tests/lib/rules/no-invalid-html-attribute.js | 21 ++- 4 files changed, 83 insertions(+), 100 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe16311de5..196b55b345 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange [#3724]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3724 [#3694]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3694 +### Fixed +* [`no-invalid-html-attribute`]: substitute placeholders in suggestion messages ([#3759][] @mdjermanovic) + ## [7.34.4] - 2024.07.13 ### Fixed diff --git a/lib/rules/no-invalid-html-attribute.js b/lib/rules/no-invalid-html-attribute.js index 98c33fbc3f..6e46f3bd4c 100644 --- a/lib/rules/no-invalid-html-attribute.js +++ b/lib/rules/no-invalid-html-attribute.js @@ -8,7 +8,6 @@ const matchAll = require('string.prototype.matchall'); const docsUrl = require('../util/docsUrl'); const report = require('../util/report'); -const getMessageData = require('../util/message'); // ------------------------------------------------------------------------------ // Rule Definition @@ -224,6 +223,7 @@ const COMPONENT_ATTRIBUTE_MAP = new Map([ ['rel', new Set(['link', 'a', 'area', 'form'])], ]); +/* eslint-disable eslint-plugin/no-unused-message-ids -- false positives, these messageIds are used */ const messages = { emptyIsMeaningless: 'An empty “{{attributeName}}” attribute is meaningless.', neverValid: '“{{reportingValue}}” is never a valid “{{attributeName}}” attribute value.', @@ -264,15 +264,11 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN report(context, messages.onlyStrings, 'onlyStrings', { node, data, - suggest: [ - Object.assign( - getMessageData('suggestRemoveNonString', messages.suggestRemoveNonString), - { - data, - fix(fixer) { return fixer.remove(parentNode); }, - } - ), - ], + suggest: [{ + messageId: 'suggestRemoveNonString', + data, + fix(fixer) { return fixer.remove(parentNode); }, + }], }); return; } @@ -283,15 +279,11 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN report(context, messages.noEmpty, 'noEmpty', { node, data, - suggest: [ - Object.assign( - getMessageData('suggestRemoveEmpty', messages.suggestRemoveEmpty), - { - data, - fix(fixer) { return fixer.remove(node.parent); }, - } - ), - ], + suggest: [{ + messageId: 'suggestRemoveEmpty', + data, + fix(fixer) { return fixer.remove(node.parent); }, + }], }); return; } @@ -307,18 +299,16 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN reportingValue, }; + const suggest = [{ + messageId: 'suggestRemoveInvalid', + data, + fix(fixer) { return fixer.removeRange(singlePart.range); }, + }]; + report(context, messages.neverValid, 'neverValid', { node, data, - suggest: [ - Object.assign( - getMessageData('suggestRemoveInvalid', messages.suggestRemoveInvalid), - { - data, - fix(fixer) { return fixer.removeRange(singlePart.range); }, - } - ), - ], + suggest, }); } else if (!allowedTags.has(parentNodeName)) { const data = { @@ -327,18 +317,16 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN elementName: parentNodeName, }; + const suggest = [{ + messageId: 'suggestRemoveInvalid', + data, + fix(fixer) { return fixer.removeRange(singlePart.range); }, + }]; + report(context, messages.notValidFor, 'notValidFor', { node, data, - suggest: [ - Object.assign( - getMessageData('suggestRemoveInvalid', messages.suggestRemoveInvalid), - { - data, - fix(fixer) { return fixer.removeRange(singlePart.range); }, - } - ), - ], + suggest, }); } } @@ -375,33 +363,27 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN const whitespaceParts = splitIntoRangedParts(node, /(\s+)/g); for (const whitespacePart of whitespaceParts) { + const data = { attributeName }; + if (whitespacePart.range[0] === (node.range[0] + 1) || whitespacePart.range[1] === (node.range[1] - 1)) { report(context, messages.spaceDelimited, 'spaceDelimited', { node, - data: { attributeName }, - suggest: [ - Object.assign( - getMessageData('suggestRemoveWhitespaces', messages.suggestRemoveWhitespaces), - { - data: { attributeName }, - fix(fixer) { return fixer.removeRange(whitespacePart.range); }, - } - ), - ], + data, + suggest: [{ + messageId: 'suggestRemoveWhitespaces', + data, + fix(fixer) { return fixer.removeRange(whitespacePart.range); }, + }], }); } else if (whitespacePart.value !== '\u0020') { report(context, messages.spaceDelimited, 'spaceDelimited', { node, - data: { attributeName }, - suggest: [ - Object.assign( - getMessageData('suggestRemoveWhitespaces', messages.suggestRemoveWhitespaces), - { - data: { attributeName }, - fix(fixer) { return fixer.replaceTextRange(whitespacePart.range, '\u0020'); }, - } - ), - ], + data, + suggest: [{ + messageId: 'suggestRemoveWhitespaces', + data, + fix(fixer) { return fixer.replaceTextRange(whitespacePart.range, '\u0020'); }, + }], }); } } @@ -426,15 +408,11 @@ function checkAttribute(context, node) { report(context, messages.onlyMeaningfulFor, 'onlyMeaningfulFor', { node: node.name, data, - suggest: [ - Object.assign( - getMessageData('suggestRemoveDefault', messages.suggestRemoveDefault), - { - data, - fix(fixer) { return fixer.remove(node); }, - } - ), - ], + suggest: [{ + messageId: 'suggestRemoveDefault', + data, + fix(fixer) { return fixer.remove(node); }, + }], }); return; } @@ -447,12 +425,11 @@ function checkAttribute(context, node) { report(context, messages.emptyIsMeaningless, 'emptyIsMeaningless', { node: node.name, data, - suggest: [ - Object.assign( - getMessageData('suggestRemoveEmpty', messages.suggestRemoveEmpty), - { data, fix } - ), - ], + suggest: [{ + messageId: 'suggestRemoveEmpty', + data, + fix, + }], }); return; } @@ -475,12 +452,11 @@ function checkAttribute(context, node) { report(context, messages.onlyStrings, 'onlyStrings', { node: node.value, data, - suggest: [ - Object.assign( - getMessageData('suggestRemoveDefault', messages.suggestRemoveDefault), - { data, fix } - ), - ], + suggest: [{ + messageId: 'suggestRemoveDefault', + data, + fix, + }], }); } else if (node.value.expression.type === 'Identifier' && node.value.expression.name === 'undefined') { const data = { attributeName: attribute }; @@ -488,12 +464,11 @@ function checkAttribute(context, node) { report(context, messages.onlyStrings, 'onlyStrings', { node: node.value, data, - suggest: [ - Object.assign( - getMessageData('suggestRemoveDefault', messages.suggestRemoveDefault), - { data, fix } - ), - ], + suggest: [{ + messageId: 'suggestRemoveDefault', + data, + fix, + }], }); } } @@ -523,15 +498,11 @@ function checkPropValidValue(context, node, value, attribute) { report(context, messages.neverValid, 'neverValid', { node: value, data, - suggest: [ - Object.assign( - getMessageData('suggestRemoveInvalid', messages.suggestRemoveInvalid), - { - data, - fix(fixer) { return fixer.replaceText(value, value.raw.replace(value.value, '')); }, - } - ), - ], + suggest: [{ + messageId: 'suggestRemoveInvalid', + data, + fix(fixer) { return fixer.replaceText(value, value.raw.replace(value.value, '')); }, + }], }); } else if (!validTagSet.has(node.arguments[0].value)) { report(context, messages.notValidFor, 'notValidFor', { diff --git a/tests/helpers/parsers.js b/tests/helpers/parsers.js index 59205a509a..24cc12bdb9 100644 --- a/tests/helpers/parsers.js +++ b/tests/helpers/parsers.js @@ -105,7 +105,7 @@ const parsers = { && { errors: testObject.errors.map( (errorObject) => { - const nextSuggestions = errorObject.suggestions && { + const nextSuggestions = errorObject.suggestions && typeof errorObject.suggestions !== 'number' && { suggestions: errorObject.suggestions.map((suggestion) => Object.assign({}, suggestion, { output: suggestion.output + extraComment, })), diff --git a/tests/lib/rules/no-invalid-html-attribute.js b/tests/lib/rules/no-invalid-html-attribute.js index fd45ad8613..d7530cecdd 100644 --- a/tests/lib/rules/no-invalid-html-attribute.js +++ b/tests/lib/rules/no-invalid-html-attribute.js @@ -9,6 +9,8 @@ // Requirements // ------------------------------------------------------------------------------ +const semver = require('semver'); +const eslintPkg = require('eslint/package.json'); const RuleTester = require('../../helpers/ruleTester'); const rule = require('../../../lib/rules/no-invalid-html-attribute'); const parsers = require('../../helpers/parsers'); @@ -488,12 +490,19 @@ ruleTester.run('no-invalid-html-attribute', rule, { attributeName: 'rel', reportingValue: 1, }, - // suggestions: [ - // { - // messageId: 'suggestRemoveDefault', - // output: 'React.createElement("a", { })', - // }, - // ], + + // FIXME: this suggestion produces invalid code + // In ESLint > 9, RuleTester doesn't allow suggestions with parsing errors. + suggestions: semver.major(eslintPkg.version) < 9 + ? [ + { + messageId: 'suggestRemoveInvalid', + data: { reportingValue: '1' }, + output: 'React.createElement("a", { rel: })', + }, + ] + : 1, + type: 'Literal', }, ], From 9cd79041b3d6be13065adcf1940f5fab0ae90dc5 Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Thu, 30 May 2024 23:23:38 +0200 Subject: [PATCH 7/7] [actions] Don't install with `--legacy-peer-deps` in pretest check --- .github/workflows/node-pretest.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/node-pretest.yml b/.github/workflows/node-pretest.yml index 0f410f48b6..ed00d06b47 100644 --- a/.github/workflows/node-pretest.yml +++ b/.github/workflows/node-pretest.yml @@ -12,8 +12,6 @@ jobs: name: 'nvm install lts/* && npm install' with: node-version: 'lts/*' - env: - NPM_CONFIG_LEGACY_PEER_DEPS: true - run: npm run pretest posttest: