From 058a505f22ff587c60c7c5a00cd6cdcde5476269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 28 Mar 2024 18:23:47 +0800 Subject: [PATCH] feat: re-export flat configs "flat/*" long-time plan: v6: no action v7: rename 'flat/*' => '*'; eslintrc config '*' => 'legacy/*'? v8~: remove eslintrc supports --- configs/all-type-checked.js | 11 ++++++----- configs/all.js | 8 +++----- configs/recommended.js | 8 +++----- configs/rules-recommended.js | 8 +++----- configs/rules.js | 8 +++----- configs/tests-recommended.js | 8 +++----- configs/tests.js | 8 +++----- lib/index.js | 38 ++++++++++++++++++++++++++++-------- package.json | 14 ++++++------- 9 files changed, 61 insertions(+), 50 deletions(-) diff --git a/configs/all-type-checked.js b/configs/all-type-checked.js index e32d57d2..2ab83414 100644 --- a/configs/all-type-checked.js +++ b/configs/all-type-checked.js @@ -1,8 +1,9 @@ +/** + * @deprecated use 'flat/all-type-checked' instead + * @author 唯然 + */ 'use strict'; -const mod = require('../lib/index.js'); +const plugin = require('../lib/index.js'); -module.exports = { - plugins: { 'eslint-plugin': mod }, - rules: mod.configs['all-type-checked'].rules, -}; +module.exports = plugin.configs['flat/all-type-checked'] diff --git a/configs/all.js b/configs/all.js index 131aeea1..31286cb3 100644 --- a/configs/all.js +++ b/configs/all.js @@ -1,13 +1,11 @@ /** * @fileoverview the `all` config for `eslint.config.js` + * @deprecated use 'flat/all' instead * @author 唯然 */ 'use strict'; -const mod = require('../lib/index.js'); +const plugin = require('../lib/index.js'); -module.exports = { - plugins: { 'eslint-plugin': mod }, - rules: mod.configs.all.rules, -}; +module.exports = plugin.configs['flat/all'] diff --git a/configs/recommended.js b/configs/recommended.js index 977b4e24..a336aa36 100644 --- a/configs/recommended.js +++ b/configs/recommended.js @@ -1,13 +1,11 @@ /** * @fileoverview the `recommended` config for `eslint.config.js` + * @deprecated use 'flat/recommended' instead * @author 唯然 */ 'use strict'; -const mod = require('../lib/index.js'); +const plugin = require('../lib/index.js'); -module.exports = { - plugins: { 'eslint-plugin': mod }, - rules: mod.configs.recommended.rules, -}; +module.exports = plugin.configs['flat/recommended'] diff --git a/configs/rules-recommended.js b/configs/rules-recommended.js index dd784e45..09673997 100644 --- a/configs/rules-recommended.js +++ b/configs/rules-recommended.js @@ -1,13 +1,11 @@ /** * @fileoverview the `rules-recommended` config for `eslint.config.js` + * @deprecated use 'flat/rules-recommended' instead * @author 唯然 */ 'use strict'; -const mod = require('../lib/index.js'); +const plugin = require('../lib/index.js'); -module.exports = { - plugins: { 'eslint-plugin': mod }, - rules: mod.configs['rules-recommended'].rules, -}; +module.exports = plugin.configs['flat/rules-recommended'] diff --git a/configs/rules.js b/configs/rules.js index 1a4f8a90..8a84bc4b 100644 --- a/configs/rules.js +++ b/configs/rules.js @@ -1,13 +1,11 @@ /** * @fileoverview the `rules` config for `eslint.config.js` + * @deprecated use 'flat/rules' instead * @author 唯然 */ 'use strict'; -const mod = require('../lib/index.js'); +const plugin = require('../lib/index.js'); -module.exports = { - plugins: { 'eslint-plugin': mod }, - rules: mod.configs.rules.rules, -}; +module.exports = plugin.configs['flat/rules'] diff --git a/configs/tests-recommended.js b/configs/tests-recommended.js index 41c50540..19d56bf9 100644 --- a/configs/tests-recommended.js +++ b/configs/tests-recommended.js @@ -1,13 +1,11 @@ /** * @fileoverview the `tests-recommended` config for `eslint.config.js` + * @deprecated use 'flat/tests-recommended' instead * @author 唯然 */ 'use strict'; -const mod = require('../lib/index.js'); +const plugin = require('../lib/index.js'); -module.exports = { - plugins: { 'eslint-plugin': mod }, - rules: mod.configs['tests-recommended'].rules, -}; +module.exports = plugin.configs['flat/tests-recommended'] diff --git a/configs/tests.js b/configs/tests.js index 53ea6c87..faa0c161 100644 --- a/configs/tests.js +++ b/configs/tests.js @@ -1,13 +1,11 @@ /** * @fileoverview the `tests` config for `eslint.config.js` + * @deprecated use 'flat/tests' instead * @author 唯然 */ 'use strict'; -const mod = require('../lib/index.js'); +const plugin = require('../lib/index.js'); -module.exports = { - plugins: { 'eslint-plugin': mod }, - rules: mod.configs.tests.rules, -}; +module.exports = plugin.configs['flat/tests'] diff --git a/lib/index.js b/lib/index.js index b09550a2..10a607fe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -42,14 +42,17 @@ const allRules = Object.fromEntries( ]) ); -module.exports.meta = { - name: packageMetadata.name, - version: packageMetadata.version, -}; - -module.exports.rules = allRules; +const plugin = { + meta: { + name: packageMetadata.name, + version: packageMetadata.version, + }, + rules: allRules, + configs: {}, // assigned later +} -module.exports.configs = Object.keys(configFilters).reduce( +// eslintrc configs +Object.assign(plugin.configs, Object.keys(configFilters).reduce( (configs, configName) => { return Object.assign(configs, { [configName]: { @@ -63,4 +66,23 @@ module.exports.configs = Object.keys(configFilters).reduce( }); }, {} -); +)); + +// flat configs +Object.assign(plugin.configs, Object.keys(configFilters).reduce( + (configs, configName) => { + return Object.assign(configs, { + [`flat/${configName}`]: { + plugins: { 'eslint-plugin': plugin}, + rules: Object.fromEntries( + Object.keys(allRules) + .filter((ruleName) => configFilters[configName](allRules[ruleName])) + .map((ruleName) => [`${PLUGIN_NAME}/${ruleName}`, 'error']) + ), + }, + }); + }, + {} +)); + +module.exports = plugin; diff --git a/package.json b/package.json index c8b532e1..08a8fb98 100644 --- a/package.json +++ b/package.json @@ -53,15 +53,15 @@ "@commitlint/cli": "^17.1.2", "@commitlint/config-conventional": "^17.1.0", "@eslint/eslintrc": "^2.0.2", - "@eslint/js": "^8.37.0", + "@eslint/js": "^8.57.0", "@release-it/conventional-changelog": "^4.3.0", - "@types/eslint": "^8.56.2", + "@types/eslint": "^8.56.6", "@types/estree": "^1.0.5", "@typescript-eslint/parser": "^5.62.0", "@typescript-eslint/utils": "^5.62.0", "chai": "^4.3.6", "dirty-chai": "^2.0.1", - "eslint": "^8.23.0", + "eslint": "^8.57.0", "eslint-config-not-an-aardvark": "^2.1.0", "eslint-config-prettier": "^8.5.0", "eslint-doc-generator": "^1.7.0", @@ -78,13 +78,13 @@ "husky": "^8.0.1", "lodash": "^4.17.21", "markdownlint-cli": "^0.39.0", - "mocha": "^10.0.0", - "npm-package-json-lint": "^7.0.0", - "npm-run-all2": "^5.0.0", + "mocha": "^10.4.0", + "npm-package-json-lint": "^7.1.0", + "npm-run-all2": "^6.1.2", "nyc": "^15.1.0", "prettier": "^2.7.1", "release-it": "^14.14.3", - "typescript": "^5.1.3" + "typescript": "^5.4.3" }, "peerDependencies": { "eslint": ">=7.0.0"