From 3abe203f333706bb1331e35c8473b3d8c861ffae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Zl=C3=A1mal?= Date: Wed, 22 Sep 2021 09:51:14 -0500 Subject: [PATCH] Eslint config: upgrade `eslint-plugin-react` to version 7.26.0 This change updates `eslint-plugin-react` to the latest version 7.26.0 and workarounds `fbt` oddities discovered in the previous version (https://github.com/yannickcr/eslint-plugin-react/issues/3080). I added 2 fixtures to make sure `no-unused-vars` rule works as expected with FBT. Additionally, it removes unused suppression comments that were also fixed in previous React plugin version (https://github.com/yannickcr/eslint-plugin-react/issues/3063). Changelog: https://github.com/yannickcr/eslint-plugin-react/blob/eeb0144f14aa972f533e2ef0b094f6742d63c492/CHANGELOG.md#7260---20210920 adeira-source-id: 97d82ba734142c6ba2e1c37e3ab006477659b77c --- CHANGELOG.md | 3 ++- .../invalid-eslint-examples/react/no-unused-vars.js | 12 ++++++++++++ .../valid-eslint-examples/react/no-unused-vars.js | 13 +++++++++++++ __tests__/__snapshots__/index.test.js.snap | 2 ++ __tests__/__snapshots__/presets.test.js.snap | 2 ++ package.json | 2 +- src/presets/base.js | 1 + src/presets/react.js | 1 + 8 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 __tests__/__fixtures__/invalid-eslint-examples/react/no-unused-vars.js create mode 100644 __tests__/__fixtures__/valid-eslint-examples/react/no-unused-vars.js diff --git a/CHANGELOG.md b/CHANGELOG.md index ce8d6aa..db8066f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,11 @@ # Unreleased +- Rule `no-unused-vars` has been adjusted to take [`fbt`](https://facebook.github.io/fbt/) oddities into account. This reverts the version pin of `eslint-plugin-react` introduced in 6.5.1. For more details please visit: https://github.com/yannickcr/eslint-plugin-react/issues/3080 - New rule [`flowtype/no-duplicate-type-union-intersection-members`](https://github.com/gajus/eslint-plugin-flowtype/blob/1c1c009ba2a58b9660d43c43750396bef8d73904/.README/rules/no-duplicate-type-union-intersection-members.md) has been enabled (as warnings or errors in strict mode). # 6.5.1 -- Dependency `eslint-plugin-react` was temporarily pined to version 7.25.1 because of a new issue with FBT tags: https://github.com/yannickcr/eslint-plugin-react/issues/3080 +- Dependency `eslint-plugin-react` has been temporarily pined to version 7.25.1 because of a new issue with FBT tags: https://github.com/yannickcr/eslint-plugin-react/issues/3080 # 6.5.0 diff --git a/__tests__/__fixtures__/invalid-eslint-examples/react/no-unused-vars.js b/__tests__/__fixtures__/invalid-eslint-examples/react/no-unused-vars.js new file mode 100644 index 0000000..a72d6af --- /dev/null +++ b/__tests__/__fixtures__/invalid-eslint-examples/react/no-unused-vars.js @@ -0,0 +1,12 @@ +// @flow strict + +// eslint-disable-next-line no-unused-vars +const someUnusedVar = 42; + +// eslint-disable-next-line no-unused-vars +function fact(n) { + if (n < 2) { + return 1; + } + return n * fact(n - 1); +} diff --git a/__tests__/__fixtures__/valid-eslint-examples/react/no-unused-vars.js b/__tests__/__fixtures__/valid-eslint-examples/react/no-unused-vars.js new file mode 100644 index 0000000..09ee5c0 --- /dev/null +++ b/__tests__/__fixtures__/valid-eslint-examples/react/no-unused-vars.js @@ -0,0 +1,13 @@ +/** + * This code should NOT report `no-unused-vars` error on FBT import, see: + * https://github.com/yannickcr/eslint-plugin-react/issues/3080 + * + * @flow + */ + +import fbt from 'fbt'; // eslint-disable-line import/no-extraneous-dependencies +import type { Node } from 'react'; + +export default function MyComponent(): Node { + return test; +} diff --git a/__tests__/__snapshots__/index.test.js.snap b/__tests__/__snapshots__/index.test.js.snap index ce4cd8d..adbdcce 100644 --- a/__tests__/__snapshots__/index.test.js.snap +++ b/__tests__/__snapshots__/index.test.js.snap @@ -625,6 +625,7 @@ Object { "args": "after-used", "argsIgnorePattern": "^_$", "ignoreRestSiblings": true, + "varsIgnorePattern": "^fbt$", }, ], "no-use-before-define": 0, @@ -852,6 +853,7 @@ Object { "ignoreStateless": true, }, ], + "react/no-namespace": 0, "react/no-redundant-should-component-update": 2, "react/no-render-return-value": 2, "react/no-set-state": 0, diff --git a/__tests__/__snapshots__/presets.test.js.snap b/__tests__/__snapshots__/presets.test.js.snap index df17082..a022e56 100644 --- a/__tests__/__snapshots__/presets.test.js.snap +++ b/__tests__/__snapshots__/presets.test.js.snap @@ -379,6 +379,7 @@ Object { "args": "after-used", "argsIgnorePattern": "^_$", "ignoreRestSiblings": true, + "varsIgnorePattern": "^fbt$", }, ], "no-use-before-define": 0, @@ -948,6 +949,7 @@ Object { "ignoreStateless": true, }, ], + "react/no-namespace": 0, "react/no-redundant-should-component-update": 2, "react/no-render-return-value": 2, "react/no-set-state": 0, diff --git a/package.json b/package.json index 29996a6..762b570 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^4.0.0", "eslint-plugin-promise": "^5.1.0", - "eslint-plugin-react": "7.25.1", + "eslint-plugin-react": "^7.26.0", "eslint-plugin-react-hooks": "^4.2.0", "eslint-plugin-react-native": "^3.11.0", "eslint-plugin-relay": "^1.8.2", diff --git a/src/presets/base.js b/src/presets/base.js index 2b5de75..d6cb4c3 100644 --- a/src/presets/base.js +++ b/src/presets/base.js @@ -165,6 +165,7 @@ module.exports = ({ args: 'after-used', ignoreRestSiblings: true, argsIgnorePattern: '^_$', // (_) => { … } + varsIgnorePattern: '^fbt$', // https://github.com/yannickcr/eslint-plugin-react/issues/3080 }, ], 'no-use-before-define': OFF, // https://github.com/babel/babel-eslint/issues/485 diff --git a/src/presets/react.js b/src/presets/react.js index f220536..4424385 100644 --- a/src/presets/react.js +++ b/src/presets/react.js @@ -78,6 +78,7 @@ module.exports = ({ 'react/no-find-dom-node': ERROR, 'react/no-is-mounted': ERROR, 'react/no-multi-comp': [ERROR, { ignoreStateless: true }], + 'react/no-namespace': OFF, // complains about `` and similar 'react/no-redundant-should-component-update': ERROR, 'react/no-render-return-value': ERROR, 'react/no-set-state': OFF,