Skip to content

Commit ea96241

Browse files
committed
Add recommended plugin config
Closes #14
1 parent b417dcd commit ea96241

File tree

4 files changed

+49
-24
lines changed

4 files changed

+49
-24
lines changed

README.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ yarn add -D eslint-plugin-react-you-might-not-need-an-effect
2222

2323
### Configuration
2424

25-
Add the plugin to your ESLint configuration file.
25+
Add the plugin's recommended config to your ESLint configuration file.
2626

2727
#### Legacy config (`.eslintrc`)
2828

2929
```js
3030
{
31-
"plugins": ["react-you-might-not-need-an-effect"],
32-
"rules": {
33-
"react-you-might-not-need-an-effect/you-might-not-need-an-effect": "warn"
34-
}
31+
"extends": [
32+
"plugin:react-you-might-not-need-an-effect/recommended"
33+
],
3534
}
3635
```
3736

@@ -41,24 +40,13 @@ Add the plugin to your ESLint configuration file.
4140
import youMightNotNeedAnEffect from "eslint-plugin-react-you-might-not-need-an-effect";
4241

4342
export default [
44-
{
45-
files: ["**/*.{js,jsx}"],
46-
plugins: {
47-
"react-you-might-not-need-an-effect": youMightNotNeedAnEffect,
48-
},
49-
rules: {
50-
"react-you-might-not-need-an-effect/you-might-not-need-an-effect": "warn",
51-
},
52-
},
43+
youMightNotNeedAnEffect.configs.recommended
5344
];
5445
```
5546

5647
### Recommended
5748

58-
The plugin will have more information to act upon when you:
59-
60-
- Configure your [ESLint global variables](https://eslint.org/docs/latest/use/configure/language-options#predefined-global-variables)
61-
- Pass the correct dependencies to your effect — [`react-hooks/exhaustive-deps`](https://www.npmjs.com/package/eslint-plugin-react-hooks)
49+
The plugin will have more information to act upon when you pass the correct dependencies to your effect — [`react-hooks/exhaustive-deps`](https://www.npmjs.com/package/eslint-plugin-react-hooks).
6250

6351
## 🔎 Rule: `you-might-not-need-an-effect`
6452

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
"node": ">=14.0.0"
3838
},
3939
"dependencies": {
40-
"eslint-utils": "^3.0.0"
40+
"eslint-utils": "^3.0.0",
41+
"globals": "^16.2.0"
4142
},
4243
"devDependencies": {
4344
"esbuild": "^0.25.3",
4445
"eslint": "^9.20.1",
4546
"eslint-plugin-eslint-plugin": "^6.4.0",
4647
"eslint-plugin-n": "^17.17.0",
47-
"globals": "^16.2.0",
4848
"mocha": "11.1.0"
4949
},
5050
"peerDependencies": {

src/index.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
1-
import { name, rule } from "./rule.js";
1+
import { name as ruleName, rule } from "./rule.js";
2+
import globals from "globals";
23

3-
export default {
4+
const pluginName = "react-you-might-not-need-an-effect";
5+
6+
const plugin = {
7+
meta: {
8+
name: pluginName,
9+
},
10+
configs: {
11+
recommended: {},
12+
},
413
rules: {
5-
[name]: rule,
14+
[ruleName]: rule,
615
},
716
};
17+
18+
Object.assign(plugin.configs.recommended, {
19+
files: ["**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"],
20+
plugins: {
21+
// Object.assign above so we can reference `plugin` here
22+
[pluginName]: plugin,
23+
},
24+
rules: {
25+
[pluginName + "/" + ruleName]: "warn",
26+
},
27+
languageOptions: {
28+
globals: {
29+
// NOTE: Required so we can resolve global references to their upstream global variables
30+
...globals.browser,
31+
},
32+
parserOptions: {
33+
ecmaFeatures: {
34+
jsx: true,
35+
},
36+
},
37+
},
38+
});
39+
40+
export default plugin;

types/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import type { ESLint } from "eslint";
22

3-
declare const plugin: ESLint.Plugin;
3+
declare const plugin: ESLint.Plugin & {
4+
configs: {
5+
recommended: ESLint.ConfigData;
6+
};
7+
};
48
export default plugin;

0 commit comments

Comments
 (0)