Skip to content

Commit 40e6d1b

Browse files
committed
feat: support eslint 9
Add flat config preset
1 parent 4d8658c commit 40e6d1b

File tree

2 files changed

+75
-9
lines changed

2 files changed

+75
-9
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,39 @@ The available configuration presets to choose from:
8080

8181
It's important to note that you can still override any of the preset rule definitions in your configuration. Think of these presets as convenience "defaults" that can still be customized.
8282

83+
### Flat Config
84+
85+
If you're using ESLint's newer flat config format, you can use the plugin's flat configuration preset:
86+
87+
```js
88+
// eslint.config.js
89+
import arrows from "@getify/eslint-plugin-proper-arrows";
90+
91+
export default [
92+
arrows.flatConfigs["CONFIG-PRESET-NAME"],
93+
// ... other configs
94+
];
95+
```
96+
97+
This will automatically load the plugin and apply the recommended preset rules configuration.
98+
The preset includes the same rules configuration as the traditional `"extends": ["plugin:@getify/proper-arrows/CONFIG-PRESET-NAME"]` format.
99+
100+
You can still override any of the preset rules in your configuration after including the flat config:
101+
102+
```js
103+
import arrows from "@getify/eslint-plugin-proper-arrows";
104+
105+
export default [
106+
arrows.flatConfigs["getify-says"],
107+
{
108+
rules: {
109+
"@getify/proper-arrows/params": ["error", {"unused": "none"}],
110+
// ... other rule overrides
111+
}
112+
}
113+
];
114+
```
115+
83116
### `.eslintrc.json`
84117

85118
To load the plugin and enable its rules via a local or global `.eslintrc.json` configuration file:
@@ -97,6 +130,25 @@ To load the plugin and enable its rules via a local or global `.eslintrc.json` c
97130
}
98131
```
99132

133+
For users of ESLint's newer flat config format, the configuration would look like this:
134+
135+
```js
136+
import arrows from "@getify/eslint-plugin-proper-arrows";
137+
138+
{
139+
plugins: {
140+
"@getify/proper-arrows": arrows
141+
},
142+
rules: {
143+
"@getify/proper-arrows/params": ["error",{"unused":"trailing"}],
144+
"@getify/proper-arrows/name": ["error",{"trivial":false}],
145+
"@getify/proper-arrows/where": ["error",{"global":true}],
146+
"@getify/proper-arrows/return": ["error",{"object":true}],
147+
"@getify/proper-arrows/this": ["error","always",{"no-global":true}]
148+
}
149+
}
150+
```
151+
100152
### `package.json`
101153

102154
To load the plugin and enable its rules via a project's `package.json`:

lib/index.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
"use strict";
22

3-
module.exports = {
3+
var recommendedRulesConfig = {
4+
"@getify/proper-arrows/params": [ "error", { "unused": "trailing", "count": 2, "length": 3, "allowed": [ "e", "v", "cb", "fn", "pr", ], }, ],
5+
"@getify/proper-arrows/name": "error",
6+
"@getify/proper-arrows/return": [ "error", { "ternary": 1, }, ],
7+
"@getify/proper-arrows/where": "error",
8+
"@getify/proper-arrows/this": [ "error", "nested", { "no-global": true, }, ],
9+
}
10+
11+
var plugin = {
412
configs: {
513
"getify-says": {
614
plugins: [ "@getify/proper-arrows", ],
7-
rules: {
8-
"@getify/proper-arrows/params": [ "error", { "unused": "trailing", "count": 2, "length": 3, "allowed": [ "e", "v", "cb", "fn", "pr", ], }, ],
9-
"@getify/proper-arrows/name": "error",
10-
"@getify/proper-arrows/return": [ "error", { "ternary": 1, }, ],
11-
"@getify/proper-arrows/where": "error",
12-
"@getify/proper-arrows/this": [ "error", "nested", { "no-global": true, }, ],
13-
},
14-
},
15+
rules: recommendedRulesConfig,
16+
}
1517
},
1618
rules: {
1719
"params": {
@@ -636,6 +638,16 @@ module.exports = {
636638
},
637639
};
638640

641+
plugin.flatConfigs = {
642+
"getify-says": {
643+
name: "getify-says",
644+
plugins: {
645+
"@getify/proper-arrows": plugin
646+
},
647+
rules: recommendedRulesConfig,
648+
}
649+
}
650+
639651

640652
// ***************************
641653

@@ -837,3 +849,5 @@ var getAncestors = (context, sourceCode, node) => {
837849
);
838850
return getAncestors(context, sourceCode, node);
839851
};
852+
853+
module.exports = plugin;

0 commit comments

Comments
 (0)