Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: eslint-community/eslint-plugin-n
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 16.4.0
Choose a base ref
...
head repository: eslint-community/eslint-plugin-n
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 16.5.0
Choose a head ref
  • 5 commits
  • 10 files changed
  • 4 contributors

Commits on Dec 15, 2023

  1. chore: Configure Renovate

    Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com>
    
    ---------
    
    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    Co-authored-by: 唯然 <weiran.zsd@outlook.com>
    Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com>
    3 people authored Dec 15, 2023
    Copy the full SHA
    0d6a0fe View commit details

Commits on Dec 16, 2023

  1. docs: Auto-generate configs list with eslint-doc-generator (#146)

    docs: auto-generate configs list with eslint-doc-generator
    bmish authored Dec 16, 2023
    Copy the full SHA
    6409e34 View commit details

Commits on Dec 20, 2023

  1. feat: Add syntax check for ES2021 to no-unsupported-features/es-synta…

    …x rule (#152)
    
    the change was borrowed from mysticatea#283
    credits goes to @ota-meshi
    aladdin-add authored Dec 20, 2023
    Copy the full SHA
    6835a10 View commit details
  2. feat: Add builtins check for ES2021 to no-unsupported-features/es-bui…

    …ltins rule (#153)
    
    the change was borrowed from mysticatea#284
    
    credits goes to @ota-meshi. :)
    
    Signed-off-by: 唯然 <weiran.zsd@outlook.com>
    aladdin-add authored Dec 20, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    15a5850 View commit details
  3. Release 16.5.0

    aladdin-add committed Dec 20, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0c9c2f3 View commit details
2 changes: 2 additions & 0 deletions .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"use strict"

/** @type {import('eslint-doc-generator').GenerateOptions} */
const config = {
urlConfigs: "https://github.com/eslint-community/eslint-plugin-n#-configs",
configEmoji: [
4 changes: 4 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>eslint/eslint//.github/renovate.json5"]
}
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -150,18 +150,30 @@ For [Shareable Configs](https://eslint.org/docs/latest/developer-guide/shareable

## 🔧 Configs

This plugin provides three configs:
<!-- begin auto-generated configs list -->

| Name | Description |
| :-- | :-- |
| `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. |
| | Name |
| :- | :------------------------ |
| 🟠 | `flat/mixed-esm-and-cjs` |
| ☑️ | `flat/recommended` |
| 🟢 | `flat/recommended-module` |
|| `flat/recommended-script` |
| ☑️ | `recommended` |
| 🟢 | `recommended-module` |
|| `recommended-script` |

<!-- end auto-generated configs list -->

About each config:

- `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.
- `recommended-module`: Considers all files as ES Modules.
- `recommended-script`: Considers all files as CommonJS.

These preset configs:

- 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.
- enable plugin rules indicated by emojis in the [rules table](#-rules).
- add `{ecmaVersion: 2021}` and etc into `parserOptions`.
- add proper globals into `globals`.
- add this plugin into `plugins`.
7 changes: 7 additions & 0 deletions docs/rules/no-unsupported-features/es-builtins.md
Original file line number Diff line number Diff line change
@@ -48,6 +48,13 @@ The `"ignores"` option accepts an array of the following strings.

<details>

**ES2021:**

- `"AggregateError"`
- `"Promise.any"`
- `"WeakRef"`
- `"FinalizationRegistry"`

**ES2020:**

- `"BigInt"`
10 changes: 10 additions & 0 deletions lib/rules/no-unsupported-features/es-builtins.js
Original file line number Diff line number Diff line change
@@ -14,13 +14,19 @@ const getConfiguredNodeVersion = require("../../util/get-configured-node-version

const trackMap = {
globals: {
AggregateError: {
[READ]: { supported: "15.0.0" },
},
Array: {
from: { [READ]: { supported: "4.0.0" } },
of: { [READ]: { supported: "4.0.0" } },
},
BigInt: {
[READ]: { supported: "10.4.0" },
},
FinalizationRegistry: {
[READ]: { supported: "14.6.0" },
},
Map: {
[READ]: { supported: "0.12.0" },
},
@@ -67,6 +73,7 @@ const trackMap = {
Promise: {
[READ]: { supported: "0.12.0" },
allSettled: { [READ]: { supported: "12.9.0" } },
any: { [READ]: { supported: "15.0.0" } },
},
Proxy: {
[READ]: { supported: "6.0.0" },
@@ -123,6 +130,9 @@ const trackMap = {
WeakMap: {
[READ]: { supported: "0.12.0" },
},
WeakRef: {
[READ]: { supported: "14.6.0" },
},
WeakSet: {
[READ]: { supported: "0.12.0" },
},
30 changes: 30 additions & 0 deletions lib/rules/no-unsupported-features/es-syntax.js
Original file line number Diff line number Diff line change
@@ -402,6 +402,28 @@ const features = {
},
],
},

//--------------------------------------------------------------------------
// ES2021
//--------------------------------------------------------------------------
logicalAssignmentOperators: {
ruleId: "no-logical-assignment-operators",
cases: [
{
supported: "15.0.0",
messageId: "no-logical-assignment-operators",
},
],
},
numericSeparators: {
ruleId: "no-numeric-separators",
cases: [
{
supported: "12.5.0",
messageId: "no-numeric-separators",
},
],
},
}
const keywords = Object.keys(features)

@@ -654,6 +676,14 @@ module.exports = {
"Optional chainings are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
"no-nullish-coalescing-operators":
"Nullish coalescing operators are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",

//------------------------------------------------------------------
// ES2021
//------------------------------------------------------------------
"no-logical-assignment-operators":
"Logical assignment operators are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
"no-numeric-separators":
"Numeric separators are not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
},
},
create(context) {
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-n",
"version": "16.4.0",
"version": "16.5.0",
"description": "Additional ESLint's rules for Node.js",
"engines": {
"node": ">=16.0.0"
@@ -32,7 +32,7 @@
"esbuild": "^0.18.7",
"eslint": "^8.53.0",
"eslint-config-prettier": "^8.8.0",
"eslint-doc-generator": "^1.4.3",
"eslint-doc-generator": "^1.6.1",
"eslint-plugin-eslint-plugin": "^5.1.0",
"eslint-plugin-n": "file:.",
"fast-glob": "^3.2.12",
2 changes: 0 additions & 2 deletions tests/lib/rules/no-path-concat.js
Original file line number Diff line number Diff line change
@@ -169,5 +169,3 @@ new RuleTester({
},
],
})

/*eslint-enable no-template-curly-in-string */
136 changes: 136 additions & 0 deletions tests/lib/rules/no-unsupported-features/es-builtins.js
Original file line number Diff line number Diff line change
@@ -72,6 +72,31 @@ ruleTester.run(
"no-unsupported-features/es-builtins",
rule,
concat([
{
keyword: "AggregateError",
valid: [
{
code: "if (error instanceof AggregateError) {}",
options: [{ version: "15.0.0" }],
},
],
invalid: [
{
code: "if (error instanceof AggregateError) {}",
options: [{ version: "14.0.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "AggregateError",
supported: "15.0.0",
version: "14.0.0",
},
},
],
},
],
},
{
keyword: "Array.from",
valid: [
@@ -185,6 +210,31 @@ ruleTester.run(
},
],
},
{
keyword: "FinalizationRegistry",
valid: [
{
code: "new FinalizationRegistry(() => {})",
options: [{ version: "14.6.0" }],
},
],
invalid: [
{
code: "new FinalizationRegistry(() => {})",
options: [{ version: "14.5.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "FinalizationRegistry",
supported: "14.6.0",
version: "14.5.0",
},
},
],
},
],
},
{
keyword: "Map",
valid: [
@@ -1209,6 +1259,49 @@ ruleTester.run(
},
],
},
{
keyword: "Promise.any",
valid: [
{
code: "(function(Promise) { Promise.any }(a))",
options: [{ version: "14.0.0" }],
},
{
code: "Promise.any",
options: [{ version: "15.0.0" }],
},
],
invalid: [
{
code: "Promise.any",
options: [{ version: "14.0.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "Promise.any",
supported: "15.0.0",
version: "14.0.0",
},
},
],
},
{
code: "function wrap() { Promise.any }",
options: [{ version: "14.0.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "Promise.any",
supported: "15.0.0",
version: "14.0.0",
},
},
],
},
],
},
{
keyword: "Proxy",
valid: [
@@ -2006,6 +2099,49 @@ ruleTester.run(
},
],
},
{
keyword: "WeakRef",
valid: [
{
code: "(function(WeakRef) { WeakRef }(a))",
options: [{ version: "14.5.0" }],
},
{
code: "WeakRef",
options: [{ version: "14.6.0" }],
},
],
invalid: [
{
code: "WeakRef",
options: [{ version: "14.5.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "WeakRef",
supported: "14.6.0",
version: "14.5.0",
},
},
],
},
{
code: "function wrap() { WeakRef }",
options: [{ version: "14.5.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "WeakRef",
supported: "14.6.0",
version: "14.5.0",
},
},
],
},
],
},
{
keyword: "WeakSet",
valid: [
105 changes: 99 additions & 6 deletions tests/lib/rules/no-unsupported-features/es-syntax.js
Original file line number Diff line number Diff line change
@@ -10,12 +10,19 @@ const { builtin } = require("globals")
const { Range } = require("semver")
const rule = require("../../../../lib/rules/no-unsupported-features/es-syntax")

const ES2020Supported = (() => {
const config = { parserOptions: { ecmaVersion: 2020 } }
const ES2021Supported = (() => {
const config = { parserOptions: { ecmaVersion: 2021 } }
const messages = new Linter().verify("0n", config)
return messages.length === 0
})()
const ecmaVersion = ES2020Supported ? 2020 : 2019
const ES2020Supported =
ES2021Supported ||
(() => {
const config = { parserOptions: { ecmaVersion: 2020 } }
const messages = new Linter().verify("0n", config)
return messages.length === 0
})()
const ecmaVersion = ES2021Supported ? 2021 : ES2020Supported ? 2020 : 2019

/**
* Makes a file path to a fixture.
@@ -1553,7 +1560,6 @@ ruleTester.run(
],
},
],
/*eslint-enable no-template-curly-in-string */
},
{
keyword: "unicodeCodePointEscapes",
@@ -2592,6 +2598,93 @@ ruleTester.run(
],
},

//----------------------------------------------------------------------
// ES2021
//----------------------------------------------------------------------
{
keyword: "logicalAssignmentOperators",
requiredEcmaVersion: 2021,
valid: [
{
code: "a ||= b",
options: [{ version: "15.0.0" }],
},
{
code: "a &&= b",
options: [{ version: "15.0.0" }],
},
{
code: "a ??= b",
options: [{ version: "15.0.0" }],
},
],
invalid: [
{
code: "a ||= b",
options: [{ version: "14.0.0" }],
errors: [
{
messageId: "no-logical-assignment-operators",
data: {
supported: "15.0.0",
version: "14.0.0",
},
},
],
},
{
code: "a &&= b",
options: [{ version: "14.0.0" }],
errors: [
{
messageId: "no-logical-assignment-operators",
data: {
supported: "15.0.0",
version: "14.0.0",
},
},
],
},
{
code: "a ??= b",
options: [{ version: "14.0.0" }],
errors: [
{
messageId: "no-logical-assignment-operators",
data: {
supported: "15.0.0",
version: "14.0.0",
},
},
],
},
],
},
{
keyword: "numericSeparators",
requiredEcmaVersion: 2021,
valid: [
{
code: "a = 123_456_789",
options: [{ version: "12.5.0" }],
},
],
invalid: [
{
code: "a = 123_456_789",
options: [{ version: "12.4.0" }],
errors: [
{
messageId: "no-numeric-separators",
data: {
supported: "12.5.0",
version: "12.4.0",
},
},
],
},
],
},
//----------------------------------------------------------------------
// MISC
//----------------------------------------------------------------------
@@ -2663,7 +2756,7 @@ ruleTester.run(
{
filename: fixture("invalid/a.js"),
code: "var a = { ...obj }",
options: [{version: '>=8.0.0'}],
options: [{ version: ">=8.0.0" }],
errors: [
{
messageId: "no-rest-spread-properties",
@@ -2684,7 +2777,7 @@ ruleTester.run(
{
filename: fixture("nothing/a.js"),
code: "var a = { ...obj }",
options: [{version: '>=8.0.0'}],
options: [{ version: ">=8.0.0" }],
errors: [
{
messageId: "no-rest-spread-properties",