diff --git a/README.md b/README.md index c5e6b86..dac503d 100644 --- a/README.md +++ b/README.md @@ -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 arrows from "@getify/eslint-plugin-proper-arrows"; + +export default [ + arrows.flatConfigs["CONFIG-PRESET-NAME"], + // ... 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 arrows from "@getify/eslint-plugin-proper-arrows"; + +export default [ + arrows.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: @@ -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 arrows from "@getify/eslint-plugin-proper-arrows"; + +{ + plugins: { + "@getify/proper-arrows": arrows + }, + 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`: diff --git a/lib/index.js b/lib/index.js index dd79c2b..4606f8b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,17 +1,19 @@ "use strict"; -module.exports = { +var recommendedRulesConfig = { + "@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: recommendedRulesConfig, + } }, rules: { "params": { @@ -636,6 +638,16 @@ module.exports = { }, }; +plugin.flatConfigs = { + "getify-says": { + name: "getify-says", + plugins: { + "@getify/proper-arrows": plugin + }, + rules: recommendedRulesConfig, + } +} + // *************************** @@ -837,3 +849,5 @@ var getAncestors = (context, sourceCode, node) => { ); return getAncestors(context, sourceCode, node); }; + +module.exports = plugin;