From 99485a7867cb5ec1d5844bf9ffc14feb7a79b853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 7 Apr 2023 12:15:27 +0800 Subject: [PATCH 1/8] chore: migrate to eslint.config.js --- .eslint-doc-generatorrc.js | 13 ++++- eslint.config.js | 102 +++++++++++++++++++++++++++++++++++++ lib/index.js | 2 +- package.json | 3 ++ 4 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 eslint.config.js diff --git a/.eslint-doc-generatorrc.js b/.eslint-doc-generatorrc.js index 8cd4b5ff..5c4ef3b6 100644 --- a/.eslint-doc-generatorrc.js +++ b/.eslint-doc-generatorrc.js @@ -1,7 +1,16 @@ +'use strict'; + /** @type {import('eslint-doc-generator').GenerateOptions} */ module.exports = { - ignoreConfig: ['all', 'rules', 'rules-recommended', 'tests', 'tests-recommended'], + ignoreConfig: [ + 'all', + 'rules', + 'rules-recommended', + 'tests', + 'tests-recommended', + ], ruleDocSectionInclude: ['Rule Details'], ruleListSplit: 'meta.docs.category', - urlConfigs: 'https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets', + urlConfigs: + 'https://github.com/eslint-community/eslint-plugin-eslint-plugin#presets', }; diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..37dd1832 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,102 @@ +'use strict'; + +/* + * IMPORTANT! + * + * Any changes made to this file must also be made to .eslintrc.js. + * + * Internally, ESLint is using the eslint.config.js file to lint itself. + * The .eslintrc.js file is needed too, because: + * + * 1. There are tests that expect .eslintrc.js to be present to actually run. + * 2. ESLint VS Code extension expects eslintrc config files to be + * present to work correctly. + * + * Once we no longer need to support both eslintrc and flat config, we will + * remove .eslintrc.js. + */ +const js = require('@eslint/js'); +const { FlatCompat } = require('@eslint/eslintrc'); +const globals = require('globals'); +const markdown = require('eslint-plugin-markdown'); +const eslintPlugin = require('eslint-plugin-eslint-plugin'); + +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, +}); + +module.exports = [ + ...compat.extends( + 'not-an-aardvark/node', + 'plugin:eslint-comments/recommended', + 'plugin:node/recommended', + 'plugin:prettier/recommended', + 'plugin:unicorn/recommended' + ), + { + languageOptions: { sourceType: 'commonjs' }, + rules: { + 'comma-dangle': [ + 'error', + { + arrays: 'always-multiline', + objects: 'always-multiline', + functions: 'never', // disallow trailing commas in function(es2017) + }, + ], + 'require-jsdoc': 'error', + + 'eslint-comments/no-unused-disable': 'error', + 'eslint-comments/require-description': 'error', + + 'unicorn/consistent-function-scoping': 'off', + 'unicorn/no-array-callback-reference': 'off', + 'unicorn/no-array-for-each': 'off', + 'unicorn/no-array-reduce': 'off', + 'unicorn/no-null': 'off', + 'unicorn/prefer-module': 'off', + 'unicorn/prefer-node-protocol': 'off', // TODO: enable once we drop support for Node 14.17. + 'unicorn/prevent-abbreviations': 'off', + }, + }, + { + // Apply eslint-plugin rules to our own rules/tests (but not docs). + files: ['lib/**/*.js', 'tests/**/*.js'], + plugins: { 'eslint-plugin': eslintPlugin }, + ...eslintPlugin.configs.recommended, + rules: { + 'eslint-plugin/report-message-format': ['error', '^[^a-z].*.$'], + 'eslint-plugin/require-meta-docs-url': [ + 'error', + { + pattern: + 'https://github.com/eslint-community/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/{{name}}.md', + }, + ], + }, + }, + { + files: ['tests/**/*.js'], + languageOptions: { globals: globals.mocha }, + }, + { + files: ['**/*.md'], + processor: 'markdown/markdown', + }, + { + // Markdown JS code samples in documentation: + files: ['**/*.md/*.js'], + plugins: { markdown }, + linterOptions: { noInlineConfig: true }, + rules: { + 'no-undef': 'off', + 'no-unused-vars': 'off', + strict: 'off', + + 'eslint-comments/require-description': 'off', + + 'unicorn/filename-case': 'off', + }, + }, +]; diff --git a/lib/index.js b/lib/index.js index baab06b4..e4044ab6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -47,7 +47,7 @@ module.exports.configs = Object.keys(configFilters).reduce( (configs, configName) => { return Object.assign(configs, { [configName]: { - plugins: ['eslint-plugin'], + // plugins: ['eslint-plugin'], rules: Object.fromEntries( Object.keys(allRules) .filter((ruleName) => configFilters[configName](allRules[ruleName])) diff --git a/package.json b/package.json index 7905b5dc..758ffda6 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,8 @@ "devDependencies": { "@commitlint/cli": "^17.1.2", "@commitlint/config-conventional": "^17.1.0", + "@eslint/eslintrc": "^2.0.2", + "@eslint/js": "^8.37.0", "@release-it/conventional-changelog": "^4.3.0", "@typescript-eslint/parser": "^5.36.2", "chai": "^4.3.6", @@ -67,6 +69,7 @@ "eslint-remote-tester": "^3.0.0", "eslint-scope": "^7.1.1", "espree": "^9.4.0", + "globals": "^13.20.0", "husky": "^8.0.1", "lodash": "^4.17.21", "markdownlint-cli": "^0.34.0", From fdb7321013dc6fa892ede9c52aa1f668ba85f6f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 7 Apr 2023 13:42:09 +0800 Subject: [PATCH 2/8] feat: export flat configs (fixes #342) to use it, you can do: ```js const eslintPluginRecommended = require('eslint-plugin-eslint-plugin/configs').recommended; module.exports = [eslintPluginRecommended]; ``` --- configs/index.js | 18 ++++++++++++++++++ eslint.config.js | 6 +++--- lib/index.js | 2 +- package.json | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 configs/index.js diff --git a/configs/index.js b/configs/index.js new file mode 100644 index 00000000..525f8576 --- /dev/null +++ b/configs/index.js @@ -0,0 +1,18 @@ +/** + * @fileoverview the configs for `eslint.config.js` + * @link https://eslint.org/docs/latest/use/configure/configuration-files-new + * @author 唯然 + */ + +'use strict'; + +const { configs, rules } = require('../lib/index.js'); +const configNames = Object.keys(configs); + +configNames.forEach((configName) => { + // the only difference is the `plugins` property must be an object + // TODO: we might better copy the config instead of mutating it, in case it's used by somewhere else + configs[configName].plugins = { 'eslint-plugin': { rules } }; +}); + +module.exports = configs; diff --git a/eslint.config.js b/eslint.config.js index 37dd1832..ee3e046d 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -19,7 +19,7 @@ const js = require('@eslint/js'); const { FlatCompat } = require('@eslint/eslintrc'); const globals = require('globals'); const markdown = require('eslint-plugin-markdown'); -const eslintPlugin = require('eslint-plugin-eslint-plugin'); +const eslintPluginConfig = require('eslint-plugin-eslint-plugin/configs').all; const compat = new FlatCompat({ baseDirectory: __dirname, @@ -63,8 +63,7 @@ module.exports = [ { // Apply eslint-plugin rules to our own rules/tests (but not docs). files: ['lib/**/*.js', 'tests/**/*.js'], - plugins: { 'eslint-plugin': eslintPlugin }, - ...eslintPlugin.configs.recommended, + ...eslintPluginConfig, rules: { 'eslint-plugin/report-message-format': ['error', '^[^a-z].*.$'], 'eslint-plugin/require-meta-docs-url': [ @@ -82,6 +81,7 @@ module.exports = [ }, { files: ['**/*.md'], + plugins: { markdown }, processor: 'markdown/markdown', }, { diff --git a/lib/index.js b/lib/index.js index e4044ab6..baab06b4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -47,7 +47,7 @@ module.exports.configs = Object.keys(configFilters).reduce( (configs, configName) => { return Object.assign(configs, { [configName]: { - // plugins: ['eslint-plugin'], + plugins: ['eslint-plugin'], rules: Object.fromEntries( Object.keys(allRules) .filter((ruleName) => configFilters[configName](allRules[ruleName])) diff --git a/package.json b/package.json index 758ffda6..85850327 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "main": "./lib/index.js", "exports": { ".": "./lib/index.js", + "./configs": "./configs/index.js", "./package.json": "./package.json" }, "license": "MIT", From a508c34d4651a3aa642e4ae30fa22d03167439fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 7 Apr 2023 14:44:15 +0800 Subject: [PATCH 3/8] chore: rm .eslintrc.js --- .eslintrc.js | 79 ------------------------------------------------ eslint.config.js | 15 --------- 2 files changed, 94 deletions(-) delete mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 4ff2ad29..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,79 +0,0 @@ -'use strict'; - -module.exports = { - root: true, - parserOptions: { - ecmaVersion: 2021, - sourceType: 'script', - }, - extends: [ - 'not-an-aardvark/node', - 'plugin:eslint-comments/recommended', - 'plugin:node/recommended', - 'plugin:prettier/recommended', - 'plugin:unicorn/recommended', - ], - rules: { - 'comma-dangle': [ - 'error', - { - arrays: 'always-multiline', - objects: 'always-multiline', - functions: 'never', // disallow trailing commas in function(es2017) - }, - ], - 'require-jsdoc': 'error', - - 'eslint-comments/no-unused-disable': 'error', - 'eslint-comments/require-description': 'error', - - 'unicorn/consistent-function-scoping': 'off', - 'unicorn/no-array-callback-reference': 'off', - 'unicorn/no-array-for-each': 'off', - 'unicorn/no-array-reduce': 'off', - 'unicorn/no-null': 'off', - 'unicorn/prefer-module': 'off', - 'unicorn/prefer-node-protocol': 'off', // TODO: enable once we drop support for Node 14.17. - 'unicorn/prevent-abbreviations': 'off', - }, - overrides: [ - { - // Apply eslint-plugin rules to our own rules/tests (but not docs). - files: ['lib/**/*.js', 'tests/**/*.js'], - extends: ['plugin:eslint-plugin/all'], - rules: { - 'eslint-plugin/report-message-format': ['error', '^[^a-z].*.$'], - 'eslint-plugin/require-meta-docs-url': [ - 'error', - { - pattern: - 'https://github.com/eslint-community/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/{{name}}.md', - }, - ], - }, - }, - { - files: ['tests/**/*.js'], - env: { mocha: true }, - }, - { - files: ['**/*.md'], - processor: 'markdown/markdown', - }, - { - // Markdown JS code samples in documentation: - files: ['**/*.md/*.js'], - plugins: ['markdown'], - noInlineConfig: true, - rules: { - 'no-undef': 'off', - 'no-unused-vars': 'off', - strict: 'off', - - 'eslint-comments/require-description': 'off', - - 'unicorn/filename-case': 'off', - }, - }, - ], -}; diff --git a/eslint.config.js b/eslint.config.js index ee3e046d..eeb4ad3c 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,20 +1,5 @@ 'use strict'; -/* - * IMPORTANT! - * - * Any changes made to this file must also be made to .eslintrc.js. - * - * Internally, ESLint is using the eslint.config.js file to lint itself. - * The .eslintrc.js file is needed too, because: - * - * 1. There are tests that expect .eslintrc.js to be present to actually run. - * 2. ESLint VS Code extension expects eslintrc config files to be - * present to work correctly. - * - * Once we no longer need to support both eslintrc and flat config, we will - * remove .eslintrc.js. - */ const js = require('@eslint/js'); const { FlatCompat } = require('@eslint/eslintrc'); const globals = require('globals'); From 6fde096213e8a1b10386064a273f0c41b0b62370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 7 Apr 2023 15:03:21 +0800 Subject: [PATCH 4/8] fix: publish configs directory --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 85850327..f8dc1fd7 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "update:eslint-docs": "eslint-doc-generator" }, "files": [ - "lib/" + "lib/", + "configs/" ], "keywords": [ "eslint", From 5ddd75c0ecc620211bc231abb993a837b4c7b1f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 21 Apr 2023 14:26:09 +0800 Subject: [PATCH 5/8] chore: move the configs to separate files --- README.md | 17 +++++++++++++++++ configs/all.js | 13 +++++++++++++ configs/index.js | 18 ------------------ configs/recommended.js | 13 +++++++++++++ configs/rules-recommended.js | 13 +++++++++++++ configs/rules.js | 13 +++++++++++++ configs/tests-recommended.js | 13 +++++++++++++ configs/tests.js | 13 +++++++++++++ eslint.config.js | 5 +++-- package.json | 2 +- 10 files changed, 99 insertions(+), 21 deletions(-) create mode 100644 configs/all.js delete mode 100644 configs/index.js create mode 100644 configs/recommended.js create mode 100644 configs/rules-recommended.js create mode 100644 configs/rules.js create mode 100644 configs/tests-recommended.js create mode 100644 configs/tests.js diff --git a/README.md b/README.md index 575a5190..769f1aa0 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ Here's an example ESLint configuration that: * Enables the `recommended` configuration * Enables an optional/non-recommended rule +### eslintrc + ```json { "parserOptions": { @@ -52,6 +54,21 @@ Here's an example ESLint configuration that: } ``` +### `eslint.config.js` + +```js +const eslintPluginRecommended = require("eslint-plugin-eslint-plugin/configs/recommended"); +module.exports = [ + eslintPluginRecommended, + { + languageOptions: {sourceType: "commonjs"}, + rules: { + "eslint-plugin/require-meta-docs-description": "error", + }, + }, +]; +``` + ## Rules diff --git a/configs/all.js b/configs/all.js new file mode 100644 index 00000000..27568984 --- /dev/null +++ b/configs/all.js @@ -0,0 +1,13 @@ +/** + * @fileoverview the `all` config for `eslint.config.js` + * @author 唯然 + */ + +'use strict'; + +const { configs, rules } = require('../lib/index.js'); + +module.exports = { + plugins: { 'eslint-plugin': { rules } }, + rules: configs.all.rules, +}; diff --git a/configs/index.js b/configs/index.js deleted file mode 100644 index 525f8576..00000000 --- a/configs/index.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * @fileoverview the configs for `eslint.config.js` - * @link https://eslint.org/docs/latest/use/configure/configuration-files-new - * @author 唯然 - */ - -'use strict'; - -const { configs, rules } = require('../lib/index.js'); -const configNames = Object.keys(configs); - -configNames.forEach((configName) => { - // the only difference is the `plugins` property must be an object - // TODO: we might better copy the config instead of mutating it, in case it's used by somewhere else - configs[configName].plugins = { 'eslint-plugin': { rules } }; -}); - -module.exports = configs; diff --git a/configs/recommended.js b/configs/recommended.js new file mode 100644 index 00000000..74c7cf23 --- /dev/null +++ b/configs/recommended.js @@ -0,0 +1,13 @@ +/** + * @fileoverview the `recommended` config for `eslint.config.js` + * @author 唯然 + */ + +'use strict'; + +const { configs, rules } = require('../lib/index.js'); + +module.exports = { + plugins: { 'eslint-plugin': { rules } }, + rules: configs.recommended.rules, +}; diff --git a/configs/rules-recommended.js b/configs/rules-recommended.js new file mode 100644 index 00000000..527d4fd0 --- /dev/null +++ b/configs/rules-recommended.js @@ -0,0 +1,13 @@ +/** + * @fileoverview the `rules-recommended` config for `eslint.config.js` + * @author 唯然 + */ + +'use strict'; + +const { configs, rules } = require('../lib/index.js'); + +module.exports = { + plugins: { 'eslint-plugin': { rules } }, + rules: configs['rules-recommended'].rules, +}; diff --git a/configs/rules.js b/configs/rules.js new file mode 100644 index 00000000..fd777c55 --- /dev/null +++ b/configs/rules.js @@ -0,0 +1,13 @@ +/** + * @fileoverview the `rules` config for `eslint.config.js` + * @author 唯然 + */ + +'use strict'; + +const { configs, rules } = require('../lib/index.js'); + +module.exports = { + plugins: { 'eslint-plugin': { rules } }, + rules: configs.rules.rules, +}; diff --git a/configs/tests-recommended.js b/configs/tests-recommended.js new file mode 100644 index 00000000..a872c478 --- /dev/null +++ b/configs/tests-recommended.js @@ -0,0 +1,13 @@ +/** + * @fileoverview the `tests-recommended` config for `eslint.config.js` + * @author 唯然 + */ + +'use strict'; + +const { configs, rules } = require('../lib/index.js'); + +module.exports = { + plugins: { 'eslint-plugin': { rules } }, + rules: configs['tests-recommended'].rules, +}; diff --git a/configs/tests.js b/configs/tests.js new file mode 100644 index 00000000..b0ac3235 --- /dev/null +++ b/configs/tests.js @@ -0,0 +1,13 @@ +/** + * @fileoverview the `tests` config for `eslint.config.js` + * @author 唯然 + */ + +'use strict'; + +const { configs, rules } = require('../lib/index.js'); + +module.exports = { + plugins: { 'eslint-plugin': { rules } }, + rules: configs.tests.rules, +}; diff --git a/eslint.config.js b/eslint.config.js index eeb4ad3c..94bebc30 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -4,7 +4,7 @@ const js = require('@eslint/js'); const { FlatCompat } = require('@eslint/eslintrc'); const globals = require('globals'); const markdown = require('eslint-plugin-markdown'); -const eslintPluginConfig = require('eslint-plugin-eslint-plugin/configs').all; +const eslintPluginConfig = require('eslint-plugin-eslint-plugin/configs/all'); const compat = new FlatCompat({ baseDirectory: __dirname, @@ -48,8 +48,9 @@ module.exports = [ { // Apply eslint-plugin rules to our own rules/tests (but not docs). files: ['lib/**/*.js', 'tests/**/*.js'], - ...eslintPluginConfig, + plugins: eslintPluginConfig.plugins, rules: { + ...eslintPluginConfig.rules, 'eslint-plugin/report-message-format': ['error', '^[^a-z].*.$'], 'eslint-plugin/require-meta-docs-url': [ 'error', diff --git a/package.json b/package.json index f8dc1fd7..06d72eeb 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "./lib/index.js", "exports": { ".": "./lib/index.js", - "./configs": "./configs/index.js", + "./configs/*": "./configs/*.js", "./package.json": "./package.json" }, "license": "MIT", From 430c991412c050656d1670fa1691303976efc8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 21 Apr 2023 19:36:09 +0800 Subject: [PATCH 6/8] docs: add links to eslint docs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 769f1aa0..9e240627 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Here's an example ESLint configuration that: * Enables the `recommended` configuration * Enables an optional/non-recommended rule -### eslintrc +### **[.eslintrc.json](https://eslint.org/docs/latest/use/configure/configuration-files)** ```json { @@ -54,7 +54,7 @@ Here's an example ESLint configuration that: } ``` -### `eslint.config.js` +### [`eslint.config.js`](https://eslint.org/docs/latest/use/configure/configuration-files-new) (requires eslint>=v8.23.0) ```js const eslintPluginRecommended = require("eslint-plugin-eslint-plugin/configs/recommended"); From e0048a8118cc875417b0d652ef4d7521d5c387dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 4 May 2023 09:56:09 +0800 Subject: [PATCH 7/8] fix: config.plugins --- configs/all.js | 6 +++--- configs/recommended.js | 6 +++--- configs/rules-recommended.js | 6 +++--- configs/rules.js | 6 +++--- configs/tests-recommended.js | 6 +++--- configs/tests.js | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/configs/all.js b/configs/all.js index 27568984..131aeea1 100644 --- a/configs/all.js +++ b/configs/all.js @@ -5,9 +5,9 @@ 'use strict'; -const { configs, rules } = require('../lib/index.js'); +const mod = require('../lib/index.js'); module.exports = { - plugins: { 'eslint-plugin': { rules } }, - rules: configs.all.rules, + plugins: { 'eslint-plugin': mod }, + rules: mod.configs.all.rules, }; diff --git a/configs/recommended.js b/configs/recommended.js index 74c7cf23..977b4e24 100644 --- a/configs/recommended.js +++ b/configs/recommended.js @@ -5,9 +5,9 @@ 'use strict'; -const { configs, rules } = require('../lib/index.js'); +const mod = require('../lib/index.js'); module.exports = { - plugins: { 'eslint-plugin': { rules } }, - rules: configs.recommended.rules, + plugins: { 'eslint-plugin': mod }, + rules: mod.configs.recommended.rules, }; diff --git a/configs/rules-recommended.js b/configs/rules-recommended.js index 527d4fd0..dd784e45 100644 --- a/configs/rules-recommended.js +++ b/configs/rules-recommended.js @@ -5,9 +5,9 @@ 'use strict'; -const { configs, rules } = require('../lib/index.js'); +const mod = require('../lib/index.js'); module.exports = { - plugins: { 'eslint-plugin': { rules } }, - rules: configs['rules-recommended'].rules, + plugins: { 'eslint-plugin': mod }, + rules: mod.configs['rules-recommended'].rules, }; diff --git a/configs/rules.js b/configs/rules.js index fd777c55..1a4f8a90 100644 --- a/configs/rules.js +++ b/configs/rules.js @@ -5,9 +5,9 @@ 'use strict'; -const { configs, rules } = require('../lib/index.js'); +const mod = require('../lib/index.js'); module.exports = { - plugins: { 'eslint-plugin': { rules } }, - rules: configs.rules.rules, + plugins: { 'eslint-plugin': mod }, + rules: mod.configs.rules.rules, }; diff --git a/configs/tests-recommended.js b/configs/tests-recommended.js index a872c478..41c50540 100644 --- a/configs/tests-recommended.js +++ b/configs/tests-recommended.js @@ -5,9 +5,9 @@ 'use strict'; -const { configs, rules } = require('../lib/index.js'); +const mod = require('../lib/index.js'); module.exports = { - plugins: { 'eslint-plugin': { rules } }, - rules: configs['tests-recommended'].rules, + plugins: { 'eslint-plugin': mod }, + rules: mod.configs['tests-recommended'].rules, }; diff --git a/configs/tests.js b/configs/tests.js index b0ac3235..53ea6c87 100644 --- a/configs/tests.js +++ b/configs/tests.js @@ -5,9 +5,9 @@ 'use strict'; -const { configs, rules } = require('../lib/index.js'); +const mod = require('../lib/index.js'); module.exports = { - plugins: { 'eslint-plugin': { rules } }, - rules: configs.tests.rules, + plugins: { 'eslint-plugin': mod }, + rules: mod.configs.tests.rules, }; From 421b8953cf0a316b82d02372fec9290fadca1fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 8 May 2023 14:46:40 +0800 Subject: [PATCH 8/8] chore: add metadata in the exported object refs: https://eslint.org/docs/latest/extend/plugins#metadata-in-plugins --- lib/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/index.js b/lib/index.js index baab06b4..4ff4ef76 100644 --- a/lib/index.js +++ b/lib/index.js @@ -41,6 +41,11 @@ const allRules = Object.fromEntries( ]) ); +module.exports.meta = { + name: packageMetadata.name, + version: packageMetadata.version, +}; + module.exports.rules = allRules; module.exports.configs = Object.keys(configFilters).reduce(