Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export flat/recommended-script and flat/recommended-module #113

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
@@ -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", "🟢"],
Comment on lines +8 to +9
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmish I am uncertain about the optimal approach here - having the same rules in both flat config and eslintrc config. Therefore, it may not be necessary to duplicate emojis. thoughts?

Copy link
Member

@bmish bmish Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure I have the right context, is exporting a config twice (under one name for eslintrc, and under another name for flat config) the recommended approach to support both kinds of configs? Does ESLint mention a recommendation about this somewhere?

Using the same emoji for multiple configs, even if they are intended to represent a single config, seems confusing and breaks assumptions that each config has a unique emoji.

Some options to handle this:

  1. eslint-doc-generator should not allow the same emoji for multiple configs. Perhaps we can recommend using the same emoji but different colors for eslintrc vs. flat?
  2. eslint-doc-generator allows the same emoji for multiple configs, but better display/handling (e.g. avoid repeating the emoji in the readme rules table).
  3. eslint-doc-generator adds some special handling/representation to indicate that one config is the flat version of an eslintrc config. But not sure how this can be reliably detected.

I personally prefer 1 as of now.

Related: bmish/eslint-doc-generator#376

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not something recommended by eslint - The examples in the eslint documentation use eslint-plugin-jsdoc, which is how this plugin is exported. Personally, I'd like to stay as close as possible to the usage in the documentation, or do you have a better recommendation?

eslint/eslint@056499d

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer 2>1>3.

for eslint plugins, there is not too much special eslintrc configs vs. flat configs. we just need to enhance the eslint-doc-generator configs.

],
}

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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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