Skip to content

Commit

Permalink
feat: export flat/recommended-script and flat/recommended-module (#113)
Browse files Browse the repository at this point in the history
`eslint-plugin-n/configs/recommended-script` & `eslint-plugin-n/configs/recommended-module` are deprecated and may be removed in future majors.
  • Loading branch information
aladdin-add committed Sep 8, 2023
1 parent 20d2713 commit 1f8fdc8
Show file tree
Hide file tree
Showing 27 changed files with 192 additions and 271 deletions.
13 changes: 13 additions & 0 deletions .eslint-doc-generatorrc.js
@@ -0,0 +1,13 @@
"use strict"
const config = {
urlConfigs: "https://github.com/eslint-community/eslint-plugin-n#-configs",
configEmoji: [
["recommended-script", "✅"],
["recommended-module", "🟢"],
["recommended", "☑️"],
["flat/recommended-script", "✅"],
["flat/recommended-module", "🟢"],
],
}

module.exports = config
102 changes: 0 additions & 102 deletions .eslintrc.js

This file was deleted.

123 changes: 56 additions & 67 deletions README.md

Large diffs are not rendered by default.

12 changes: 2 additions & 10 deletions configs/recommended-module.js
@@ -1,17 +1,9 @@
/**
* @fileoverview the `recommended-module` config for `eslint.config.js`
* @author 唯然<weiran.zsd@outlook.com>
* @deprecated use `flat/recommended-module` instead
*/

"use strict"

const mod = require("../lib/index.js")

module.exports = {
plugins: { n: mod },
languageOptions: {
sourceType: "module",
globals: mod.configs["recommended-module"].globals,
},
rules: mod.configs["recommended-module"].rules,
}
module.exports = require("../lib/index.js").configs["flat/recommended-module"]
12 changes: 2 additions & 10 deletions configs/recommended-script.js
@@ -1,17 +1,9 @@
/**
* @fileoverview the `recommended-script` config for `eslint.config.js`
* @author 唯然<weiran.zsd@outlook.com>
* @deprecated use `flat/recommended-script` instead
*/

"use strict"

const mod = require("../lib/index.js")

module.exports = {
plugins: { n: mod },
languageOptions: {
sourceType: "commonjs",
globals: mod.configs["recommended-script"].globals,
},
rules: mod.configs["recommended-script"].rules,
}
module.exports = require("../lib/index.js").configs["flat/recommended-script"]
2 changes: 1 addition & 1 deletion docs/rules/no-deprecated-api.md
@@ -1,6 +1,6 @@
# Disallow deprecated APIs (`n/no-deprecated-api`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-exports-assign.md
@@ -1,6 +1,6 @@
# Disallow the assignment to `exports` (`n/no-exports-assign`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-extraneous-import.md
@@ -1,6 +1,6 @@
# Disallow `import` declarations which import extraneous modules (`n/no-extraneous-import`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-extraneous-require.md
@@ -1,6 +1,6 @@
# Disallow `require()` expressions which import extraneous modules (`n/no-extraneous-require`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-missing-import.md
@@ -1,6 +1,6 @@
# Disallow `import` declarations which import non-existence modules (`n/no-missing-import`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-missing-require.md
@@ -1,6 +1,6 @@
# Disallow `require()` expressions which import non-existence modules (`n/no-missing-require`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-process-exit.md
@@ -1,6 +1,6 @@
# Disallow the use of `process.exit()` (`n/no-process-exit`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-unpublished-bin.md
@@ -1,6 +1,6 @@
# Disallow `bin` files that npm ignores (`n/no-unpublished-bin`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-unpublished-import.md
@@ -1,6 +1,6 @@
# Disallow `import` declarations which import private modules (`n/no-unpublished-import`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-unpublished-require.md
@@ -1,6 +1,6 @@
# Disallow `require()` expressions which import private modules (`n/no-unpublished-require`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-unsupported-features/es-builtins.md
@@ -1,6 +1,6 @@
# Disallow unsupported ECMAScript built-ins on the specified version (`n/no-unsupported-features/es-builtins`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-unsupported-features/es-syntax.md
@@ -1,6 +1,6 @@
# Disallow unsupported ECMAScript syntax on the specified version (`n/no-unsupported-features/es-syntax`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-unsupported-features/node-builtins.md
@@ -1,6 +1,6 @@
# Disallow unsupported Node.js built-in APIs on the specified version (`n/no-unsupported-features/node-builtins`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/process-exit-as-throw.md
@@ -1,6 +1,6 @@
# Require that `process.exit()` expressions use the same code path as `throw` (`n/process-exit-as-throw`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

<!-- end auto-generated rule header -->

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/shebang.md
@@ -1,6 +1,6 @@
# Require correct usage of shebang (`n/shebang`)

💼 This rule is enabled in the `recommended` [config](https://github.com/eslint-community/eslint-plugin-n#-configs).
💼 This rule is enabled in the following [configs](https://github.com/eslint-community/eslint-plugin-n#-configs): 🟢 `flat/recommended-module`, ✅ `flat/recommended-script`, ☑️ `recommended`, 🟢 `recommended-module`, ✅ `recommended-script`.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

Expand Down
13 changes: 11 additions & 2 deletions lib/configs/recommended-module.js
Expand Up @@ -2,7 +2,8 @@

const { commonGlobals, commonRules } = require("./_commons")

module.exports = {
// eslintrc config: https://eslint.org/docs/latest/use/configure/configuration-files
module.exports.eslintrc = {
globals: {
...commonGlobals,
__dirname: "off",
Expand All @@ -16,7 +17,6 @@ module.exports = {
ecmaVersion: 2021,
sourceType: "module",
},
plugins: ["n"],
rules: {
...commonRules,
"n/no-unsupported-features/es-syntax": [
Expand All @@ -25,3 +25,12 @@ module.exports = {
],
},
}

// flat config: https://eslint.org/docs/latest/use/configure/configuration-files-new
module.exports.flat = {
languageOptions: {
sourceType: "module",
globals: module.exports.eslintrc.globals,
},
rules: module.exports.eslintrc.rules,
}
13 changes: 11 additions & 2 deletions lib/configs/recommended-script.js
Expand Up @@ -2,7 +2,8 @@

const { commonGlobals, commonRules } = require("./_commons")

module.exports = {
// eslintrc config: https://eslint.org/docs/latest/use/configure/configuration-files
module.exports.eslintrc = {
globals: {
...commonGlobals,
__dirname: "readonly",
Expand All @@ -16,9 +17,17 @@ module.exports = {
ecmaVersion: 2021,
sourceType: "script",
},
plugins: ["n"],
rules: {
...commonRules,
"n/no-unsupported-features/es-syntax": ["error", { ignores: [] }],
},
}

// https://eslint.org/docs/latest/use/configure/configuration-files-new
module.exports.flat = {
languageOptions: {
sourceType: "commonjs",
globals: module.exports.eslintrc.globals,
},
rules: module.exports.eslintrc.rules,
}
21 changes: 11 additions & 10 deletions lib/configs/recommended.js
Expand Up @@ -4,15 +4,16 @@ const getPackageJson = require("../util/get-package-json")
const moduleConfig = require("./recommended-module")
const scriptConfig = require("./recommended-script")

module.exports = () => {
const packageJson = getPackageJson()
const isModule = (packageJson && packageJson.type) === "module"
const packageJson = getPackageJson()
const isModule = (packageJson && packageJson.type) === "module"
const recommendedConfig = isModule ? moduleConfig : scriptConfig

return {
...(isModule ? moduleConfig : scriptConfig),
overrides: [
{ files: ["*.cjs", ".*.cjs"], ...scriptConfig },
{ files: ["*.mjs", ".*.mjs"], ...moduleConfig },
],
}
module.exports.eslintrc = {
...recommendedConfig.eslintrc,
overrides: [
{ files: ["*.cjs", ".*.cjs"], ...scriptConfig.eslintrc },
{ files: ["*.mjs", ".*.mjs"], ...moduleConfig.eslintrc },
],
}

module.exports.flat = recommendedConfig.flat

0 comments on commit 1f8fdc8

Please sign in to comment.