diff --git a/eslint-plugin/README.md b/eslint-plugin/README.md index de9b872..7ba84a4 100644 --- a/eslint-plugin/README.md +++ b/eslint-plugin/README.md @@ -36,19 +36,54 @@ yarn add -D eslint @green-code-initiative/ecocode-eslint-plugin npm install -D eslint @green-code-initiative/ecocode-eslint-plugin ``` -### Enable whole plugin +### Enable plugin with recommended configuration -Add `@ecocode` recommended configuration to `extends` section of your `.eslintrc`: +#### ESLint Flat Configuration (`eslint.config.js`) -```jsonc +Add `@ecocode` **"flat/recommended"** configuration to your `eslint.config.js`: + +```js +import ecocode from '@ecocode/eslint-plugin' + +export default [ + /* other eslint configurations */ + ecocode.configs['flat/recommended'], +] +``` + +#### ESLint deprecated legacy configuration (`.eslintrc`) + +For legacy ESLint versions using the deprecated `.eslintrc` file, add the `@ecocode` **"recommended"** configuration to the `extends` array : + +```json { "extends": ["plugin:@ecocode/recommended"] } ``` -### Enable only some rules +### Enable specific rules + +#### ESLint Flat configuration (`eslint.config.js`) + +Add the `ecocode` plugin configuration to your `eslint.config.js` and select the rules to activate: + +```js +import ecocode from '@ecocode/eslint-plugin' + +export default [ + /* other eslint configurations */ + { + plugins: { "@ecocode": ecocode }, + rules: { + "@ecocode/no-multiple-access-dom-element": "error" + } + } +] +``` + +#### ESLint deprecated legacy configuration (`.eslintrc`) -Add `@ecocode` to the `plugins` section of your `.eslintrc`, followed by rules configuration: +If your project uses a legacy ESLint version, it may use as well the now deprecated `.eslintrc` file. In such case, Add `@ecocode` to the `plugins` array, potentially followed by rules specific configurations: ```jsonc { diff --git a/eslint-plugin/docs/rules/avoid-brightness-override.md b/eslint-plugin/docs/rules/avoid-brightness-override.md index 34a3e3f..a28af56 100644 --- a/eslint-plugin/docs/rules/avoid-brightness-override.md +++ b/eslint-plugin/docs/rules/avoid-brightness-override.md @@ -1,6 +1,6 @@ # Should avoid to override brightness (`@ecocode/avoid-brightness-override`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/docs/rules/avoid-css-animations.md b/eslint-plugin/docs/rules/avoid-css-animations.md index 2a77558..ab4080f 100644 --- a/eslint-plugin/docs/rules/avoid-css-animations.md +++ b/eslint-plugin/docs/rules/avoid-css-animations.md @@ -1,6 +1,6 @@ # Avoid usage of CSS animations (`@ecocode/avoid-css-animations`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/docs/rules/avoid-high-accuracy-geolocation.md b/eslint-plugin/docs/rules/avoid-high-accuracy-geolocation.md index 49e4072..e9cae02 100644 --- a/eslint-plugin/docs/rules/avoid-high-accuracy-geolocation.md +++ b/eslint-plugin/docs/rules/avoid-high-accuracy-geolocation.md @@ -1,6 +1,6 @@ # Avoid using high accuracy geolocation in web applications (`@ecocode/avoid-high-accuracy-geolocation`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/docs/rules/limit-db-query-results.md b/eslint-plugin/docs/rules/limit-db-query-results.md index e996235..b1030b6 100644 --- a/eslint-plugin/docs/rules/limit-db-query-results.md +++ b/eslint-plugin/docs/rules/limit-db-query-results.md @@ -1,6 +1,6 @@ # Should limit the number of returns for a SQL query (`@ecocode/limit-db-query-results`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/docs/rules/no-empty-image-src-attribute.md b/eslint-plugin/docs/rules/no-empty-image-src-attribute.md index 8051a81..637eb73 100644 --- a/eslint-plugin/docs/rules/no-empty-image-src-attribute.md +++ b/eslint-plugin/docs/rules/no-empty-image-src-attribute.md @@ -1,6 +1,6 @@ # Disallow usage of image with empty source attribute (`@ecocode/no-empty-image-src-attribute`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/docs/rules/no-import-all-from-library.md b/eslint-plugin/docs/rules/no-import-all-from-library.md index 9b3b541..f9d3056 100644 --- a/eslint-plugin/docs/rules/no-import-all-from-library.md +++ b/eslint-plugin/docs/rules/no-import-all-from-library.md @@ -1,6 +1,6 @@ # Should not import all from library (`@ecocode/no-import-all-from-library`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/docs/rules/no-multiple-access-dom-element.md b/eslint-plugin/docs/rules/no-multiple-access-dom-element.md index b88d139..6b5e585 100644 --- a/eslint-plugin/docs/rules/no-multiple-access-dom-element.md +++ b/eslint-plugin/docs/rules/no-multiple-access-dom-element.md @@ -1,6 +1,6 @@ # Disallow multiple access of same DOM element (`@ecocode/no-multiple-access-dom-element`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/docs/rules/no-multiple-style-changes.md b/eslint-plugin/docs/rules/no-multiple-style-changes.md index 1742cdd..2a9d7e2 100644 --- a/eslint-plugin/docs/rules/no-multiple-style-changes.md +++ b/eslint-plugin/docs/rules/no-multiple-style-changes.md @@ -1,6 +1,6 @@ # Disallow multiple style changes at once (`@ecocode/no-multiple-style-changes`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/docs/rules/no-torch.md b/eslint-plugin/docs/rules/no-torch.md index ca068a4..009c437 100644 --- a/eslint-plugin/docs/rules/no-torch.md +++ b/eslint-plugin/docs/rules/no-torch.md @@ -1,6 +1,6 @@ # Should not programmatically enable torch mode (`@ecocode/no-torch`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. ## Why is this an issue? diff --git a/eslint-plugin/docs/rules/prefer-collections-with-pagination.md b/eslint-plugin/docs/rules/prefer-collections-with-pagination.md index 2a457d8..52dd2b5 100644 --- a/eslint-plugin/docs/rules/prefer-collections-with-pagination.md +++ b/eslint-plugin/docs/rules/prefer-collections-with-pagination.md @@ -1,6 +1,6 @@ # Prefer API collections with pagination (`@ecocode/prefer-collections-with-pagination`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/docs/rules/prefer-shorthand-css-notations.md b/eslint-plugin/docs/rules/prefer-shorthand-css-notations.md index e8f66e2..07437bd 100644 --- a/eslint-plugin/docs/rules/prefer-shorthand-css-notations.md +++ b/eslint-plugin/docs/rules/prefer-shorthand-css-notations.md @@ -1,6 +1,6 @@ # Encourage usage of shorthand CSS notations (`@ecocode/prefer-shorthand-css-notations`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/docs/rules/provide-print-css.md b/eslint-plugin/docs/rules/provide-print-css.md index 42f13b3..c6dff54 100644 --- a/eslint-plugin/docs/rules/provide-print-css.md +++ b/eslint-plugin/docs/rules/provide-print-css.md @@ -1,6 +1,6 @@ # Enforce providing a print stylesheet (`@ecocode/provide-print-css`) -⚠️ This rule _warns_ in the ✅ `recommended` config. +⚠️ This rule _warns_ in the following configs: `flat/recommended`, ✅ `recommended`. diff --git a/eslint-plugin/lib/standalone.js b/eslint-plugin/lib/standalone.js index 8d23003..f5c9778 100644 --- a/eslint-plugin/lib/standalone.js +++ b/eslint-plugin/lib/standalone.js @@ -22,21 +22,35 @@ */ "use strict"; -const rules = require("./rule-list"); +const rulesList = require("./rule-list"); -const ruleModules = rules.reduce((map, rule) => { - map[rule.ruleName] = rule.ruleModule; - return map; -}, {}); +const allRules = {}; +const recommendedRules = {}; -const ruleConfigs = rules.reduce((map, rule) => { - const recommended = rule.ruleModule.meta.docs.recommended; - map[`@ecocode/${rule.ruleName}`] = - recommended === false ? "off" : recommended; - return map; -}, {}); +for (let { ruleName, ruleModule } of rulesList) { + allRules[ruleName] = ruleModule; + const { recommended } = ruleModule.meta.docs; + const ruleConfiguration = recommended === false ? "off" : recommended; + recommendedRules[`@ecocode/${ruleName}`] = ruleConfiguration; +} -module.exports = { - rules: ruleModules, - configs: { recommended: { plugins: ["@ecocode"], rules: ruleConfigs } }, +const plugin = { + meta: { + name: "@ecocode/eslint-plugin", + version: "1.6.0", + }, + rules: allRules, }; + +plugin.configs = { + recommended: { + plugins: ["@ecocode"], + rules: recommendedRules, + }, + ["flat/recommended"]: { + plugins: { "@ecocode": plugin }, + rules: recommendedRules, + }, +}; + +module.exports = plugin;