Skip to content

Commit

Permalink
feat: support eslint 9
Browse files Browse the repository at this point in the history
 Add flat config preset
  • Loading branch information
Smrtnyk committed Dec 26, 2024
1 parent 4d8658c commit e23cb26
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,39 @@ The available configuration presets to choose from:

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.

### Flat Config

If you're using ESLint's newer flat config format, you can use the plugin's flat configuration preset:

```js
// eslint.config.js
import properArrows from "@getify/eslint-plugin-proper-arrows";

export default [
properArrows.flatConfigs["CONFIG-PRESET-NAME"], // i.e., "getify-says", etc
// ... other configs
];
```

This will automatically load the plugin and apply the recommended preset rules configuration.
The preset includes the same rules configuration as the traditional `"extends": ["plugin:@getify/proper-arrows/CONFIG-PRESET-NAME"]` format.

You can still override any of the preset rules in your configuration after including the flat config:

```js
import properArrows from "@getify/eslint-plugin-proper-arrows";

export default [
properArrows.flatConfigs["getify-says"],
{
rules: {
"@getify/proper-arrows/params": ["error", {"unused": "none"}],
// ... other rule overrides
}
}
];
```

### `.eslintrc.json`

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

For users of ESLint's newer flat config format, the configuration would look like this:

```js
import properArrows from "@getify/eslint-plugin-proper-arrows";

{
plugins: {
"@getify/proper-arrows": properArrows
},
rules: {
"@getify/proper-arrows/params": ["error",{"unused":"trailing"}],
"@getify/proper-arrows/name": ["error",{"trivial":false}],
"@getify/proper-arrows/where": ["error",{"global":true}],
"@getify/proper-arrows/return": ["error",{"object":true}],
"@getify/proper-arrows/this": ["error","always",{"no-global":true}]
}
}
```

### `package.json`

To load the plugin and enable its rules via a project's `package.json`:
Expand Down
34 changes: 25 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
"use strict";

module.exports = {
var presetRulesConfig = {
"getify-says": {
"@getify/proper-arrows/params": [ "error", { "unused": "trailing", "count": 2, "length": 3, "allowed": [ "e", "v", "cb", "fn", "pr", ], }, ],
"@getify/proper-arrows/name": "error",
"@getify/proper-arrows/return": [ "error", { "ternary": 1, }, ],
"@getify/proper-arrows/where": "error",
"@getify/proper-arrows/this": [ "error", "nested", { "no-global": true, }, ],
}
};

var plugin = {
configs: {
"getify-says": {
plugins: [ "@getify/proper-arrows", ],
rules: {
"@getify/proper-arrows/params": [ "error", { "unused": "trailing", "count": 2, "length": 3, "allowed": [ "e", "v", "cb", "fn", "pr", ], }, ],
"@getify/proper-arrows/name": "error",
"@getify/proper-arrows/return": [ "error", { "ternary": 1, }, ],
"@getify/proper-arrows/where": "error",
"@getify/proper-arrows/this": [ "error", "nested", { "no-global": true, }, ],
},
},
rules: presetRulesConfig["getify-says"],
}
},
rules: {
"params": {
Expand Down Expand Up @@ -636,6 +640,16 @@ module.exports = {
},
};

plugin.flatConfigs = {
"getify-says": {
name: "getify-says",
plugins: {
"@getify/proper-arrows": plugin
},
rules: presetRulesConfig["getify-says"],
}
}


// ***************************

Expand Down Expand Up @@ -837,3 +851,5 @@ var getAncestors = (context, sourceCode, node) => {
);
return getAncestors(context, sourceCode, node);
};

module.exports = plugin;

0 comments on commit e23cb26

Please sign in to comment.