From 075f0c5170a0a2ae797b04c1725ebf360b10b678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Sun, 23 Apr 2023 17:01:30 +0800 Subject: [PATCH] feat!: engines.node defaults to 16.0.0 (#91) * feat!: engines.node defaults to 16.0.0 node.js < 13, v15 has been eol. and node.js v14 will be eol in a few months. refs: #42 * docs: update docs to reflect the new default version * docs: deduplication of the configured Node.js version range * docs: fix node lts statement --- README.md | 27 +++++++++++++++++-- docs/rules/no-deprecated-api.md | 19 ++----------- .../no-unsupported-features/es-builtins.md | 27 +++---------------- .../no-unsupported-features/es-syntax.md | 27 +++---------------- .../no-unsupported-features/node-builtins.md | 27 +++---------------- lib/util/get-configured-node-version.js | 4 +-- .../no-unsupported-features/es-syntax.js | 2 ++ 7 files changed, 40 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 59ff02fa..f3ce71b1 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,6 @@ npm install --save-dev eslint eslint-plugin-n - Requires Node.js `>=16.0.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. - **.eslintrc.json** (An example) ```jsonc @@ -53,6 +51,31 @@ npm install --save-dev eslint eslint-plugin-n } ``` +### Configured Node.js version range + +The rules get the supported Node.js version range from the following, falling back to the next if unspecified: + +1. Rule configuration `version` +2. ESLint [shared setting](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings) `node.version` +3. `package.json` [`engines`] field +4. `>=16.0.0` + +If you omit the [engines] field, this rule chooses `>=16.0.0` as the configured Node.js version since `16` is the maintained lts (see also [Node.js Release Working Group](https://github.com/nodejs/Release#readme)). + +For Node.js packages, using the [`engines`] field is recommended because it's the official way to indicate support: + +```json +{ + "name": "your-module", + "version": "1.0.0", + "engines": { + "node": ">=16.0.0" + } +} +``` + +For [Shareable Configs](https://eslint.org/docs/latest/developer-guide/shareable-configs) or packages with a different development environment (e.g. pre-compiled, web package, etc.), you can configure ESLint with `settings.node.version` to specify support. + ## 📖 Rules diff --git a/docs/rules/no-deprecated-api.md b/docs/rules/no-deprecated-api.md index 40b45072..c67dd782 100644 --- a/docs/rules/no-deprecated-api.md +++ b/docs/rules/no-deprecated-api.md @@ -141,22 +141,7 @@ This rule reports the following deprecated API. ### Configured Node.js version range -This rule reads the [engines] field of `package.json` to detect which Node.js versions your module is supporting. - -I recommend the use of the [engines] field because it's the official way that indicates which Node.js versions your module is supporting. -For example of `package.json`: - -```json -{ - "name": "your-module", - "version": "1.0.0", - "engines": { - "node": ">=8.0.0" - } -} -``` - -If you omit the [engines] field, this rule chooses `>=8.0.0` as the configured Node.js version since `8` is the minimum version the community is maintaining (see also [Node.js Release Working Group](https://github.com/nodejs/Release#readme)). +[Configured Node.js version range](../../README.md#configured-nodejs-version-range) ### Options @@ -166,7 +151,7 @@ This rule has 4 options. { "rules": { "n/no-deprecated-api": ["error", { - "version": ">=8.0.0", + "version": ">=16.0.0", "ignoreModuleItems": [], "ignoreGlobalItems": [] "ignoreIndirectDependencies": true diff --git a/docs/rules/no-unsupported-features/es-builtins.md b/docs/rules/no-unsupported-features/es-builtins.md index 3e087b0d..4c6e438f 100644 --- a/docs/rules/no-unsupported-features/es-builtins.md +++ b/docs/rules/no-unsupported-features/es-builtins.md @@ -19,35 +19,14 @@ See also [TC39 finished proposals](https://github.com/tc39/proposals/blob/master ### Configured Node.js version range -This rule gets the supported Node.js version range from the following, falling back to the next if unspecified: - -1. Rule configuration `version` -2. ESLint [shared setting](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings) `node.version` -3. `package.json` [`engines`] field -4. `>=8.0.0` - -The default version is `8.0.0` because it's the minimum version the community is maintaining (see also [Node.js Release Working Group](https://github.com/nodejs/Release#readme)). - -For Node.js packages, using the [`engines`] field is recommended because it's the official way to indicate support: - -```json -{ - "name": "your-module", - "version": "1.0.0", - "engines": { - "node": ">=8.0.0" - } -} -``` - -For [Shareable Configs](https://eslint.org/docs/latest/developer-guide/shareable-configs) or packages with a different development environment (e.g. pre-compiled, web package, etc.), you can configure ESLint with `settings.node.version` to specify support. +[Configured Node.js version range](../../../README.md#configured-nodejs-version-range) ### Options ```json { "n/no-unsupported-features/es-builtins": ["error", { - "version": ">=8.0.0", + "version": ">=16.0.0", "ignores": [] }] } @@ -159,7 +138,7 @@ For Example: { "settings": { "node": { - "version": ">=8.0.0", + "version": ">=16.0.0", } }, "rules": { diff --git a/docs/rules/no-unsupported-features/es-syntax.md b/docs/rules/no-unsupported-features/es-syntax.md index cf7771db..e4f51daa 100644 --- a/docs/rules/no-unsupported-features/es-syntax.md +++ b/docs/rules/no-unsupported-features/es-syntax.md @@ -22,35 +22,14 @@ For example, set `2020` to `parserOptions.ecmaVersion`. ### Configured Node.js version range -This rule gets the supported Node.js version range from the following, falling back to the next if unspecified: - -1. Rule configuration `version` -2. ESLint [shared setting](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings) `node.version` -3. `package.json` [`engines`] field -4. `>=8.0.0` - -The default version is `8.0.0` because it's the minimum version the community is maintaining (see also [Node.js Release Working Group](https://github.com/nodejs/Release#readme)). - -For Node.js packages, using the [`engines`] field is recommended because it's the official way to indicate support: - -```json -{ - "name": "your-module", - "version": "1.0.0", - "engines": { - "node": ">=8.0.0" - } -} -``` - -For [Shareable Configs](https://eslint.org/docs/latest/developer-guide/shareable-configs) or packages with a different development environment (e.g. pre-compiled, web package, etc.), you can configure ESLint with `settings.node.version` to specify support. +[Configured Node.js version range](../../../README.md#configured-nodejs-version-range) ### Options ```json { "n/no-unsupported-features/es-syntax": ["error", { - "version": ">=8.0.0", + "version": ">=16.0.0", "ignores": [] }] } @@ -144,7 +123,7 @@ For Example: { "settings": { "node": { - "version": ">=8.0.0", + "version": ">=16.0.0", } }, "rules": { diff --git a/docs/rules/no-unsupported-features/node-builtins.md b/docs/rules/no-unsupported-features/node-builtins.md index bbdeeab8..a31dfc3d 100644 --- a/docs/rules/no-unsupported-features/node-builtins.md +++ b/docs/rules/no-unsupported-features/node-builtins.md @@ -16,35 +16,14 @@ This rule reports APIs of Node.js built-in APIs on the basis of [Node.js v13.2.0 ### Configured Node.js version range -This rule gets the supported Node.js version range from the following, falling back to the next if unspecified: - -1. Rule configuration `version` -2. ESLint [shared setting](http://eslint.org/docs/user-guide/configuring.html#adding-shared-settings) `node.version` -3. `package.json` [`engines`] field -4. `>=8.0.0` - -The default version is `8.0.0` because it's the minimum version the community is maintaining (see also [Node.js Release Working Group](https://github.com/nodejs/Release#readme)). - -For Node.js packages, using the [`engines`] field is recommended because it's the official way to indicate support: - -```json -{ - "name": "your-module", - "version": "1.0.0", - "engines": { - "node": ">=8.0.0" - } -} -``` - -For [Shareable Configs](https://eslint.org/docs/latest/developer-guide/shareable-configs) or packages with a different development environment (e.g. pre-compiled, web package, etc.), you can configure ESLint with `settings.node.version` to specify support. +[Configured Node.js version range](../../../README.md#configured-nodejs-version-range) ### Options ```json { "n/no-unsupported-features/node-builtins": ["error", { - "version": ">=8.0.0", + "version": ">=16.0.0", "ignores": [] }] } @@ -343,7 +322,7 @@ For Example: { "settings": { "node": { - "version": ">=8.0.0", + "version": ">=16.0.0", } }, "rules": { diff --git a/lib/util/get-configured-node-version.js b/lib/util/get-configured-node-version.js index ff5f9dcd..c1395d7f 100644 --- a/lib/util/get-configured-node-version.js +++ b/lib/util/get-configured-node-version.js @@ -36,7 +36,7 @@ function getEnginesNode(filename) { * * 1. Parse a given version then return it if it's valid. * 2. Look package.json up and parse `engines.node` then return it if it's valid. - * 3. Return `>=8.0.0`. + * 3. Return `>=16.0.0`. * * @param {string|undefined} version The version range text. * @param {string} filename The path to the current linting file. @@ -52,7 +52,7 @@ module.exports = function getConfiguredNodeVersion(context) { return ( getSemverRange(version) || getEnginesNode(filePath) || - getSemverRange(">=8.0.0") + getSemverRange(">=16.0.0") ) } diff --git a/tests/lib/rules/no-unsupported-features/es-syntax.js b/tests/lib/rules/no-unsupported-features/es-syntax.js index 1e402321..0f85de62 100644 --- a/tests/lib/rules/no-unsupported-features/es-syntax.js +++ b/tests/lib/rules/no-unsupported-features/es-syntax.js @@ -2663,6 +2663,7 @@ ruleTester.run( { filename: fixture("invalid/a.js"), code: "var a = { ...obj }", + options: [{version: '>=8.0.0'}], errors: [ { messageId: "no-rest-spread-properties", @@ -2683,6 +2684,7 @@ ruleTester.run( { filename: fixture("nothing/a.js"), code: "var a = { ...obj }", + options: [{version: '>=8.0.0'}], errors: [ { messageId: "no-rest-spread-properties",