From 9c0e32260576f0684239c86ca7bc90aa58cff9cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 21 Apr 2023 18:53:53 +0800 Subject: [PATCH 01/13] feat: support eslint.config.js (fixes #89) --- README.md | 29 +++++++++++++++++++---------- configs/recommended-module.js | 13 +++++++++++++ configs/recommended-script.js | 13 +++++++++++++ configs/recommended.js | 13 +++++++++++++ package.json | 3 ++- 5 files changed, 60 insertions(+), 11 deletions(-) create mode 100644 configs/recommended-module.js create mode 100644 configs/recommended-script.js create mode 100644 configs/recommended.js diff --git a/README.md b/README.md index 19c75723..2568eee6 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,9 @@ npm install --save-dev eslint eslint-plugin-n - Requires Node.js `>=16.0.0` - Requires ESLint `>=7.0.0` -**.eslintrc.json** (An example) +**Note:** It recommends a use of [the "engines" field of package.json](https://docs.npmjs.com/files/package.json#engines). The "engines" field is used by `n/no-unsupported-features/*` rules. + +### **.eslintrc.json** (An example) ```jsonc { @@ -24,19 +26,26 @@ npm install --save-dev eslint eslint-plugin-n "ecmaVersion": 2021 }, "rules": { - "n/exports-style": ["error", "module.exports"], - "n/file-extension-in-import": ["error", "always"], - "n/prefer-global/buffer": ["error", "always"], - "n/prefer-global/console": ["error", "always"], - "n/prefer-global/process": ["error", "always"], - "n/prefer-global/url-search-params": ["error", "always"], - "n/prefer-global/url": ["error", "always"], - "n/prefer-promises/dns": "error", - "n/prefer-promises/fs": "error" + "n/exports-style": ["error", "module.exports"] } } ``` +### `eslint.config.js` + +```js +const nodeRecommended = require("eslint-plugin-n/configs/recommended") + +module.exports = [ + nodeRecommended, + { + rules: { + "n/exports-style": ["error", "module.exports"] + } + } +] +``` + **package.json** (An example) ```json diff --git a/configs/recommended-module.js b/configs/recommended-module.js new file mode 100644 index 00000000..99d500de --- /dev/null +++ b/configs/recommended-module.js @@ -0,0 +1,13 @@ +/** + * @fileoverview the `recommended-module` config for `eslint.config.js` + * @author 唯然 + */ + +"use strict" + +const { configs, rules } = require("../lib/index.js") + +module.exports = { + plugins: { n: { rules } }, + rules: configs["recommended-module"].rules, +} diff --git a/configs/recommended-script.js b/configs/recommended-script.js new file mode 100644 index 00000000..755714b9 --- /dev/null +++ b/configs/recommended-script.js @@ -0,0 +1,13 @@ +/** + * @fileoverview the `recommended-script` config for `eslint.config.js` + * @author 唯然 + */ + +"use strict" + +const { configs, rules } = require("../lib/index.js") + +module.exports = { + plugins: { n: { rules } }, + rules: configs["recommended-script"].rules, +} diff --git a/configs/recommended.js b/configs/recommended.js new file mode 100644 index 00000000..073ac071 --- /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: { n: { rules } }, + rules: configs.recommended.rules, +} diff --git a/package.json b/package.json index fb6bd395..5e6bd5a7 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ }, "main": "lib/index.js", "files": [ - "lib" + "lib/", + "configs/" ], "peerDependencies": { "eslint": ">=7.0.0" From cc19d35f7211e4863eaeaeb49ba64c6dd09cefe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 21 Apr 2023 19:08:19 +0800 Subject: [PATCH 02/13] fix: add languageOptions --- configs/recommended-module.js | 1 + configs/recommended-script.js | 1 + 2 files changed, 2 insertions(+) diff --git a/configs/recommended-module.js b/configs/recommended-module.js index 99d500de..36c9997a 100644 --- a/configs/recommended-module.js +++ b/configs/recommended-module.js @@ -9,5 +9,6 @@ const { configs, rules } = require("../lib/index.js") module.exports = { plugins: { n: { rules } }, + languageOptions: { sourceType: "module" }, rules: configs["recommended-module"].rules, } diff --git a/configs/recommended-script.js b/configs/recommended-script.js index 755714b9..bdfa9c49 100644 --- a/configs/recommended-script.js +++ b/configs/recommended-script.js @@ -9,5 +9,6 @@ const { configs, rules } = require("../lib/index.js") module.exports = { plugins: { n: { rules } }, + languageOptions: { sourceType: "script" }, rules: configs["recommended-script"].rules, } From 97d3d09bab9ec3a4a0e9d4d6f3a0e2f677014bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 21 Apr 2023 19:33:48 +0800 Subject: [PATCH 03/13] docs: add link to eslint docs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2568eee6..540b4fb9 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ npm install --save-dev eslint eslint-plugin-n **Note:** It recommends a use of [the "engines" field of package.json](https://docs.npmjs.com/files/package.json#engines). The "engines" field is used by `n/no-unsupported-features/*` rules. -### **.eslintrc.json** (An example) +### **[.eslintrc.json](https://eslint.org/docs/latest/use/configure/configuration-files)** (An example) ```jsonc { @@ -31,7 +31,7 @@ npm install --save-dev eslint eslint-plugin-n } ``` -### `eslint.config.js` +### [`eslint.config.js`](https://eslint.org/docs/latest/use/configure/configuration-files-new) (requires eslint>=v8.23.0) ```js const nodeRecommended = require("eslint-plugin-n/configs/recommended") From dea40ad3a1a11d90741f976523ba860cda4f9c1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 21 Apr 2023 19:53:53 +0800 Subject: [PATCH 04/13] chore: dogfooding the new config --- .eslintrc.js | 2 ++ configs/recommended-script.js | 2 +- eslint.config.js | 27 +++++++++++++++++++++++++++ package.json | 4 +++- 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 eslint.config.js diff --git a/.eslintrc.js b/.eslintrc.js index fdc5d9f4..564aca77 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,7 @@ /** * @author Toru Nagashima + * @deprecated + * @description the file is no longer used, and will be removed in the future. * See LICENSE file in root directory for full license. */ "use strict" diff --git a/configs/recommended-script.js b/configs/recommended-script.js index bdfa9c49..fcdfa5df 100644 --- a/configs/recommended-script.js +++ b/configs/recommended-script.js @@ -9,6 +9,6 @@ const { configs, rules } = require("../lib/index.js") module.exports = { plugins: { n: { rules } }, - languageOptions: { sourceType: "script" }, + languageOptions: { sourceType: "commonjs" }, rules: configs["recommended-script"].rules, } diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..96f92963 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,27 @@ +/** + * @author 唯然 + */ +"use strict" + +const js = require("@eslint/js") +const { FlatCompat } = require("@eslint/eslintrc") +const globals = require("globals") +const nodeRecommended = require("eslint-plugin-n/configs/recommended-script") + +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, +}) + +module.exports = [ + ...compat.extends( + "eslint:recommended", + "plugin:eslint-plugin/recommended", + "prettier" + ), + nodeRecommended, + { + languageOptions: { globals: globals.mocha }, + linterOptions: { reportUnusedDisableDirectives: true }, + }, +] diff --git a/package.json b/package.json index 5e6bd5a7..ff983bf1 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,9 @@ "eslint": ">=7.0.0" }, "dependencies": { + "@eslint-community/eslint-utils": "^4.4.0", "builtins": "^5.0.1", "eslint-plugin-es-x": "^6.1.0", - "@eslint-community/eslint-utils": "^4.4.0", "ignore": "^5.1.1", "is-core-module": "^2.12.0", "minimatch": "^3.1.2", @@ -24,6 +24,8 @@ "semver": "^7.5.0" }, "devDependencies": { + "@eslint/eslintrc": "^2.0.2", + "@eslint/js": "^8.38.0", "@typescript-eslint/parser": "^5.59.0", "codecov": "^3.3.0", "esbuild": "^0.17.17", From a3a0dfb3ca480e872b6eb5832372f5d3b785b534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 21 Apr 2023 20:06:16 +0800 Subject: [PATCH 05/13] chore: fix linting errors --- eslint.config.js | 2 +- lib/util/check-unsupported-builtins.js | 2 +- lib/util/get-configured-node-version.js | 2 +- package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 96f92963..cc6b3a51 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -15,7 +15,7 @@ const compat = new FlatCompat({ module.exports = [ ...compat.extends( - "eslint:recommended", + // "eslint:recommended", // TODO: adding this line will cause commonjs globals to be undefined "plugin:eslint-plugin/recommended", "prettier" ), diff --git a/lib/util/check-unsupported-builtins.js b/lib/util/check-unsupported-builtins.js index 7e0c0009..cdae621f 100644 --- a/lib/util/check-unsupported-builtins.js +++ b/lib/util/check-unsupported-builtins.js @@ -4,7 +4,7 @@ */ "use strict" -const { Range, lt, major } = require("semver") //eslint-disable-line no-unused-vars +const { Range, lt, major } = require("semver") const { ReferenceTracker } = require("@eslint-community/eslint-utils") const getConfiguredNodeVersion = require("./get-configured-node-version") const getSemverRange = require("./get-semver-range") diff --git a/lib/util/get-configured-node-version.js b/lib/util/get-configured-node-version.js index c1395d7f..cca6a23c 100644 --- a/lib/util/get-configured-node-version.js +++ b/lib/util/get-configured-node-version.js @@ -4,7 +4,7 @@ */ "use strict" -const { Range } = require("semver") //eslint-disable-line no-unused-vars +const { Range } = require("semver") const getPackageJson = require("./get-package-json") const getSemverRange = require("./get-semver-range") diff --git a/package.json b/package.json index ff983bf1..1e368d16 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "lint": "npm-run-all \"lint:*\"", "lint:docs": "markdownlint \"**/*.md\"", "lint:eslint-docs": "npm run update:eslint-docs -- --check", - "lint:js": "eslint lib scripts tests/lib .eslintrc.js", + "lint:js": "eslint lib scripts tests/lib eslint.config.js", "new": "node scripts/new-rule", "postversion": "git push && git push --tags", "prepare": "npx husky install", From 58cbfcb4242a63d70049da86ec1c55d421e7a517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 28 Apr 2023 17:46:00 +0800 Subject: [PATCH 06/13] chore: add metadata in the exported object refs: https://eslint.org/docs/latest/extend/plugins#metadata-in-plugins --- lib/index.js | 6 ++++++ scripts/update-lib-index.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/index.js b/lib/index.js index b391396f..341c86df 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,7 +1,13 @@ /* DON'T EDIT THIS FILE. This is generated by 'scripts/update-lib-index.js' */ "use strict" +const pkg = require("../package.json") + module.exports = { + meta: { + name: pkg.name, + version: pkg.version, + }, configs: { "recommended-module": require("./configs/recommended-module"), "recommended-script": require("./configs/recommended-script"), diff --git a/scripts/update-lib-index.js b/scripts/update-lib-index.js index aaa7fa07..7dc04003 100644 --- a/scripts/update-lib-index.js +++ b/scripts/update-lib-index.js @@ -13,7 +13,13 @@ const filePath = path.resolve(__dirname, "../lib/index.js") const rawContent = `/* DON'T EDIT THIS FILE. This is generated by 'scripts/update-lib-index.js' */ "use strict" +const pkg = require("../package.json") + module.exports = { + meta: { + name: pkg.name, + version: pkg.version, + }, configs: { "recommended-module": require("./configs/recommended-module"), "recommended-script": require("./configs/recommended-script"), From ccfbeb3f518d816f3f070611be8cda2c5db1802e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Sun, 30 Apr 2023 01:04:00 +0800 Subject: [PATCH 07/13] fix: config.plugins https://github.com/eslint-community/eslint-plugin-n/pull/95#discussion_r1180325139 --- configs/recommended-module.js | 6 +++--- configs/recommended-script.js | 6 +++--- configs/recommended.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/configs/recommended-module.js b/configs/recommended-module.js index 36c9997a..6ce5d2e2 100644 --- a/configs/recommended-module.js +++ b/configs/recommended-module.js @@ -5,10 +5,10 @@ "use strict" -const { configs, rules } = require("../lib/index.js") +const mod = require("../lib/index.js") module.exports = { - plugins: { n: { rules } }, + plugins: { n: mod }, languageOptions: { sourceType: "module" }, - rules: configs["recommended-module"].rules, + rules: mod.configs["recommended-module"].rules, } diff --git a/configs/recommended-script.js b/configs/recommended-script.js index fcdfa5df..bdd74fa8 100644 --- a/configs/recommended-script.js +++ b/configs/recommended-script.js @@ -5,10 +5,10 @@ "use strict" -const { configs, rules } = require("../lib/index.js") +const mod = require("../lib/index.js") module.exports = { - plugins: { n: { rules } }, + plugins: { n: mod }, languageOptions: { sourceType: "commonjs" }, - rules: configs["recommended-script"].rules, + rules: mod.configs["recommended-script"].rules, } diff --git a/configs/recommended.js b/configs/recommended.js index 073ac071..efad6f2f 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: { n: { rules } }, - rules: configs.recommended.rules, + plugins: { n: mod }, + rules: mod.configs.recommended.rules, } From 52125ffd8ad8be9b84fdb8d47577820b9ae10363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Sun, 30 Apr 2023 01:21:00 +0800 Subject: [PATCH 08/13] fix: add globals config refs: https://github.com/eslint-community/eslint-plugin-n/pull/95#discussion_r1180506643 --- configs/recommended-module.js | 5 ++++- configs/recommended-script.js | 5 ++++- configs/recommended.js | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/configs/recommended-module.js b/configs/recommended-module.js index 6ce5d2e2..8c676422 100644 --- a/configs/recommended-module.js +++ b/configs/recommended-module.js @@ -9,6 +9,9 @@ const mod = require("../lib/index.js") module.exports = { plugins: { n: mod }, - languageOptions: { sourceType: "module" }, + languageOptions: { + sourceType: "module", + globals: mod.configs["recommended-module"].globals, + }, rules: mod.configs["recommended-module"].rules, } diff --git a/configs/recommended-script.js b/configs/recommended-script.js index bdd74fa8..a6df853e 100644 --- a/configs/recommended-script.js +++ b/configs/recommended-script.js @@ -9,6 +9,9 @@ const mod = require("../lib/index.js") module.exports = { plugins: { n: mod }, - languageOptions: { sourceType: "commonjs" }, + languageOptions: { + sourceType: "commonjs", + globals: mod.configs["recommended-script"].globals, + }, rules: mod.configs["recommended-script"].rules, } diff --git a/configs/recommended.js b/configs/recommended.js index efad6f2f..25efe9c4 100644 --- a/configs/recommended.js +++ b/configs/recommended.js @@ -9,5 +9,6 @@ const mod = require("../lib/index.js") module.exports = { plugins: { n: mod }, + languageOptions: { globals: mod.configs.recommended.globals }, rules: mod.configs.recommended.rules, } From 4eea92b66da37455f1215303149d4c1e6de3f1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Sun, 30 Apr 2023 01:22:01 +0800 Subject: [PATCH 09/13] chore: update eslint config --- .eslintignore | 7 ------- eslint.config.js | 5 ++++- lib/util/check-unsupported-builtins.js | 2 +- lib/util/get-configured-node-version.js | 2 +- package.json | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) delete mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 4ca9f9c6..00000000 --- a/.eslintignore +++ /dev/null @@ -1,7 +0,0 @@ -!.* - -/.nyc_output -/coverage -/docs -/node_modules -/lib/converted-esm \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js index cc6b3a51..ce7425ed 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -15,7 +15,7 @@ const compat = new FlatCompat({ module.exports = [ ...compat.extends( - // "eslint:recommended", // TODO: adding this line will cause commonjs globals to be undefined + "eslint:recommended", "plugin:eslint-plugin/recommended", "prettier" ), @@ -24,4 +24,7 @@ module.exports = [ languageOptions: { globals: globals.mocha }, linterOptions: { reportUnusedDisableDirectives: true }, }, + { + ignores: [".nyc_output/", "coverage/", "docs/", "lib/converted-esm/"], + }, ] diff --git a/lib/util/check-unsupported-builtins.js b/lib/util/check-unsupported-builtins.js index cdae621f..79b8f1e4 100644 --- a/lib/util/check-unsupported-builtins.js +++ b/lib/util/check-unsupported-builtins.js @@ -4,7 +4,7 @@ */ "use strict" -const { Range, lt, major } = require("semver") +const { Range, lt, major } = require("semver") // eslint-disable-line no-unused-vars const { ReferenceTracker } = require("@eslint-community/eslint-utils") const getConfiguredNodeVersion = require("./get-configured-node-version") const getSemverRange = require("./get-semver-range") diff --git a/lib/util/get-configured-node-version.js b/lib/util/get-configured-node-version.js index cca6a23c..ed235fa7 100644 --- a/lib/util/get-configured-node-version.js +++ b/lib/util/get-configured-node-version.js @@ -4,7 +4,7 @@ */ "use strict" -const { Range } = require("semver") +const { Range } = require("semver") // eslint-disable-line no-unused-vars const getPackageJson = require("./get-package-json") const getSemverRange = require("./get-semver-range") diff --git a/package.json b/package.json index 1e368d16..fcb22b2c 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "lint": "npm-run-all \"lint:*\"", "lint:docs": "markdownlint \"**/*.md\"", "lint:eslint-docs": "npm run update:eslint-docs -- --check", - "lint:js": "eslint lib scripts tests/lib eslint.config.js", + "lint:js": "eslint .", "new": "node scripts/new-rule", "postversion": "git push && git push --tags", "prepare": "npx husky install", From e5585fa38baea514965062d481a8553421cde041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Sun, 30 Apr 2023 01:30:28 +0800 Subject: [PATCH 10/13] chore: use predefined eslint:recommended --- eslint.config.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index ce7425ed..5898aa3a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -14,17 +14,12 @@ const compat = new FlatCompat({ }) module.exports = [ - ...compat.extends( - "eslint:recommended", - "plugin:eslint-plugin/recommended", - "prettier" - ), - nodeRecommended, { languageOptions: { globals: globals.mocha }, linterOptions: { reportUnusedDisableDirectives: true }, - }, - { ignores: [".nyc_output/", "coverage/", "docs/", "lib/converted-esm/"], }, + js.configs.recommended, + nodeRecommended, + ...compat.extends("plugin:eslint-plugin/recommended", "prettier"), ] From 4979148927a67e5e15fd824aa2c7d05fd6fac765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 5 May 2023 14:15:13 +0800 Subject: [PATCH 11/13] fix: global ignores should not be used with other keys https://eslint.org/docs/latest/use/configure/configuration-files-new#globally-ignoring-files-with-ignores --- eslint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eslint.config.js b/eslint.config.js index 5898aa3a..dfd58673 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -17,8 +17,8 @@ module.exports = [ { languageOptions: { globals: globals.mocha }, linterOptions: { reportUnusedDisableDirectives: true }, - ignores: [".nyc_output/", "coverage/", "docs/", "lib/converted-esm/"], }, + { ignores: [".nyc_output/", "coverage/", "docs/", "lib/converted-esm/"] }, js.configs.recommended, nodeRecommended, ...compat.extends("plugin:eslint-plugin/recommended", "prettier"), From 5fc4dac57e26d8ffb10fa363ccae4b1a8b903155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 11 May 2023 11:05:32 +0800 Subject: [PATCH 12/13] fix: remove recommended config --- README.md | 23 +++++++++++++++++++++-- configs/recommended.js | 14 -------------- 2 files changed, 21 insertions(+), 16 deletions(-) delete mode 100644 configs/recommended.js diff --git a/README.md b/README.md index 540b4fb9..960ef19f 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,10 @@ npm install --save-dev eslint eslint-plugin-n ### [`eslint.config.js`](https://eslint.org/docs/latest/use/configure/configuration-files-new) (requires eslint>=v8.23.0) ```js -const nodeRecommended = require("eslint-plugin-n/configs/recommended") +const nodeRecommendedScript = require("eslint-plugin-n/configs/recommended-script") module.exports = [ - nodeRecommended, + nodeRecommendedScript, { rules: { "n/exports-style": ["error", "module.exports"] @@ -172,6 +172,25 @@ These preset configs: - Q: The `no-missing-import` / `no-missing-require` rules don't work with nested folders in SublimeLinter-eslint - A: See [context.getFilename() in rule returns relative path](https://github.com/roadhump/SublimeLinter-eslint#contextgetfilename-in-rule-returns-relative-path) in the SublimeLinter-eslint FAQ. +- Q: How to use the new eslint config with mixed commonjs and es modules? +- A: The `recommended` config is no longer exported. You can create a config based on `recommended-script` and `recommended-module`. + +```js +const nodeRecommendedScript = require("eslint-plugin-n/configs/recommended-script"); +const nodeRecommendedModule = require("eslint-plugin-n/configs/recommended-module"); + +module.exports = [ + { + files: ["**/*.js", "**/*.cjs"], + ...nodeRecommendedScript + }, + { + files: ["**/*.mjs"], + ...nodeRecommendedModule + } +] +``` + ## 🚥 Semantic Versioning Policy `eslint-plugin-n` follows [semantic versioning](http://semver.org/) and [ESLint's Semantic Versioning Policy](https://github.com/eslint/eslint#semantic-versioning-policy). diff --git a/configs/recommended.js b/configs/recommended.js deleted file mode 100644 index 25efe9c4..00000000 --- a/configs/recommended.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @fileoverview the `recommended` config for `eslint.config.js` - * @author 唯然 - */ - -"use strict" - -const mod = require("../lib/index.js") - -module.exports = { - plugins: { n: mod }, - languageOptions: { globals: mod.configs.recommended.globals }, - rules: mod.configs.recommended.rules, -} From dcf6f66437195cf8fbef2f8f4a78d873da9be9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 15 May 2023 10:22:32 +0800 Subject: [PATCH 13/13] chore: update eslint.config.js --- README.md | 2 +- eslint.config.js | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 960ef19f..76740fb9 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ These preset configs: - A: See [context.getFilename() in rule returns relative path](https://github.com/roadhump/SublimeLinter-eslint#contextgetfilename-in-rule-returns-relative-path) in the SublimeLinter-eslint FAQ. - Q: How to use the new eslint config with mixed commonjs and es modules? -- A: The `recommended` config is no longer exported. You can create a config based on `recommended-script` and `recommended-module`. +- A: The `recommended` config is no longer exported. You can create a config based on `recommended-script` and `recommended-module`. An example: ```js const nodeRecommendedScript = require("eslint-plugin-n/configs/recommended-script"); diff --git a/eslint.config.js b/eslint.config.js index dfd58673..7e50e9a2 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -18,8 +18,24 @@ module.exports = [ languageOptions: { globals: globals.mocha }, linterOptions: { reportUnusedDisableDirectives: true }, }, - { ignores: [".nyc_output/", "coverage/", "docs/", "lib/converted-esm/"] }, + { + ignores: [ + ".nyc_output/", + "coverage/", + "docs/", + "lib/converted-esm/", + "test/fixtures/", + ], + }, js.configs.recommended, nodeRecommended, ...compat.extends("plugin:eslint-plugin/recommended", "prettier"), + { rules: { "eslint-plugin/require-meta-docs-description": "error" } }, + { + // these messageIds were used outside + files: ["lib/rules/prefer-global/*.js"], + rules: { + "eslint-plugin/no-unused-message-ids": 0, + }, + }, ]