From 237b2a1f486eda527a6cb386ff08ca781cb00adf Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Sat, 5 Nov 2022 22:23:49 -0400 Subject: [PATCH] docs: automate docs with eslint-doc-generator (#61) --- .eslintrc.js | 3 + README.md | 188 ++++++++--------- docs/rules/callback-return.md | 5 +- docs/rules/exports-style.md | 8 +- docs/rules/file-extension-in-import.md | 8 +- docs/rules/global-require.md | 5 +- docs/rules/handle-callback-err.md | 5 +- docs/rules/no-callback-literal.md | 15 +- docs/rules/no-deprecated-api.md | 191 +++++++++--------- docs/rules/no-exports-assign.md | 8 +- docs/rules/no-extraneous-import.md | 12 +- docs/rules/no-extraneous-require.md | 12 +- docs/rules/no-hide-core-modules.md | 8 +- docs/rules/no-missing-import.md | 8 +- docs/rules/no-missing-require.md | 8 +- docs/rules/no-mixed-requires.md | 5 +- docs/rules/no-new-require.md | 5 +- docs/rules/no-path-concat.md | 5 +- docs/rules/no-process-env.md | 5 +- docs/rules/no-process-exit.md | 7 +- docs/rules/no-restricted-import.md | 5 +- docs/rules/no-restricted-require.md | 5 +- docs/rules/no-sync.md | 5 +- docs/rules/no-unpublished-bin.md | 9 +- docs/rules/no-unpublished-import.md | 12 +- docs/rules/no-unpublished-require.md | 12 +- docs/rules/no-unsupported-features.md | 10 +- .../no-unsupported-features/es-builtins.md | 8 +- .../no-unsupported-features/es-syntax.md | 8 +- .../no-unsupported-features/node-builtins.md | 8 +- docs/rules/prefer-global/buffer.md | 5 +- docs/rules/prefer-global/console.md | 5 +- docs/rules/prefer-global/process.md | 5 +- docs/rules/prefer-global/text-decoder.md | 5 +- docs/rules/prefer-global/text-encoder.md | 5 +- docs/rules/prefer-global/url-search-params.md | 5 +- docs/rules/prefer-global/url.md | 5 +- docs/rules/prefer-promises/dns.md | 5 +- docs/rules/prefer-promises/fs.md | 5 +- docs/rules/process-exit-as-throw.md | 8 +- docs/rules/shebang.md | 11 +- lib/rules/no-callback-literal.js | 7 +- lib/rules/no-unsupported-features.js | 9 +- lib/rules/process-exit-as-throw.js | 2 +- lib/rules/shebang.js | 9 +- package.json | 9 +- scripts/update-docs-header-and-footer.js | 76 ------- scripts/update-readme.js | 78 ------- scripts/update-rule-docs.js | 41 ++++ scripts/update.js | 4 +- 50 files changed, 426 insertions(+), 466 deletions(-) delete mode 100644 scripts/update-docs-header-and-footer.js delete mode 100644 scripts/update-readme.js create mode 100644 scripts/update-rule-docs.js diff --git a/.eslintrc.js b/.eslintrc.js index f6726965..fdc5d9f4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -17,6 +17,9 @@ module.exports = { env: { mocha: true, }, + rules: { + "eslint-plugin/require-meta-docs-description": "error", + }, overrides: [ { // these messageIds were used outside diff --git a/README.md b/README.md index 260e3d7e..2d9d60d5 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,12 @@ Additional ESLint's rules for Node.js ## 💿 Install & Usage -``` -$ npm install --save-dev eslint eslint-plugin-n +```sh +npm install --save-dev eslint eslint-plugin-n ``` -- Requires Node.js `>=12.22.0` -- Requires ESLint `>=7.0.0` +- Requires Node.js `>=12.22.0` +- Requires ESLint `>=7.0.0` **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. @@ -55,119 +55,119 @@ $ npm install --save-dev eslint eslint-plugin-n ## 📖 Rules -- ⭐️ - the mark of recommended rules. -- ✒️ - the mark of fixable rules. - - -### Possible Errors + -| Rule ID | Description | | -|:--------|:------------|:--:| -| [n/handle-callback-err](./docs/rules/handle-callback-err.md) | require error handling in callbacks | | -| [n/no-callback-literal](./docs/rules/no-callback-literal.md) | ensure Node.js-style error-first callback pattern is followed | | -| [n/no-exports-assign](./docs/rules/no-exports-assign.md) | disallow the assignment to `exports` | ⭐️ | -| [n/no-extraneous-import](./docs/rules/no-extraneous-import.md) | disallow `import` declarations which import extraneous modules | ⭐️ | -| [n/no-extraneous-require](./docs/rules/no-extraneous-require.md) | disallow `require()` expressions which import extraneous modules | ⭐️ | -| [n/no-missing-import](./docs/rules/no-missing-import.md) | disallow `import` declarations which import non-existence modules | ⭐️ | -| [n/no-missing-require](./docs/rules/no-missing-require.md) | disallow `require()` expressions which import non-existence modules | ⭐️ | -| [n/no-new-require](./docs/rules/no-new-require.md) | disallow `new` operators with calls to `require` | | -| [n/no-path-concat](./docs/rules/no-path-concat.md) | disallow string concatenation with `__dirname` and `__filename` | | -| [n/no-process-exit](./docs/rules/no-process-exit.md) | disallow the use of `process.exit()` | | -| [n/no-unpublished-bin](./docs/rules/no-unpublished-bin.md) | disallow `bin` files that npm ignores | ⭐️ | -| [n/no-unpublished-import](./docs/rules/no-unpublished-import.md) | disallow `import` declarations which import private modules | ⭐️ | -| [n/no-unpublished-require](./docs/rules/no-unpublished-require.md) | disallow `require()` expressions which import private modules | ⭐️ | -| [n/no-unsupported-features/es-builtins](./docs/rules/no-unsupported-features/es-builtins.md) | disallow unsupported ECMAScript built-ins on the specified version | ⭐️ | -| [n/no-unsupported-features/es-syntax](./docs/rules/no-unsupported-features/es-syntax.md) | disallow unsupported ECMAScript syntax on the specified version | ⭐️ | -| [n/no-unsupported-features/node-builtins](./docs/rules/no-unsupported-features/node-builtins.md) | disallow unsupported Node.js built-in APIs on the specified version | ⭐️ | -| [n/process-exit-as-throw](./docs/rules/process-exit-as-throw.md) | make `process.exit()` expressions the same code path as `throw` | ⭐️ | -| [n/shebang](./docs/rules/shebang.md) | suggest correct usage of shebang | ⭐️✒️ | +💼 Configurations enabled in.\ +✅ Set in the `recommended` configuration.\ +☑️ Set in the `recommended-module` configuration.\ +✔️ Set in the `recommended-script` configuration.\ +🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\ +❌ Deprecated. ### Best Practices -| Rule ID | Description | | -|:--------|:------------|:--:| -| [n/no-deprecated-api](./docs/rules/no-deprecated-api.md) | disallow deprecated APIs | ⭐️ | +| Name | Description | 💼 | 🔧 | ❌ | +| :--------------------------------------------------- | :----------------------- | :------ | :- | :- | +| [no-deprecated-api](docs/rules/no-deprecated-api.md) | disallow deprecated APIs | ✅ ☑️ ✔️ | | | + +### Possible Errors + +| Name                                  | Description | 💼 | 🔧 | ❌ | +| :------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------- | :------ | :- | :- | +| [handle-callback-err](docs/rules/handle-callback-err.md) | require error handling in callbacks | | | | +| [no-callback-literal](docs/rules/no-callback-literal.md) | enforce Node.js-style error-first callback pattern is followed | | | | +| [no-exports-assign](docs/rules/no-exports-assign.md) | disallow the assignment to `exports` | ✅ ☑️ ✔️ | | | +| [no-extraneous-import](docs/rules/no-extraneous-import.md) | disallow `import` declarations which import extraneous modules | ✅ ☑️ ✔️ | | | +| [no-extraneous-require](docs/rules/no-extraneous-require.md) | disallow `require()` expressions which import extraneous modules | ✅ ☑️ ✔️ | | | +| [no-hide-core-modules](docs/rules/no-hide-core-modules.md) | disallow third-party modules which are hiding core modules | | | ❌ | +| [no-missing-import](docs/rules/no-missing-import.md) | disallow `import` declarations which import non-existence modules | ✅ ☑️ ✔️ | | | +| [no-missing-require](docs/rules/no-missing-require.md) | disallow `require()` expressions which import non-existence modules | ✅ ☑️ ✔️ | | | +| [no-new-require](docs/rules/no-new-require.md) | disallow `new` operators with calls to `require` | | | | +| [no-path-concat](docs/rules/no-path-concat.md) | disallow string concatenation with `__dirname` and `__filename` | | | | +| [no-process-exit](docs/rules/no-process-exit.md) | disallow the use of `process.exit()` | ✅ ☑️ ✔️ | | | +| [no-unpublished-bin](docs/rules/no-unpublished-bin.md) | disallow `bin` files that npm ignores | ✅ ☑️ ✔️ | | | +| [no-unpublished-import](docs/rules/no-unpublished-import.md) | disallow `import` declarations which import private modules | ✅ ☑️ ✔️ | | | +| [no-unpublished-require](docs/rules/no-unpublished-require.md) | disallow `require()` expressions which import private modules | ✅ ☑️ ✔️ | | | +| [no-unsupported-features](docs/rules/no-unsupported-features.md) | disallow unsupported ECMAScript features on the specified version | | | ❌ | +| [no-unsupported-features/es-builtins](docs/rules/no-unsupported-features/es-builtins.md) | disallow unsupported ECMAScript built-ins on the specified version | ✅ ☑️ ✔️ | | | +| [no-unsupported-features/es-syntax](docs/rules/no-unsupported-features/es-syntax.md) | disallow unsupported ECMAScript syntax on the specified version | ✅ ☑️ ✔️ | | | +| [no-unsupported-features/node-builtins](docs/rules/no-unsupported-features/node-builtins.md) | disallow unsupported Node.js built-in APIs on the specified version | ✅ ☑️ ✔️ | | | +| [process-exit-as-throw](docs/rules/process-exit-as-throw.md) | require that `process.exit()` expressions use the same code path as `throw` | ✅ ☑️ ✔️ | | | +| [shebang](docs/rules/shebang.md) | require correct usage of shebang | ✅ ☑️ ✔️ | 🔧 | | ### Stylistic Issues -| Rule ID | Description | | -|:--------|:------------|:--:| -| [n/callback-return](./docs/rules/callback-return.md) | require `return` statements after callbacks | | -| [n/exports-style](./docs/rules/exports-style.md) | enforce either `module.exports` or `exports` | ✒️ | -| [n/file-extension-in-import](./docs/rules/file-extension-in-import.md) | enforce the style of file extensions in `import` declarations | ✒️ | -| [n/global-require](./docs/rules/global-require.md) | require `require()` calls to be placed at top-level module scope | | -| [n/no-mixed-requires](./docs/rules/no-mixed-requires.md) | disallow `require` calls to be mixed with regular variable declarations | | -| [n/no-process-env](./docs/rules/no-process-env.md) | disallow the use of `process.env` | | -| [n/no-restricted-import](./docs/rules/no-restricted-import.md) | disallow specified modules when loaded by `import` declarations | | -| [n/no-restricted-require](./docs/rules/no-restricted-require.md) | disallow specified modules when loaded by `require` | | -| [n/no-sync](./docs/rules/no-sync.md) | disallow synchronous methods | | -| [n/prefer-global/buffer](./docs/rules/prefer-global/buffer.md) | enforce either `Buffer` or `require("buffer").Buffer` | | -| [n/prefer-global/console](./docs/rules/prefer-global/console.md) | enforce either `console` or `require("console")` | | -| [n/prefer-global/process](./docs/rules/prefer-global/process.md) | enforce either `process` or `require("process")` | | -| [n/prefer-global/text-decoder](./docs/rules/prefer-global/text-decoder.md) | enforce either `TextDecoder` or `require("util").TextDecoder` | | -| [n/prefer-global/text-encoder](./docs/rules/prefer-global/text-encoder.md) | enforce either `TextEncoder` or `require("util").TextEncoder` | | -| [n/prefer-global/url-search-params](./docs/rules/prefer-global/url-search-params.md) | enforce either `URLSearchParams` or `require("url").URLSearchParams` | | -| [n/prefer-global/url](./docs/rules/prefer-global/url.md) | enforce either `URL` or `require("url").URL` | | -| [n/prefer-promises/dns](./docs/rules/prefer-promises/dns.md) | enforce `require("dns").promises` | | -| [n/prefer-promises/fs](./docs/rules/prefer-promises/fs.md) | enforce `require("fs").promises` | | - -### Deprecated rules - -These rules have been deprecated in accordance with the [deprecation policy](https://eslint.org/docs/user-guide/rule-deprecation), and replaced by newer rules: - -| Rule ID | Replaced by | -|:--------|:------------| -| [n/no-hide-core-modules](./docs/rules/no-hide-core-modules.md) | (nothing) | -| [n/no-unsupported-features](./docs/rules/no-unsupported-features.md) | [n/no-unsupported-features/es-syntax](./docs/rules/no-unsupported-features/es-syntax.md) and [n/no-unsupported-features/es-builtins](./docs/rules/no-unsupported-features/es-builtins.md) | - - +| Name                            | Description | 💼 | 🔧 | ❌ | +| :------------------------------------------------------------------------------- | :---------------------------------------------------------------------- | :- | :- | :- | +| [callback-return](docs/rules/callback-return.md) | require `return` statements after callbacks | | | | +| [exports-style](docs/rules/exports-style.md) | enforce either `module.exports` or `exports` | | 🔧 | | +| [file-extension-in-import](docs/rules/file-extension-in-import.md) | enforce the style of file extensions in `import` declarations | | 🔧 | | +| [global-require](docs/rules/global-require.md) | require `require()` calls to be placed at top-level module scope | | | | +| [no-mixed-requires](docs/rules/no-mixed-requires.md) | disallow `require` calls to be mixed with regular variable declarations | | | | +| [no-process-env](docs/rules/no-process-env.md) | disallow the use of `process.env` | | | | +| [no-restricted-import](docs/rules/no-restricted-import.md) | disallow specified modules when loaded by `import` declarations | | | | +| [no-restricted-require](docs/rules/no-restricted-require.md) | disallow specified modules when loaded by `require` | | | | +| [no-sync](docs/rules/no-sync.md) | disallow synchronous methods | | | | +| [prefer-global/buffer](docs/rules/prefer-global/buffer.md) | enforce either `Buffer` or `require("buffer").Buffer` | | | | +| [prefer-global/console](docs/rules/prefer-global/console.md) | enforce either `console` or `require("console")` | | | | +| [prefer-global/process](docs/rules/prefer-global/process.md) | enforce either `process` or `require("process")` | | | | +| [prefer-global/text-decoder](docs/rules/prefer-global/text-decoder.md) | enforce either `TextDecoder` or `require("util").TextDecoder` | | | | +| [prefer-global/text-encoder](docs/rules/prefer-global/text-encoder.md) | enforce either `TextEncoder` or `require("util").TextEncoder` | | | | +| [prefer-global/url](docs/rules/prefer-global/url.md) | enforce either `URL` or `require("url").URL` | | | | +| [prefer-global/url-search-params](docs/rules/prefer-global/url-search-params.md) | enforce either `URLSearchParams` or `require("url").URLSearchParams` | | | | +| [prefer-promises/dns](docs/rules/prefer-promises/dns.md) | enforce `require("dns").promises` | | | | +| [prefer-promises/fs](docs/rules/prefer-promises/fs.md) | enforce `require("fs").promises` | | | | + + ## 🔧 Configs This plugin provides three configs: -- `plugin:n/recommended` considers both CommonJS and ES Modules. If [`"type":"module"` field](https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff#b023) existed in package.json then it considers files as ES Modules. Otherwise it considers files as CommonJS. In addition, it considers `*.mjs` files as ES Modules and `*.cjs` files as CommonJS. -- `plugin:n/recommended-module` considers all files as ES Modules. -- `plugin:n/recommended-script` considers all files as CommonJS. +- `plugin:n/recommended` considers both CommonJS and ES Modules. If [`"type":"module"` field](https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff#b023) existed in package.json then it considers files as ES Modules. Otherwise it considers files as CommonJS. In addition, it considers `*.mjs` files as ES Modules and `*.cjs` files as CommonJS. +- `plugin:n/recommended-module` considers all files as ES Modules. +- `plugin:n/recommended-script` considers all files as CommonJS. Those preset config: -- enable [no-process-exit](http://eslint.org/docs/rules/no-process-exit) rule because [the official document](https://nodejs.org/api/process.html#process_process_exit_code) does not recommend a use of `process.exit()`. -- enable plugin rules which are given :star: in the above table. -- add `{ecmaVersion: 2019}` and etc into `parserOptions`. -- add proper globals into `globals`. -- add this plugin into `plugins`. +- enable [no-process-exit](http://eslint.org/docs/rules/no-process-exit) rule because [the official document](https://nodejs.org/api/process.html#process_process_exit_code) does not recommend a use of `process.exit()`. +- enable plugin rules which are given ✅ in the above table. +- add `{ecmaVersion: 2019}` and etc into `parserOptions`. +- add proper globals into `globals`. +- add this plugin into `plugins`. ## 👫 FAQ -- 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: 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. ## 🚥 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). -- Patch release (intended to not break your lint build) - - A bug fix in a rule that results in it reporting fewer errors. - - Improvements to documentation. - - Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage. - - Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone). -- Minor release (might break your lint build) - - A bug fix in a rule that results in it reporting more errors. - - A new rule is created. - - A new option to an existing rule is created. - - An existing rule is deprecated. -- Major release (likely to break your lint build) - - A support for old Node version is dropped. - - A support for old ESLint version is dropped. - - An existing rule is changed in it reporting more errors. - - An existing rule is removed. - - An existing option of a rule is removed. - - An existing config is updated. +- Patch release (intended to not break your lint build) + - A bug fix in a rule that results in it reporting fewer errors. + - Improvements to documentation. + - Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage. + - Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone). +- Minor release (might break your lint build) + - A bug fix in a rule that results in it reporting more errors. + - A new rule is created. + - A new option to an existing rule is created. + - An existing rule is deprecated. +- Major release (likely to break your lint build) + - A support for old Node version is dropped. + - A support for old ESLint version is dropped. + - An existing rule is changed in it reporting more errors. + - An existing rule is removed. + - An existing option of a rule is removed. + - An existing config is updated. + +Deprecated rules follow ESLint's [deprecation policy](https://eslint.org/docs/user-guide/rule-deprecation). ## 📰 Changelog -- [GitHub Releases](https://github.com/weiran-zsd/eslint-plugin-node/releases) +- [GitHub Releases](https://github.com/weiran-zsd/eslint-plugin-node/releases) ## ❤️ Contributing @@ -177,6 +177,6 @@ Please use GitHub's Issues/PRs. ### Development Tools -- `npm test` runs tests and measures coverage. -- `npm run coverage` shows the coverage result of `npm test` command. -- `npm run clean` removes the coverage result of `npm test` command. +- `npm test` runs tests and measures coverage. +- `npm run coverage` shows the coverage result of `npm test` command. +- `npm run clean` removes the coverage result of `npm test` command. diff --git a/docs/rules/callback-return.md b/docs/rules/callback-return.md index c730a397..8f3ae6a1 100644 --- a/docs/rules/callback-return.md +++ b/docs/rules/callback-return.md @@ -1,5 +1,6 @@ -# n/callback-return -> require `return` statements after callbacks +# Require `return` statements after callbacks (`n/callback-return`) + + The callback pattern is at the heart of most I/O and event-driven programming in JavaScript. diff --git a/docs/rules/exports-style.md b/docs/rules/exports-style.md index d16e8ae0..cf164d1a 100644 --- a/docs/rules/exports-style.md +++ b/docs/rules/exports-style.md @@ -1,6 +1,8 @@ -# n/exports-style -> enforce either `module.exports` or `exports` -> - ✒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. +# Enforce either `module.exports` or `exports` (`n/exports-style`) + +🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + `module.exports` and `exports` are the same instance by default. But those come to be different if one of them is modified. diff --git a/docs/rules/file-extension-in-import.md b/docs/rules/file-extension-in-import.md index c0be47a2..6d76e420 100644 --- a/docs/rules/file-extension-in-import.md +++ b/docs/rules/file-extension-in-import.md @@ -1,6 +1,8 @@ -# n/file-extension-in-import -> enforce the style of file extensions in `import` declarations -> - ✒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. +# Enforce the style of file extensions in `import` declarations (`n/file-extension-in-import`) + +🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). + + We can omit file extensions in `import`/`export` declarations. diff --git a/docs/rules/global-require.md b/docs/rules/global-require.md index 22c55b05..ff969678 100644 --- a/docs/rules/global-require.md +++ b/docs/rules/global-require.md @@ -1,5 +1,6 @@ -# n/global-require -> require `require()` calls to be placed at top-level module scope +# Require `require()` calls to be placed at top-level module scope (`n/global-require`) + + In Node.js, module dependencies are included using the `require()` function, such as: diff --git a/docs/rules/handle-callback-err.md b/docs/rules/handle-callback-err.md index 086c8ac9..a646f6ac 100644 --- a/docs/rules/handle-callback-err.md +++ b/docs/rules/handle-callback-err.md @@ -1,5 +1,6 @@ -# n/handle-callback-err -> require error handling in callbacks +# Require error handling in callbacks (`n/handle-callback-err`) + + In Node.js, a common pattern for dealing with asynchronous behavior is called the callback pattern. This pattern expects an `Error` object or `null` as the first argument of the callback. diff --git a/docs/rules/no-callback-literal.md b/docs/rules/no-callback-literal.md index 8c130ef8..63654213 100644 --- a/docs/rules/no-callback-literal.md +++ b/docs/rules/no-callback-literal.md @@ -1,5 +1,6 @@ -# n/no-callback-literal -> ensure Node.js-style error-first callback pattern is followed +# Enforce Node.js-style error-first callback pattern is followed (`n/no-callback-literal`) + + When invoking a callback function which uses the Node.js error-first callback pattern, all of your errors should either use the `Error` class or a subclass of it. It is also acceptable to use `undefined` or `null` if there is no error. @@ -28,16 +29,6 @@ callback(new Error('some error')); callback(someVariable); ``` -### Options - -```json -{ - "rules": { - "n/no-callback-literal": "error" - } -} -``` - ## 🔎 Implementation - [Rule source](../../lib/rules/no-callback-literal.js) diff --git a/docs/rules/no-deprecated-api.md b/docs/rules/no-deprecated-api.md index fb19385f..f6b8b1aa 100644 --- a/docs/rules/no-deprecated-api.md +++ b/docs/rules/no-deprecated-api.md @@ -1,6 +1,8 @@ -# n/no-deprecated-api -> disallow deprecated APIs -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow deprecated APIs (`n/no-deprecated-api`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + Node has many deprecated API. The community is going to remove those API from Node in future, so we should not use those. @@ -28,110 +30,110 @@ This rule reports the following deprecated API. - [_linklist](https://nodejs.org/docs/v8.0.0/api/deprecations.html#deprecations_dep0002_require_linklist) - [_stream_wrap](https://nodejs.org/docs/v12.0.0/api/deprecations.html#deprecations_dep0125_require_stream_wrap) - async_hooks - - [currentId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0070_async_hooks_currentid) - - [triggerId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0071_async_hooks_triggerid) + - [currentId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0070_async_hooks_currentid) + - [triggerId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0071_async_hooks_triggerid) - buffer - - [Buffer constructors](https://nodejs.org/dist/v6.0.0/docs/api/buffer.html#buffer_class_buffer) (Use [safe-buffer](https://www.npmjs.com/package/safe-buffer) module for `Node@<4.5.0`) - - [SlowBuffer class](https://nodejs.org/dist/v6.0.0/docs/api/buffer.html#buffer_class_slowbuffer) + - [Buffer constructors](https://nodejs.org/dist/v6.0.0/docs/api/buffer.html#buffer_class_buffer) (Use [safe-buffer](https://www.npmjs.com/package/safe-buffer) module for `Node@<4.5.0`) + - [SlowBuffer class](https://nodejs.org/dist/v6.0.0/docs/api/buffer.html#buffer_class_slowbuffer) - constants (undocumented) - crypto - - [_toBuf](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0114_crypto_tobuf) - - `Credentials` (undocumented) - - [DEFAULT_ENCODING](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_default_encoding) - - [createCredentials](https://nodejs.org/dist/v0.12.0/docs/api/crypto.html#crypto_crypto_createcredentials_details) - - [createCipher](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_createcipher_algorithm_password_options) - - [createDecipher](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_createdecipher_algorithm_password_options) - - [fips](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_fips) - - [prng](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0115_crypto_prng_crypto_pseudorandombytes_crypto_rng) - - [pseudoRandomBytes](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0115_crypto_prng_crypto_pseudorandombytes_crypto_rng) - - [rng](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0115_crypto_prng_crypto_pseudorandombytes_crypto_rng) + - [_toBuf](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0114_crypto_tobuf) + - `Credentials` (undocumented) + - [DEFAULT_ENCODING](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_default_encoding) + - [createCredentials](https://nodejs.org/dist/v0.12.0/docs/api/crypto.html#crypto_crypto_createcredentials_details) + - [createCipher](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_createcipher_algorithm_password_options) + - [createDecipher](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_createdecipher_algorithm_password_options) + - [fips](https://nodejs.org/dist/v10.0.0/docs/api/crypto.html#crypto_crypto_fips) + - [prng](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0115_crypto_prng_crypto_pseudorandombytes_crypto_rng) + - [pseudoRandomBytes](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0115_crypto_prng_crypto_pseudorandombytes_crypto_rng) + - [rng](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0115_crypto_prng_crypto_pseudorandombytes_crypto_rng) - [domain](https://nodejs.org/dist/v4.0.0/docs/api/domain.html#domain_domain) - events - - [EventEmitter.listenerCount](https://nodejs.org/dist/v4.0.0/docs/api/events.html#events_class_method_eventemitter_listenercount_emitter_event) + - [EventEmitter.listenerCount](https://nodejs.org/dist/v4.0.0/docs/api/events.html#events_class_method_eventemitter_listenercount_emitter_event) - freelist (undocumented) - fs - - `SyncWriteStream` (undocumented) - - [exists](https://nodejs.org/dist/v4.0.0/docs/api/fs.html#fs_fs_exists_path_callback) - - [lchmod](https://nodejs.org/dist/v8.0.0/docs/api/fs.html#fs_fs_lchmod_path_mode_callback) - - [lchmodSync](https://nodejs.org/dist/v8.0.0/docs/api/fs.html#fs_fs_lchmodsync_path_mode) + - `SyncWriteStream` (undocumented) + - [exists](https://nodejs.org/dist/v4.0.0/docs/api/fs.html#fs_fs_exists_path_callback) + - [lchmod](https://nodejs.org/dist/v8.0.0/docs/api/fs.html#fs_fs_lchmod_path_mode_callback) + - [lchmodSync](https://nodejs.org/dist/v8.0.0/docs/api/fs.html#fs_fs_lchmodsync_path_mode) - globals - - [require.extensions](https://nodejs.org/dist/v0.12.0/docs/api/globals.html#globals_require_extensions) - - [GLOBAL](https://nodejs.org/api/deprecations.html#deprecations_dep0016_global_root) - - [root](https://nodejs.org/api/deprecations.html#deprecations_dep0016_global_root) - - [Intl.v8BreakIterator](https://nodejs.org/api/deprecations.html#deprecations_dep0017_intl_v8breakiterator) - - [COUNTER_NET_SERVER_CONNECTION](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) - - [COUNTER_NET_SERVER_CONNECTION_CLOSE](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) - - [COUNTER_HTTP_SERVER_REQUEST](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) - - [COUNTER_HTTP_SERVER_RESPONSE](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) - - [COUNTER_HTTP_CLIENT_REQUEST](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) - - [COUNTER_HTTP_CLIENT_RESPONSE](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [require.extensions](https://nodejs.org/dist/v0.12.0/docs/api/globals.html#globals_require_extensions) + - [GLOBAL](https://nodejs.org/api/deprecations.html#deprecations_dep0016_global_root) + - [root](https://nodejs.org/api/deprecations.html#deprecations_dep0016_global_root) + - [Intl.v8BreakIterator](https://nodejs.org/api/deprecations.html#deprecations_dep0017_intl_v8breakiterator) + - [COUNTER_NET_SERVER_CONNECTION](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [COUNTER_NET_SERVER_CONNECTION_CLOSE](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [COUNTER_HTTP_SERVER_REQUEST](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [COUNTER_HTTP_SERVER_RESPONSE](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [COUNTER_HTTP_CLIENT_REQUEST](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) + - [COUNTER_HTTP_CLIENT_RESPONSE](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0120_windows_performance_counter_support) - http - - [createClient](https://nodejs.org/dist/v0.10.0/docs/api/http.html#http_http_createclient_port_host) + - [createClient](https://nodejs.org/dist/v0.10.0/docs/api/http.html#http_http_createclient_port_host) - module - - [createRequireFromPath](https://nodejs.org/dist/v12.2.0/docs/api/deprecations.html#deprecations_dep0130_module_createrequirefrompath) - - `requireRepl` (undocumented) - - [_debug](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0077_module_debug) + - [createRequireFromPath](https://nodejs.org/dist/v12.2.0/docs/api/deprecations.html#deprecations_dep0130_module_createrequirefrompath) + - `requireRepl` (undocumented) + - [_debug](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0077_module_debug) - net - - [_setSimultaneousAccepts](https://nodejs.org/docs/v12.0.0/api/deprecations.html#deprecations_dep0121_net_setsimultaneousaccepts) + - [_setSimultaneousAccepts](https://nodejs.org/docs/v12.0.0/api/deprecations.html#deprecations_dep0121_net_setsimultaneousaccepts) - os - - `tmpDir` (undocumented) - - `getNetworkInterfaces` (undocumented) + - `tmpDir` (undocumented) + - `getNetworkInterfaces` (undocumented) - path - - [_makeLong](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0080_path_makelong) + - [_makeLong](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0080_path_makelong) - process - - `EventEmitter` (undocumented) - - `assert` (undocumented) - - [binding](https://nodejs.org/dist/v10.9.0/docs/api/deprecations.html#deprecations_dep0111_process_binding) + - `EventEmitter` (undocumented) + - `assert` (undocumented) + - [binding](https://nodejs.org/dist/v10.9.0/docs/api/deprecations.html#deprecations_dep0111_process_binding) - [punycode](https://nodejs.org/dist/v7.0.0/docs/api/punycode.html) - readline - - `codePointAt` (undocumented) - - `getStringWidth` (undocumented) - - `isFullWidthCodePoint` (undocumented) - - `stripVTControlCharacters` (undocumented) + - `codePointAt` (undocumented) + - `getStringWidth` (undocumented) + - `isFullWidthCodePoint` (undocumented) + - `stripVTControlCharacters` (undocumented) - repl - - [process.env.NODE_REPL_HISTORY_FILE](https://nodejs.org/dist/v4.0.0/docs/api/repl.html#repl_node_repl_history_file) + - [process.env.NODE_REPL_HISTORY_FILE](https://nodejs.org/dist/v4.0.0/docs/api/repl.html#repl_node_repl_history_file) - [sys](https://nodejs.org/api/deprecations.html#deprecations_dep0025_require_sys) - timers - - `enroll` (undocumented) - - `unenroll` (undocumented) + - `enroll` (undocumented) + - `unenroll` (undocumented) - tls - - [CleartextStream](https://nodejs.org/dist/v0.10.0/docs/api/tls.html#tls_class_tls_cleartextstream) + - [CleartextStream](https://nodejs.org/dist/v0.10.0/docs/api/tls.html#tls_class_tls_cleartextstream) (this class was removed on v0.11.3, but never deprecated in documents) - - [CryptoStream](https://nodejs.org/dist/v0.12.0/docs/api/tls.html#tls_class_cryptostream) - - [SecurePair](https://nodejs.org/dist/v6.0.0/docs/api/tls.html#tls_class_securepair) - - `convertNPNProtocols` (undocumented) - - [createSecurePair](https://nodejs.org/dist/v6.0.0/docs/api/tls.html#tls_tls_createsecurepair_context_isserver_requestcert_rejectunauthorized_options) - - [parseCertString](https://nodejs.org/dist/v8.6.0/docs/api/deprecations.html#deprecations_dep0076_tls_parsecertstring) + - [CryptoStream](https://nodejs.org/dist/v0.12.0/docs/api/tls.html#tls_class_cryptostream) + - [SecurePair](https://nodejs.org/dist/v6.0.0/docs/api/tls.html#tls_class_securepair) + - `convertNPNProtocols` (undocumented) + - [createSecurePair](https://nodejs.org/dist/v6.0.0/docs/api/tls.html#tls_tls_createsecurepair_context_isserver_requestcert_rejectunauthorized_options) + - [parseCertString](https://nodejs.org/dist/v8.6.0/docs/api/deprecations.html#deprecations_dep0076_tls_parsecertstring) - tty - - [setRawMode](https://nodejs.org/dist/v0.10.0/docs/api/tty.html#tty_tty_setrawmode_mode) + - [setRawMode](https://nodejs.org/dist/v0.10.0/docs/api/tty.html#tty_tty_setrawmode_mode) - url - - [parse](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0116_legacy_url_api) - - [resolve](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0116_legacy_url_api) + - [parse](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0116_legacy_url_api) + - [resolve](https://nodejs.org/dist/v11.0.0/docs/api/deprecations.html#deprecations_dep0116_legacy_url_api) - util - - [debug](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_debug_string) - - [error](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_error) - - [isArray](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isarray_object) - - [isBoolean](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isboolean_object) - - [isBuffer](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isbuffer_object) - - [isDate](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isdate_object) - - [isError](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_iserror_object) - - [isFunction](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isfunction_object) - - [isNull](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isnull_object) - - [isNullOrUndefined](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isnullorundefined_object) - - [isNumber](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isnumber_object) - - [isObject](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isobject_object) - - [isPrimitive](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isprimitive_object) - - [isRegExp](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isregexp_object) - - [isString](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isstring_object) - - [isSymbol](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_issymbol_object) - - [isUndefined](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isundefined_object) - - [log](https://nodejs.org/dist/v6.0.0/docs/api/util.html#util_util_log_string) - - [print](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_print) - - [pump](https://nodejs.org/dist/v0.10.0/docs/api/util.html#util_util_pump_readablestream_writablestream_callback) - - [puts](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_puts) - - [_extend](https://nodejs.org/dist/v6.0.0/docs/api/util.html#util_util_extend_obj) + - [debug](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_debug_string) + - [error](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_error) + - [isArray](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isarray_object) + - [isBoolean](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isboolean_object) + - [isBuffer](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isbuffer_object) + - [isDate](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isdate_object) + - [isError](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_iserror_object) + - [isFunction](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isfunction_object) + - [isNull](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isnull_object) + - [isNullOrUndefined](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isnullorundefined_object) + - [isNumber](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isnumber_object) + - [isObject](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isobject_object) + - [isPrimitive](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isprimitive_object) + - [isRegExp](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isregexp_object) + - [isString](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isstring_object) + - [isSymbol](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_issymbol_object) + - [isUndefined](https://nodejs.org/dist/v4.0.0/docs/api/util.html#util_util_isundefined_object) + - [log](https://nodejs.org/dist/v6.0.0/docs/api/util.html#util_util_log_string) + - [print](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_print) + - [pump](https://nodejs.org/dist/v0.10.0/docs/api/util.html#util_util_pump_readablestream_writablestream_callback) + - [puts](https://nodejs.org/dist/v0.12.0/docs/api/util.html#util_util_puts) + - [_extend](https://nodejs.org/dist/v6.0.0/docs/api/util.html#util_util_extend_obj) - vm - - [runInDebugContext](https://nodejs.org/dist/v8.0.0/docs/api/vm.html#vm_vm_runindebugcontext_code) + - [runInDebugContext](https://nodejs.org/dist/v8.0.0/docs/api/vm.html#vm_vm_runindebugcontext_code) > ⚠️ Note that userland modules don't hide core modules. > For example, `require("punycode")` still imports the deprecated core module even if you executed `npm install punycode`. @@ -158,7 +160,7 @@ If you omit the [engines] field, this rule chooses `>=8.0.0` as the configured N ### Options -This rule has 3 options. +This rule has 4 options. ```json { @@ -167,6 +169,7 @@ This rule has 3 options. "version": ">=8.0.0", "ignoreModuleItems": [], "ignoreGlobalItems": [] + "ignoreIndirectDependencies": true }] } } @@ -316,28 +319,28 @@ This rule cannot report the following cases: ### non-static properties - async_hooks - - [asyncResource.triggerId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0072_async_hooks_asyncresource_triggerid) + - [asyncResource.triggerId](https://nodejs.org/dist/v8.2.0/docs/api/deprecations.html#deprecations_dep0072_async_hooks_asyncresource_triggerid) - buffer - - [buf.parent](https://nodejs.org/dist/v8.0.0/docs/api/buffer.html#buffer_buf_parent) + - [buf.parent](https://nodejs.org/dist/v8.0.0/docs/api/buffer.html#buffer_buf_parent) - cluster - - [worker.suicide](https://nodejs.org/dist/v6.0.0/docs/api/cluster.html#cluster_worker_suicide) + - [worker.suicide](https://nodejs.org/dist/v6.0.0/docs/api/cluster.html#cluster_worker_suicide) - crypto - - [ecdh.setPublicKey](https://nodejs.org/dist/v6.0.0/docs/api/crypto.html#crypto_ecdh_setpublickey_public_key_encoding) + - [ecdh.setPublicKey](https://nodejs.org/dist/v6.0.0/docs/api/crypto.html#crypto_ecdh_setpublickey_public_key_encoding) - http - - [res.writeHeader()](https://nodejs.org/dist/v8.0.0/docs/api/deprecations.html#deprecations_dep0063_serverresponse_prototype_writeheader) + - [res.writeHeader()](https://nodejs.org/dist/v8.0.0/docs/api/deprecations.html#deprecations_dep0063_serverresponse_prototype_writeheader) - net - - [server.connections](https://nodejs.org/dist/v0.10.0/docs/api/net.html#net_server_connections) + - [server.connections](https://nodejs.org/dist/v0.10.0/docs/api/net.html#net_server_connections) - repl - - `replServer.convertToContext` (undocumented) - - [replServer.turnOffEditorMode](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0078_replserver_turnoffeditormode) - - [replServer.memory](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0082_replserver_prototype_memory) + - `replServer.convertToContext` (undocumented) + - [replServer.turnOffEditorMode](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0078_replserver_turnoffeditormode) + - [replServer.memory](https://nodejs.org/dist/v9.0.0/docs/api/deprecations.html#deprecations_dep0082_replserver_prototype_memory) ### types of arguments - fs - - `fs.truncate()` and `fs.truncateSync()` usage with a file descriptor has been deprecated. + - `fs.truncate()` and `fs.truncateSync()` usage with a file descriptor has been deprecated. - url - - `url.format()` with legacy `urlObject` has been deprecated. + - `url.format()` with legacy `urlObject` has been deprecated. ### dynamic things diff --git a/docs/rules/no-exports-assign.md b/docs/rules/no-exports-assign.md index d024f813..0bb10bb1 100644 --- a/docs/rules/no-exports-assign.md +++ b/docs/rules/no-exports-assign.md @@ -1,6 +1,8 @@ -# n/no-exports-assign -> disallow the assignment to `exports` -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow the assignment to `exports` (`n/no-exports-assign`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + To assign to `exports` variable would not work as expected. diff --git a/docs/rules/no-extraneous-import.md b/docs/rules/no-extraneous-import.md index 2c052752..875fad25 100644 --- a/docs/rules/no-extraneous-import.md +++ b/docs/rules/no-extraneous-import.md @@ -1,6 +1,8 @@ -# n/no-extraneous-import -> disallow `import` declarations which import extraneous modules -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow `import` declarations which import extraneous modules (`n/no-extraneous-import`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + If an `import` declaration's source is extraneous (it's not written in `package.json`), the program works in local, but will not work after dependencies are re-installed. It will cause troubles to your team/contributors. This rule disallows `import` declarations of extraneous modules. @@ -47,6 +49,10 @@ If a path is relative, it will be resolved from CWD. Default is `[]` +#### convertPath + +TODO + ### Shared Settings The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). diff --git a/docs/rules/no-extraneous-require.md b/docs/rules/no-extraneous-require.md index e891264a..d63212d1 100644 --- a/docs/rules/no-extraneous-require.md +++ b/docs/rules/no-extraneous-require.md @@ -1,6 +1,8 @@ -# n/no-extraneous-require -> disallow `require()` expressions which import extraneous modules -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow `require()` expressions which import extraneous modules (`n/no-extraneous-require`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + If a `require()`'s target is extraneous (it's not written in `package.json`), the program works in local, but will not work after dependencies are re-installed. It will cause troubles to your team/contributors. This rule disallows `require()` of extraneous modules. @@ -55,6 +57,10 @@ When an import path does not exist, this rule checks whether or not any of `path Default is `[".js", ".json", ".node"]`. +#### convertPath + +TODO + ### Shared Settings The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). diff --git a/docs/rules/no-hide-core-modules.md b/docs/rules/no-hide-core-modules.md index c5fa509c..a00f6c1a 100644 --- a/docs/rules/no-hide-core-modules.md +++ b/docs/rules/no-hide-core-modules.md @@ -1,6 +1,8 @@ -# n/no-hide-core-modules -> disallow third-party modules which are hiding core modules -> - ⛔ This rule has been deprecated. +# Disallow third-party modules which are hiding core modules (`n/no-hide-core-modules`) + +❌ This rule is deprecated. + + **:warning: This is deprecated since v4.2.0.** This rule was based on an invalid assumption. See also [#69](https://github.com/mysticatea/eslint-plugin-node/issues/69). diff --git a/docs/rules/no-missing-import.md b/docs/rules/no-missing-import.md index 4d568193..b84d7463 100644 --- a/docs/rules/no-missing-import.md +++ b/docs/rules/no-missing-import.md @@ -1,6 +1,8 @@ -# n/no-missing-import -> disallow `import` declarations which import non-existence modules -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow `import` declarations which import non-existence modules (`n/no-missing-import`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + This is similar to [no-missing-require](no-missing-require.md), but this rule handles `import` and `export` declarations. diff --git a/docs/rules/no-missing-require.md b/docs/rules/no-missing-require.md index 1c7651c6..9b87d5c3 100644 --- a/docs/rules/no-missing-require.md +++ b/docs/rules/no-missing-require.md @@ -1,6 +1,8 @@ -# n/no-missing-require -> disallow `require()` expressions which import non-existence modules -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow `require()` expressions which import non-existence modules (`n/no-missing-require`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + Maybe we cannot find typo of import paths until run it, so this rule checks import paths. diff --git a/docs/rules/no-mixed-requires.md b/docs/rules/no-mixed-requires.md index d2a93b64..e36b35c9 100644 --- a/docs/rules/no-mixed-requires.md +++ b/docs/rules/no-mixed-requires.md @@ -1,5 +1,6 @@ -# n/no-mixed-requires -> disallow `require` calls to be mixed with regular variable declarations +# Disallow `require` calls to be mixed with regular variable declarations (`n/no-mixed-requires`) + + In the Node.js community it is often customary to separate initializations with calls to `require` modules from other variable declarations, sometimes also grouping them by the type of module. This rule helps you enforce this convention. diff --git a/docs/rules/no-new-require.md b/docs/rules/no-new-require.md index 1d86b4f4..734c0eda 100644 --- a/docs/rules/no-new-require.md +++ b/docs/rules/no-new-require.md @@ -1,5 +1,6 @@ -# n/no-new-require -> disallow `new` operators with calls to `require` +# Disallow `new` operators with calls to `require` (`n/no-new-require`) + + The `require` function is used to include modules that exist in separate files, such as: diff --git a/docs/rules/no-path-concat.md b/docs/rules/no-path-concat.md index ca281cc4..7baa9a2d 100644 --- a/docs/rules/no-path-concat.md +++ b/docs/rules/no-path-concat.md @@ -1,5 +1,6 @@ -# n/no-path-concat -> disallow string concatenation with `__dirname` and `__filename` +# Disallow string concatenation with `__dirname` and `__filename` (`n/no-path-concat`) + + In Node.js, the `__dirname` and `__filename` global variables contain the directory path and the file path of the currently executing script file, respectively. Sometimes, developers try to use these variables to create paths to other files, such as: diff --git a/docs/rules/no-process-env.md b/docs/rules/no-process-env.md index 3e80c82b..bd3c84dc 100644 --- a/docs/rules/no-process-env.md +++ b/docs/rules/no-process-env.md @@ -1,5 +1,6 @@ -# n/no-process-env -> disallow the use of `process.env` +# Disallow the use of `process.env` (`n/no-process-env`) + + The `process.env` object in Node.js is used to store deployment/configuration parameters. Littering it through out a project could lead to maintenance issues as it's another kind of global dependency. As such, it could lead to merge conflicts in a multi-user setup and deployment issues in a multi-server setup. Instead, one of the best practices is to define all those parameters in a single configuration/settings file which could be accessed throughout the project. diff --git a/docs/rules/no-process-exit.md b/docs/rules/no-process-exit.md index 54285ba1..07ad8c4b 100644 --- a/docs/rules/no-process-exit.md +++ b/docs/rules/no-process-exit.md @@ -1,5 +1,8 @@ -# n/no-process-exit -> disallow the use of `process.exit()` +# Disallow the use of `process.exit()` (`n/no-process-exit`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + The `process.exit()` method in Node.js is used to immediately stop the Node.js process and exit. This is a dangerous operation because it can occur in any method at any point in time, potentially stopping a Node.js application completely when an error occurs. For example: diff --git a/docs/rules/no-restricted-import.md b/docs/rules/no-restricted-import.md index 51b6fdc7..82da6e24 100644 --- a/docs/rules/no-restricted-import.md +++ b/docs/rules/no-restricted-import.md @@ -1,5 +1,6 @@ -# n/no-restricted-import -> disallow specified modules when loaded by `import` declarations +# Disallow specified modules when loaded by `import` declarations (`n/no-restricted-import`) + + ## 📖 Rule Details diff --git a/docs/rules/no-restricted-require.md b/docs/rules/no-restricted-require.md index ca2d0704..9b1723b4 100644 --- a/docs/rules/no-restricted-require.md +++ b/docs/rules/no-restricted-require.md @@ -1,5 +1,6 @@ -# n/no-restricted-require -> disallow specified modules when loaded by `require` +# Disallow specified modules when loaded by `require` (`n/no-restricted-require`) + + A module in Node.js is a simple or complex functionality organized in a JavaScript file which can be reused throughout the Node.js application. The keyword `require` is used in Node.js/CommonJS to import modules into an application. This way you can have dynamic loading where the loaded module name isn't predefined /static, or where you conditionally load a module only if it's "truly required". diff --git a/docs/rules/no-sync.md b/docs/rules/no-sync.md index 57fc3713..30789ca7 100644 --- a/docs/rules/no-sync.md +++ b/docs/rules/no-sync.md @@ -1,5 +1,6 @@ -# n/no-sync -> disallow synchronous methods +# Disallow synchronous methods (`n/no-sync`) + + In Node.js, most I/O is done through asynchronous methods. However, there are often synchronous versions of the asynchronous methods. For example, `fs.exists()` and `fs.existsSync()`. In some contexts, using synchronous operations is okay (if, as with ESLint, you are writing a command line utility). However, in other contexts the use of synchronous operations is considered a bad practice that should be avoided. For example, if you are running a high-travel web server on Node.js, you should consider carefully if you want to allow any synchronous operations that could lock up the server. diff --git a/docs/rules/no-unpublished-bin.md b/docs/rules/no-unpublished-bin.md index efd1b5a9..2f413103 100644 --- a/docs/rules/no-unpublished-bin.md +++ b/docs/rules/no-unpublished-bin.md @@ -1,6 +1,8 @@ -# n/no-unpublished-bin -> disallow `bin` files that npm ignores -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow `bin` files that npm ignores (`n/no-unpublished-bin`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + We can publish CLI commands by `npm`. It uses `bin` field of `package.json`. @@ -85,7 +87,6 @@ For example: In this style, this option has the following shape as the same expression as above: `{include: [], replace: [, ]}`. In addition, we can specify glob patterns to exclude files. - ### Shared Settings The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). diff --git a/docs/rules/no-unpublished-import.md b/docs/rules/no-unpublished-import.md index 23bb1fe1..a33419b0 100644 --- a/docs/rules/no-unpublished-import.md +++ b/docs/rules/no-unpublished-import.md @@ -1,6 +1,8 @@ -# n/no-unpublished-import -> disallow `import` declarations which import private modules -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow `import` declarations which import private modules (`n/no-unpublished-import`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + This is similar to [no-unpublished-require](no-unpublished-require.md), but this rule handles `import` declarations. @@ -102,6 +104,10 @@ For example: In this style, this option has the following shape as the same expression as above: `{include: [], replace: [, ]}`. In addition, we can specify glob patterns to exclude files. +#### resolvePaths + +TODO + ### Shared Settings The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). diff --git a/docs/rules/no-unpublished-require.md b/docs/rules/no-unpublished-require.md index aa48e1b8..bfe1bf61 100644 --- a/docs/rules/no-unpublished-require.md +++ b/docs/rules/no-unpublished-require.md @@ -1,6 +1,8 @@ -# n/no-unpublished-require -> disallow `require()` expressions which import private modules -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow `require()` expressions which import private modules (`n/no-unpublished-require`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + If a `require()` expression's target is not published, the program works in local, but will not work after published to npm. This rule disallows `require()` expressions of unpublished files/modules. @@ -110,6 +112,10 @@ When an import path does not exist, this rule checks whether or not any of `path Default is `[".js", ".json", ".node"]`. +#### resolvePaths + +TODO + ### Shared Settings The following options can be set by [shared settings](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings). diff --git a/docs/rules/no-unsupported-features.md b/docs/rules/no-unsupported-features.md index e5d8a13f..bc83232c 100644 --- a/docs/rules/no-unsupported-features.md +++ b/docs/rules/no-unsupported-features.md @@ -1,8 +1,8 @@ -# n/no-unsupported-features -> disallow unsupported ECMAScript features on the specified version -> - ⛔ This rule has been deprecated. Use [n/no-unsupported-features/es-syntax](./no-unsupported-features/es-syntax.md) and [n/no-unsupported-features/es-builtins](./no-unsupported-features/es-builtins.md) instead. +# Disallow unsupported ECMAScript features on the specified version (`n/no-unsupported-features`) -**:warning: This is deprecated since v7.0.0.** Use [n/no-unsupported-features/es-syntax](./no-unsupported-features/es-syntax.md) and [n/no-unsupported-features/es-builtins](./no-unsupported-features/es-builtins.md) instead. +❌ This rule is deprecated. It was replaced by [`n/no-unsupported-features/es-syntax`](n/no-unsupported-features/es-syntax.md), [`n/no-unsupported-features/es-builtins`](n/no-unsupported-features/es-builtins.md). + + Node.js doesn't support all ECMAScript standard features. This rule reports when you used unsupported ECMAScript 2015-2018 features on the specified Node.js version. @@ -298,7 +298,7 @@ E.g., a use of instance methods. ## 📚 Further Reading -- http://node.green/ +- [engines]: https://docs.npmjs.com/files/package.json#engines diff --git a/docs/rules/no-unsupported-features/es-builtins.md b/docs/rules/no-unsupported-features/es-builtins.md index 7d2c3cff..b6699512 100644 --- a/docs/rules/no-unsupported-features/es-builtins.md +++ b/docs/rules/no-unsupported-features/es-builtins.md @@ -1,6 +1,8 @@ -# n/no-unsupported-features/es-builtins -> disallow unsupported ECMAScript built-ins on the specified version -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow unsupported ECMAScript built-ins on the specified version (`n/no-unsupported-features/es-builtins`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + ECMAScript standard is updating every two months. You can check [node.green](https://node.green/) to know which Node.js version supports each ECMAScript feature. diff --git a/docs/rules/no-unsupported-features/es-syntax.md b/docs/rules/no-unsupported-features/es-syntax.md index c85ae094..24f6b75d 100644 --- a/docs/rules/no-unsupported-features/es-syntax.md +++ b/docs/rules/no-unsupported-features/es-syntax.md @@ -1,6 +1,8 @@ -# n/no-unsupported-features/es-syntax -> disallow unsupported ECMAScript syntax on the specified version -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow unsupported ECMAScript syntax on the specified version (`n/no-unsupported-features/es-syntax`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + ECMAScript standard is updating every two months. You can check [node.green](https://node.green/) to know which Node.js version supports each ECMAScript feature. diff --git a/docs/rules/no-unsupported-features/node-builtins.md b/docs/rules/no-unsupported-features/node-builtins.md index 6e071e6a..0b4e6b91 100644 --- a/docs/rules/no-unsupported-features/node-builtins.md +++ b/docs/rules/no-unsupported-features/node-builtins.md @@ -1,6 +1,8 @@ -# n/no-unsupported-features/node-builtins -> disallow unsupported Node.js built-in APIs on the specified version -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Disallow unsupported Node.js built-in APIs on the specified version (`n/no-unsupported-features/node-builtins`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + Node.js community is improving built-in APIs continuously. You can check [Node.js Documentation](https://nodejs.org/api/) to know which Node.js version supports each Node.js API. diff --git a/docs/rules/prefer-global/buffer.md b/docs/rules/prefer-global/buffer.md index 2731b1eb..b4c91584 100644 --- a/docs/rules/prefer-global/buffer.md +++ b/docs/rules/prefer-global/buffer.md @@ -1,5 +1,6 @@ -# n/prefer-global/buffer -> enforce either `Buffer` or `require("buffer").Buffer` +# Enforce either `Buffer` or `require("buffer").Buffer` (`n/prefer-global/buffer`) + + The `Buffer` class of `buffer` module is defined as a global variable. diff --git a/docs/rules/prefer-global/console.md b/docs/rules/prefer-global/console.md index f69f7179..e4779fdc 100644 --- a/docs/rules/prefer-global/console.md +++ b/docs/rules/prefer-global/console.md @@ -1,5 +1,6 @@ -# n/prefer-global/console -> enforce either `console` or `require("console")` +# Enforce either `console` or `require("console")` (`n/prefer-global/console`) + + The `console` module is defined as a global variable. diff --git a/docs/rules/prefer-global/process.md b/docs/rules/prefer-global/process.md index 77e10c84..8a46dd1d 100644 --- a/docs/rules/prefer-global/process.md +++ b/docs/rules/prefer-global/process.md @@ -1,5 +1,6 @@ -# n/prefer-global/process -> enforce either `process` or `require("process")` +# Enforce either `process` or `require("process")` (`n/prefer-global/process`) + + The `process` module is defined as a global variable. diff --git a/docs/rules/prefer-global/text-decoder.md b/docs/rules/prefer-global/text-decoder.md index 9a952bc0..40cc8728 100644 --- a/docs/rules/prefer-global/text-decoder.md +++ b/docs/rules/prefer-global/text-decoder.md @@ -1,5 +1,6 @@ -# n/prefer-global/text-decoder -> enforce either `TextDecoder` or `require("util").TextDecoder` +# Enforce either `TextDecoder` or `require("util").TextDecoder` (`n/prefer-global/text-decoder`) + + The `TextDecoder` class of `util` module is defined as a global variable. diff --git a/docs/rules/prefer-global/text-encoder.md b/docs/rules/prefer-global/text-encoder.md index 1ba7ae81..5432f56c 100644 --- a/docs/rules/prefer-global/text-encoder.md +++ b/docs/rules/prefer-global/text-encoder.md @@ -1,5 +1,6 @@ -# n/prefer-global/text-encoder -> enforce either `TextEncoder` or `require("util").TextEncoder` +# Enforce either `TextEncoder` or `require("util").TextEncoder` (`n/prefer-global/text-encoder`) + + The `TextEncoder` class of `util` module is defined as a global variable. diff --git a/docs/rules/prefer-global/url-search-params.md b/docs/rules/prefer-global/url-search-params.md index 232533cb..b0758c52 100644 --- a/docs/rules/prefer-global/url-search-params.md +++ b/docs/rules/prefer-global/url-search-params.md @@ -1,5 +1,6 @@ -# n/prefer-global/url-search-params -> enforce either `URLSearchParams` or `require("url").URLSearchParams` +# Enforce either `URLSearchParams` or `require("url").URLSearchParams` (`n/prefer-global/url-search-params`) + + The `URLSearchParams` class of `url` module is defined as a global variable. diff --git a/docs/rules/prefer-global/url.md b/docs/rules/prefer-global/url.md index 5e44f955..33ff2a51 100644 --- a/docs/rules/prefer-global/url.md +++ b/docs/rules/prefer-global/url.md @@ -1,5 +1,6 @@ -# n/prefer-global/url -> enforce either `URL` or `require("url").URL` +# Enforce either `URL` or `require("url").URL` (`n/prefer-global/url`) + + The `URL` class of `url` module is defined as a global variable. diff --git a/docs/rules/prefer-promises/dns.md b/docs/rules/prefer-promises/dns.md index 1170cb44..501bae78 100644 --- a/docs/rules/prefer-promises/dns.md +++ b/docs/rules/prefer-promises/dns.md @@ -1,5 +1,6 @@ -# n/prefer-promises/dns -> enforce `require("dns").promises` +# Enforce `require("dns").promises` (`n/prefer-promises/dns`) + + Since Node.js v11.14.0, `require("dns").promises` API has been stable. Promise API and `async`/`await` syntax will make code more readable than callback API. diff --git a/docs/rules/prefer-promises/fs.md b/docs/rules/prefer-promises/fs.md index d35a5680..ed7f420c 100644 --- a/docs/rules/prefer-promises/fs.md +++ b/docs/rules/prefer-promises/fs.md @@ -1,5 +1,6 @@ -# n/prefer-promises/fs -> enforce `require("fs").promises` +# Enforce `require("fs").promises` (`n/prefer-promises/fs`) + + Since Node.js v11.14.0, `require("fs").promises` API has been stable. Promise API and `async`/`await` syntax will make code more readable than callback API. diff --git a/docs/rules/process-exit-as-throw.md b/docs/rules/process-exit-as-throw.md index e3c03f6c..ed0b7681 100644 --- a/docs/rules/process-exit-as-throw.md +++ b/docs/rules/process-exit-as-throw.md @@ -1,6 +1,8 @@ -# n/process-exit-as-throw -> make `process.exit()` expressions the same code path as `throw` -> - ⭐️ This rule is included in `plugin:n/recommended` preset. +# Require that `process.exit()` expressions use the same code path as `throw` (`n/process-exit-as-throw`) + +💼 This rule is enabled in the following configs: ✅ `recommended`, ☑️ `recommended-module`, ✔️ `recommended-script`. + + ## 📖 Rule Details diff --git a/docs/rules/shebang.md b/docs/rules/shebang.md index 5ff0abaf..32d2acf9 100644 --- a/docs/rules/shebang.md +++ b/docs/rules/shebang.md @@ -1,7 +1,10 @@ -# n/shebang -> suggest correct usage of shebang -> - ⭐️ This rule is included in `plugin:n/recommended` preset. -> - ✒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. +# Require correct usage of shebang (`n/shebang`) + +💼 This rule is enabled in the following configs: ✅ `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). + + When we make a CLI tool with Node.js, we add `bin` field to `package.json`, then we add a shebang the entry file. This rule suggests correct usage of shebang. diff --git a/lib/rules/no-callback-literal.js b/lib/rules/no-callback-literal.js index a15c8aa1..c80aaf41 100644 --- a/lib/rules/no-callback-literal.js +++ b/lib/rules/no-callback-literal.js @@ -8,7 +8,7 @@ module.exports = { meta: { docs: { description: - "ensure Node.js-style error-first callback pattern is followed", + "enforce Node.js-style error-first callback pattern is followed", category: "Possible Errors", recommended: false, url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-callback-literal.md", @@ -17,8 +17,9 @@ module.exports = { fixable: null, schema: [], messages: { - unexpectedLiteral: "Unexpected literal in error position of callback." - } + unexpectedLiteral: + "Unexpected literal in error position of callback.", + }, }, create(context) { diff --git a/lib/rules/no-unsupported-features.js b/lib/rules/no-unsupported-features.js index 67499839..b3de1f17 100644 --- a/lib/rules/no-unsupported-features.js +++ b/lib/rules/no-unsupported-features.js @@ -1047,14 +1047,15 @@ module.exports = { "disallow unsupported ECMAScript features on the specified version", category: "Possible Errors", recommended: false, - replacedBy: [ - "n/no-unsupported-features/es-syntax", - "n/no-unsupported-features/es-builtins", - ], + url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unsupported-features.md", }, type: "problem", deprecated: true, + replacedBy: [ + "n/no-unsupported-features/es-syntax", + "n/no-unsupported-features/es-builtins", + ], fixable: null, schema: [ { diff --git a/lib/rules/process-exit-as-throw.js b/lib/rules/process-exit-as-throw.js index c7cc526a..3936b853 100644 --- a/lib/rules/process-exit-as-throw.js +++ b/lib/rules/process-exit-as-throw.js @@ -148,7 +148,7 @@ module.exports = { meta: { docs: { description: - "make `process.exit()` expressions the same code path as `throw`", + "require that `process.exit()` expressions use the same code path as `throw`", category: "Possible Errors", recommended: true, url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/process-exit-as-throw.md", diff --git a/lib/rules/shebang.js b/lib/rules/shebang.js index 56ba7020..7bdddb4a 100644 --- a/lib/rules/shebang.js +++ b/lib/rules/shebang.js @@ -69,7 +69,7 @@ function getShebangInfo(sourceCode) { module.exports = { meta: { docs: { - description: "suggest correct usage of shebang", + description: "require correct usage of shebang", category: "Possible Errors", recommended: true, url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/shebang.md", @@ -89,9 +89,10 @@ module.exports = { messages: { unexpectedBOM: "This file must not have Unicode BOM.", expectedLF: "This file must have Unix linebreaks (LF).", - expectedHashbangNode: 'This file needs shebang "#!/usr/bin/env node".', - expectedHashbang: "This file needs no shebang." - } + expectedHashbangNode: + 'This file needs shebang "#!/usr/bin/env node".', + expectedHashbang: "This file needs no shebang.", + }, }, create(context) { const sourceCode = context.getSourceCode() diff --git a/package.json b/package.json index 02e0f94f..720665c8 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "esbuild": "^0.14.39", "eslint": "^8.21.0", "eslint-config-prettier": "^8.5.0", + "eslint-doc-generator": "^0.19.0", "eslint-plugin-eslint-plugin": "^5.0.2", "eslint-plugin-n": "file:.", "fast-glob": "^3.2.11", @@ -35,6 +36,7 @@ "import-meta-resolve": "^1.1.1", "lint-staged": "^12.4.1", "mocha": "^10.0.0", + "npm-run-all": "^4.1.5", "nyc": "^15.1.0", "opener": "^1.5.1", "prettier": "^2.7.1", @@ -47,7 +49,9 @@ "clean": "rimraf .nyc_output coverage", "codecov": "nyc report --reporter text-lcov | codecov --pipe --disable=gcov -t $CODECOV_TOKEN", "coverage": "opener ./coverage/lcov-report/index.html", - "lint": "eslint lib scripts tests/lib .eslintrc.js", + "lint": "npm-run-all \"lint:*\"", + "lint:eslint-docs": "npm run update:eslint-docs -- --check", + "lint:js": "eslint lib scripts tests/lib .eslintrc.js", "new": "node scripts/new-rule", "pretest": "npm run -s lint", "test": "nyc npm run -s test:_mocha", @@ -58,7 +62,8 @@ "postversion": "git push && git push --tags", "watch": "npm run test:_mocha -- --watch --growl", "format": "prettier --loglevel warn --write \"**/*.{js,css,md}\"", - "prepare": "husky install" + "prepare": "husky install", + "update:eslint-docs": "eslint-doc-generator --config-emoji recommended-module,☑️ --config-emoji recommended-script,✔️ --split-by meta.docs.category" }, "repository": { "type": "git", diff --git a/scripts/update-docs-header-and-footer.js b/scripts/update-docs-header-and-footer.js deleted file mode 100644 index 698ecf98..00000000 --- a/scripts/update-docs-header-and-footer.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @author Toru Nagashima - * See LICENSE file in root directory for full license. - */ -"use strict" - -const fs = require("fs") -const path = require("path") -const { rules } = require("./rules") -const headerPattern = /^#.+\n(?:>.+\n)*\n+/u -const footerPattern = /\n+## 🔎 Implementation[\s\S]*$/u -const ruleRoot = path.resolve(__dirname, "../lib/rules") -const testRoot = path.resolve(__dirname, "../tests/lib/rules") -const docsRoot = path.resolve(__dirname, "../docs/rules") -const listFormatter = new Intl.ListFormat("en", { type: "conjunction" }) - -/** @typedef {import("./rules").RuleInfo} RuleInfo */ - -/** - * Render the document header of a given rule. - * @param {RuleInfo} rule The rule information. - * @returns {string} The document header. - */ -function renderHeader(rule) { - const lines = [`# ${rule.id}`, `> ${rule.description}`] - - if (rule.recommended) { - lines.push( - "> - ⭐️ This rule is included in `plugin:n/recommended` preset." - ) - } - if (rule.fixable) { - lines.push( - "> - ✒️ The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule." - ) - } - if (rule.deprecated) { - const replace = rule.replacedBy.map( - ruleId => `[${ruleId}](./${ruleId.replace(/^n\//, "")}.md)` - ) - const replaceText = - replace.length === 0 - ? "" - : ` Use ${listFormatter.format(replace)} instead.` - lines.push(`> - ⛔ This rule has been deprecated.${replaceText}`) - } - lines.push("", "") - - return lines.join("\n") -} - -/** - * Render the document header of a given rule. - * @param {RuleInfo} rule The rule information. - * @returns {string} The document header. - */ -function renderFooter(rule) { - const docsPath = path.dirname(path.resolve(docsRoot, `${rule.name}.md`)) - const rulePath = path - .relative(docsPath, path.join(ruleRoot, `${rule.name}.js`)) - .replace(/\\/gu, "/") - const testPath = path - .relative(docsPath, path.join(testRoot, `${rule.name}.js`)) - .replace(/\\/gu, "/") - - return `\n\n## 🔎 Implementation\n\n- [Rule source](${rulePath})\n- [Test source](${testPath})` -} - -for (const rule of rules) { - const filePath = path.resolve(docsRoot, `${rule.name}.md`) - const original = fs.readFileSync(filePath, "utf8") - const body = original.replace(headerPattern, "").replace(footerPattern, "") - const content = `${renderHeader(rule)}${body}${renderFooter(rule)}\n` - - fs.writeFileSync(filePath, content) -} diff --git a/scripts/update-readme.js b/scripts/update-readme.js deleted file mode 100644 index 7eddad04..00000000 --- a/scripts/update-readme.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * @author Toru Nagashima - * See LICENSE file in root directory for full license. - */ -"use strict" - -const fs = require("fs") -const path = require("path") -const { categories, rules } = require("./rules") -const { pluginName } = require("./utils") - -/** - * Render a given rule as a table row. - * @param {RuleInfo} rule The rule information. - * @returns {string} The table row. - */ -function renderRule(rule) { - const mark = `${rule.recommended ? "⭐️" : ""}${rule.fixable ? "✒️" : ""}` - const link = `[${rule.id}](./docs/rules/${rule.name}.md)` - const description = rule.description || "(no description)" - return `| ${link} | ${description} | ${mark} |` -} - -/** - * Render a given rule as a table row. - * @param {RuleInfo} rule The rule information. - * @returns {string} The table row. - */ -function renderDeprecatedRule(rule) { - const link = `[${rule.id}](./docs/rules/${rule.name}.md)` - const pluginNameReg = new RegExp(`^${pluginName}[/]`, "u") - const replacedBy = rule.replacedBy - .map(nameRaw => { - const name = nameRaw.replace(pluginNameReg, "") - return `[${pluginName}/${name}](./docs/rules/${name}.md)` - }) - .join(" and ") - - return `| ${link} | ${replacedBy || "(nothing)"} |` -} - -/** - * Render a given category as a section. - * @param {CategoryInfo} category The rule information. - * @returns {string} The section. - */ -function renderCategory(category) { - return `### ${category.id} - -| Rule ID | Description | | -|:--------|:------------|:--:| -${category.rules.map(renderRule).join("\n")} -` -} - -const filePath = path.resolve(__dirname, "../README.md") -const content = `${categories.map(renderCategory).join("\n")} -### Deprecated rules - -These rules have been deprecated in accordance with the [deprecation policy](https://eslint.org/docs/user-guide/rule-deprecation), and replaced by newer rules: - -| Rule ID | Replaced by | -|:--------|:------------| -${rules - .filter(rule => rule.deprecated) - .map(renderDeprecatedRule) - .join("\n")} -` - -fs.writeFileSync( - filePath, - fs - .readFileSync(filePath, "utf8") - .replace( - /[\s\S]*/u, - `\n${content}\n` - ) -) diff --git a/scripts/update-rule-docs.js b/scripts/update-rule-docs.js new file mode 100644 index 00000000..94a4435d --- /dev/null +++ b/scripts/update-rule-docs.js @@ -0,0 +1,41 @@ +/** + * @author Toru Nagashima + * See LICENSE file in root directory for full license. + */ +"use strict" + +const fs = require("fs") +const path = require("path") +const { rules } = require("./rules") +const footerPattern = /\n+## 🔎 Implementation[\s\S]*$/u +const ruleRoot = path.resolve(__dirname, "../lib/rules") +const testRoot = path.resolve(__dirname, "../tests/lib/rules") +const docsRoot = path.resolve(__dirname, "../docs/rules") + +/** @typedef {import("./rules").RuleInfo} RuleInfo */ + +/** + * Render the document header of a given rule. + * @param {RuleInfo} rule The rule information. + * @returns {string} The document header. + */ +function renderFooter(rule) { + const docsPath = path.dirname(path.resolve(docsRoot, `${rule.name}.md`)) + const rulePath = path + .relative(docsPath, path.join(ruleRoot, `${rule.name}.js`)) + .replace(/\\/gu, "/") + const testPath = path + .relative(docsPath, path.join(testRoot, `${rule.name}.js`)) + .replace(/\\/gu, "/") + + return `\n\n## 🔎 Implementation\n\n- [Rule source](${rulePath})\n- [Test source](${testPath})` +} + +for (const rule of rules) { + const filePath = path.resolve(docsRoot, `${rule.name}.md`) + const original = fs.readFileSync(filePath, "utf8") + const body = original.replace(footerPattern, "") + const content = `${body}${renderFooter(rule)}\n` + + fs.writeFileSync(filePath, content) +} diff --git a/scripts/update.js b/scripts/update.js index c239407a..5d7366ee 100644 --- a/scripts/update.js +++ b/scripts/update.js @@ -4,7 +4,5 @@ */ "use strict" -require("./update-docs-header-and-footer") -require("./update-docs-header-and-footer") +require("./update-rule-docs") require("./update-lib-index") -require("./update-readme")