diff --git a/index.js b/index.js index d1b2c120aa..106dd5f3f7 100644 --- a/index.js +++ b/index.js @@ -27,6 +27,9 @@ const plugins = [ 'react', ]; +const SEVERITY_ERROR = /** @type {2} */ (2); +const SEVERITY_OFF = /** @type {0} */ (0); + const plugin = { deprecatedRules, rules: allRules, @@ -39,28 +42,28 @@ const plugin = { }, }, rules: { - 'react/display-name': 2, - 'react/jsx-key': 2, - 'react/jsx-no-comment-textnodes': 2, - 'react/jsx-no-duplicate-props': 2, - 'react/jsx-no-target-blank': 2, - 'react/jsx-no-undef': 2, - 'react/jsx-uses-react': 2, - 'react/jsx-uses-vars': 2, - 'react/no-children-prop': 2, - 'react/no-danger-with-children': 2, - 'react/no-deprecated': 2, - 'react/no-direct-mutation-state': 2, - 'react/no-find-dom-node': 2, - 'react/no-is-mounted': 2, - 'react/no-render-return-value': 2, - 'react/no-string-refs': 2, - 'react/no-unescaped-entities': 2, - 'react/no-unknown-property': 2, - 'react/no-unsafe': 0, - 'react/prop-types': 2, - 'react/react-in-jsx-scope': 2, - 'react/require-render-return': 2, + 'react/display-name': SEVERITY_ERROR, + 'react/jsx-key': SEVERITY_ERROR, + 'react/jsx-no-comment-textnodes': SEVERITY_ERROR, + 'react/jsx-no-duplicate-props': SEVERITY_ERROR, + 'react/jsx-no-target-blank': SEVERITY_ERROR, + 'react/jsx-no-undef': SEVERITY_ERROR, + 'react/jsx-uses-react': SEVERITY_ERROR, + 'react/jsx-uses-vars': SEVERITY_ERROR, + 'react/no-children-prop': SEVERITY_ERROR, + 'react/no-danger-with-children': SEVERITY_ERROR, + 'react/no-deprecated': SEVERITY_ERROR, + 'react/no-direct-mutation-state': SEVERITY_ERROR, + 'react/no-find-dom-node': SEVERITY_ERROR, + 'react/no-is-mounted': SEVERITY_ERROR, + 'react/no-render-return-value': SEVERITY_ERROR, + 'react/no-string-refs': SEVERITY_ERROR, + 'react/no-unescaped-entities': SEVERITY_ERROR, + 'react/no-unknown-property': SEVERITY_ERROR, + 'react/no-unsafe': SEVERITY_OFF, + 'react/prop-types': SEVERITY_ERROR, + 'react/react-in-jsx-scope': SEVERITY_ERROR, + 'react/require-render-return': SEVERITY_ERROR, }, }, all: { @@ -81,8 +84,8 @@ const plugin = { jsxPragma: null, // for @typescript/eslint-parser }, rules: { - 'react/react-in-jsx-scope': 0, - 'react/jsx-uses-react': 0, + 'react/react-in-jsx-scope': SEVERITY_OFF, + 'react/jsx-uses-react': SEVERITY_OFF, }, }, }, diff --git a/lib/rules/forbid-prop-types.js b/lib/rules/forbid-prop-types.js index df40706d00..44de1fa023 100644 --- a/lib/rules/forbid-prop-types.js +++ b/lib/rules/forbid-prop-types.js @@ -195,6 +195,7 @@ module.exports = { const propTypesSpecifier = node.specifiers.find((specifier) => ( 'imported' in specifier && specifier.imported + && 'name' in specifier.imported && specifier.imported.name === 'PropTypes' )); if (propTypesSpecifier) { diff --git a/lib/rules/forward-ref-uses-ref.js b/lib/rules/forward-ref-uses-ref.js index aeedeb82df..3a0b7de4c9 100644 --- a/lib/rules/forward-ref-uses-ref.js +++ b/lib/rules/forward-ref-uses-ref.js @@ -41,6 +41,7 @@ const messages = { removeForwardRef: 'Remove forwardRef wrapper', }; +/** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: { docs: { diff --git a/lib/rules/index.js b/lib/rules/index.js index 1e010b677b..0e73ab1a3f 100644 --- a/lib/rules/index.js +++ b/lib/rules/index.js @@ -3,7 +3,7 @@ /* eslint global-require: 0 */ /** @satisfies {Record} */ -module.exports = { +const rules = { 'boolean-prop-naming': require('./boolean-prop-naming'), 'button-has-type': require('./button-has-type'), 'checked-requires-onchange-or-readonly': require('./checked-requires-onchange-or-readonly'), @@ -108,3 +108,5 @@ module.exports = { 'style-prop-object': require('./style-prop-object'), 'void-dom-elements-no-children': require('./void-dom-elements-no-children'), }; + +module.exports = rules; diff --git a/lib/rules/jsx-fragments.js b/lib/rules/jsx-fragments.js index 6835331025..e6787c8af5 100644 --- a/lib/rules/jsx-fragments.js +++ b/lib/rules/jsx-fragments.js @@ -170,7 +170,7 @@ module.exports = { ImportDeclaration(node) { if (node.source && node.source.value === 'react') { node.specifiers.forEach((spec) => { - if ('imported' in spec && spec.imported && spec.imported.name === fragmentPragma) { + if ('imported' in spec && spec.imported && 'name' in spec.imported && spec.imported.name === fragmentPragma) { if (spec.local) { fragmentNames.add(spec.local.name); } diff --git a/lib/rules/jsx-no-literals.js b/lib/rules/jsx-no-literals.js index 230d33a18d..169f2f9f76 100644 --- a/lib/rules/jsx-no-literals.js +++ b/lib/rules/jsx-no-literals.js @@ -45,7 +45,7 @@ const messages = { literalNotInJSXExpressionInElement: 'Missing JSX expression container around literal string: "{{text}}" in {{element}}', }; -/** @type {Exclude['properties']} */ +/** @type {Exclude['properties']} */ const commonPropertiesSchema = { noStrings: { type: 'boolean', @@ -182,6 +182,7 @@ const elementOverrides = { }, }; +/** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: /** @type {import('eslint').Rule.RuleModule["meta"]} */ ({ docs: { diff --git a/lib/rules/jsx-props-no-spread-multi.js b/lib/rules/jsx-props-no-spread-multi.js index 2eeed0be49..3103be86da 100644 --- a/lib/rules/jsx-props-no-spread-multi.js +++ b/lib/rules/jsx-props-no-spread-multi.js @@ -16,6 +16,7 @@ const messages = { noMultiSpreading: 'Spreading the same expression multiple times is forbidden', }; +/** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: { docs: { diff --git a/lib/rules/no-deprecated.js b/lib/rules/no-deprecated.js index 9f5ddf7082..0c5931345f 100644 --- a/lib/rules/no-deprecated.js +++ b/lib/rules/no-deprecated.js @@ -229,7 +229,7 @@ module.exports = { } node.specifiers.filter(((s) => 'imported' in s && s.imported)).forEach((specifier) => { // TODO, semver-major: remove `in` check as part of jsdoc->tsdoc migration - checkDeprecation(node, 'imported' in specifier && `${MODULES[node.source.value][0]}.${specifier.imported.name}`, specifier); + checkDeprecation(node, 'imported' in specifier && 'name' in specifier.imported && `${MODULES[node.source.value][0]}.${specifier.imported.name}`, specifier); }); }, diff --git a/package.json b/package.json index 7e0be6c9b0..b54dcd87c2 100644 --- a/package.json +++ b/package.json @@ -55,12 +55,11 @@ "@babel/plugin-syntax-do-expressions": "^7.24.7", "@babel/plugin-syntax-function-bind": "^7.24.7", "@babel/preset-react": "^7.24.7", - "@types/eslint": "=7.2.10", "@types/estree": "0.0.52", "@types/node": "^4.9.5", "@typescript-eslint/parser": "^2.34.0 || ^3.10.1 || ^4 || ^5 || ^6.20 || ^7.14.1 || ^8.4", "babel-eslint": "^8 || ^9 || ^10.1.0", - "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.7", + "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9.10", "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",