Skip to content

Commit d616e43

Browse files
feat: added eslint-plugin-react-hooks plugin (#96)
1 parent 73ce999 commit d616e43

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

configs/react.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,30 @@ async function getReactRecommendedConfig() {
1111
// Nothing
1212
}
1313

14+
let reactHooksPlugin;
15+
16+
try {
17+
reactHooksPlugin = (await import("eslint-plugin-react-hooks")).default;
18+
// eslint-disable-next-line unicorn/prefer-optional-catch-binding
19+
} catch (_err) {
20+
// Nothing
21+
}
22+
1423
const { recommended, "jsx-runtime": jsxRuntime } = (reactPlugin &&
1524
reactPlugin.configs &&
1625
reactPlugin.configs.flat) || { recommended: {}, "jsx-runtime": {} };
1726

27+
const { recommended: recommendedHooks } = (reactHooksPlugin &&
28+
reactHooksPlugin.configs &&
29+
reactHooksPlugin.configs.flat) || { recommended: {} };
30+
1831
return {
1932
...recommended,
33+
...recommendedHooks,
34+
plugins: {
35+
...recommended.plugins,
36+
...recommendedHooks.plugins,
37+
},
2038
files: ["**/*.{jsx,tsx}"],
2139
settings: {
2240
react: {
@@ -31,6 +49,7 @@ async function getReactRecommendedConfig() {
3149
rules: {
3250
...recommended.rules,
3351
...jsxRuntime.rules,
52+
...recommendedHooks.rules,
3453
},
3554
};
3655
}

package-lock.json

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"eslint-plugin-n": "^17.23.1",
4949
"eslint-plugin-prettier": "^5.5.3",
5050
"eslint-plugin-react": "^7.37.5",
51+
"eslint-plugin-react-hooks": "^7.0.1",
5152
"eslint-plugin-unicorn": "^62.0.0",
5253
"globals": "^16.5.0",
5354
"jsonc-eslint-parser": "^2.4.2",

0 commit comments

Comments
 (0)