Skip to content

Commit

Permalink
feat!: engines.node defaults to 16.0.0 (mysticatea#91)
Browse files Browse the repository at this point in the history
* 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: mysticatea#42

* docs: update docs to reflect the new default version

* docs: deduplication of the configured Node.js version range

* docs: fix node lts statement
  • Loading branch information
aladdin-add authored Apr 23, 2023
1 parent aa75610 commit 075f0c5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 93 deletions.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

<!-- begin auto-generated rules list -->
Expand Down
19 changes: 2 additions & 17 deletions docs/rules/no-deprecated-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
27 changes: 3 additions & 24 deletions docs/rules/no-unsupported-features/es-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}]
}
Expand Down Expand Up @@ -159,7 +138,7 @@ For Example:
{
"settings": {
"node": {
"version": ">=8.0.0",
"version": ">=16.0.0",
}
},
"rules": {
Expand Down
27 changes: 3 additions & 24 deletions docs/rules/no-unsupported-features/es-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}]
}
Expand Down Expand Up @@ -144,7 +123,7 @@ For Example:
{
"settings": {
"node": {
"version": ">=8.0.0",
"version": ">=16.0.0",
}
},
"rules": {
Expand Down
27 changes: 3 additions & 24 deletions docs/rules/no-unsupported-features/node-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}]
}
Expand Down Expand Up @@ -343,7 +322,7 @@ For Example:
{
"settings": {
"node": {
"version": ">=8.0.0",
"version": ">=16.0.0",
}
},
"rules": {
Expand Down
4 changes: 2 additions & 2 deletions lib/util/get-configured-node-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -52,7 +52,7 @@ module.exports = function getConfiguredNodeVersion(context) {
return (
getSemverRange(version) ||
getEnginesNode(filePath) ||
getSemverRange(">=8.0.0")
getSemverRange(">=16.0.0")
)
}

Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/no-unsupported-features/es-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 075f0c5

Please sign in to comment.