Skip to content

Commit e23cb26

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

File tree

2 files changed

+77
-9
lines changed

2 files changed

+77
-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 properArrows from "@getify/eslint-plugin-proper-arrows";
90+
91+
export default [
92+
properArrows.flatConfigs["CONFIG-PRESET-NAME"], // i.e., "getify-says", etc
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 properArrows from "@getify/eslint-plugin-proper-arrows";
104+
105+
export default [
106+
properArrows.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 properArrows from "@getify/eslint-plugin-proper-arrows";
137+
138+
{
139+
plugins: {
140+
"@getify/proper-arrows": properArrows
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: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
"use strict";
22

3-
module.exports = {
3+
var presetRulesConfig = {
4+
"getify-says": {
5+
"@getify/proper-arrows/params": [ "error", { "unused": "trailing", "count": 2, "length": 3, "allowed": [ "e", "v", "cb", "fn", "pr", ], }, ],
6+
"@getify/proper-arrows/name": "error",
7+
"@getify/proper-arrows/return": [ "error", { "ternary": 1, }, ],
8+
"@getify/proper-arrows/where": "error",
9+
"@getify/proper-arrows/this": [ "error", "nested", { "no-global": true, }, ],
10+
}
11+
};
12+
13+
var plugin = {
414
configs: {
515
"getify-says": {
616
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-
},
17+
rules: presetRulesConfig["getify-says"],
18+
}
1519
},
1620
rules: {
1721
"params": {
@@ -636,6 +640,16 @@ module.exports = {
636640
},
637641
};
638642

643+
plugin.flatConfigs = {
644+
"getify-says": {
645+
name: "getify-says",
646+
plugins: {
647+
"@getify/proper-arrows": plugin
648+
},
649+
rules: presetRulesConfig["getify-says"],
650+
}
651+
}
652+
639653

640654
// ***************************
641655

@@ -837,3 +851,5 @@ var getAncestors = (context, sourceCode, node) => {
837851
);
838852
return getAncestors(context, sourceCode, node);
839853
};
854+
855+
module.exports = plugin;

0 commit comments

Comments
 (0)