From c3d63a9b8295215538cb73545956ef05f73962e8 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Tue, 1 Jun 2021 20:17:43 +0900 Subject: [PATCH] Add builtins check for ES2021 to `no-unsupported-features/es-builtins` rule --- .github/workflows/CI.yml | 42 +++++- .../no-unsupported-features/es-builtins.md | 7 + .../no-unsupported-features/es-builtins.js | 10 ++ package.json | 4 +- .../no-unsupported-features/es-builtins.js | 136 ++++++++++++++++++ 5 files changed, 190 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f430cbd8..ce2dc9b7 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -31,13 +31,25 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] - eslint: [6.x, 5.x] - node: [13.x, 12.x, 10.x, 8.x] + eslint: [7.x, 6.x, 5.x] + node: [14.x, 12.x, 10.x, 8.x] exclude: # On Windows, run tests with only the latest LTS environments. + - os: windows-latest + eslint: 7.x + node: 12.x + - os: windows-latest + eslint: 7.x + node: 10.x + - os: windows-latest + eslint: 7.x + node: 8.x - os: windows-latest eslint: 6.x - node: 13.x + node: 14.x + - os: windows-latest + eslint: 6.x + node: 12.x - os: windows-latest eslint: 6.x node: 10.x @@ -46,7 +58,7 @@ jobs: node: 8.x - os: windows-latest eslint: 5.x - node: 13.x + node: 14.x - os: windows-latest eslint: 5.x node: 12.x @@ -57,9 +69,21 @@ jobs: eslint: 5.x node: 8.x # On macOS, run tests with only the latest LTS environments. + - os: macOS-latest + eslint: 7.x + node: 12.x + - os: macOS-latest + eslint: 7.x + node: 10.x + - os: macOS-latest + eslint: 7.x + node: 8.x + - os: macOS-latest + eslint: 6.x + node: 14.x - os: macOS-latest eslint: 6.x - node: 13.x + node: 12.x - os: macOS-latest eslint: 6.x node: 10.x @@ -68,7 +92,7 @@ jobs: node: 8.x - os: macOS-latest eslint: 5.x - node: 13.x + node: 14.x - os: macOS-latest eslint: 5.x node: 12.x @@ -78,10 +102,14 @@ jobs: - os: macOS-latest eslint: 5.x node: 8.x + # Run ESLint 7.x tests on only the supports LTS Node. + - os: ubuntu-latest + eslint: 7.x + node: 8.x # Run ESLint 5.x tests on only the latest LTS Node. - os: ubuntu-latest eslint: 5.x - node: 13.x + node: 12.x - os: ubuntu-latest eslint: 5.x node: 10.x diff --git a/docs/rules/no-unsupported-features/es-builtins.md b/docs/rules/no-unsupported-features/es-builtins.md index 7bc561eb..45c9b3c7 100644 --- a/docs/rules/no-unsupported-features/es-builtins.md +++ b/docs/rules/no-unsupported-features/es-builtins.md @@ -61,6 +61,13 @@ The `"ignores"` option accepts an array of the following strings.
+**ES2021:** + +- `"AggregateError"` +- `"Promise.any"` +- `"WeakRef"` +- `"FinalizationRegistry"` + **ES2020:** - `"BigInt"` diff --git a/lib/rules/no-unsupported-features/es-builtins.js b/lib/rules/no-unsupported-features/es-builtins.js index 3165afa9..1626c906 100644 --- a/lib/rules/no-unsupported-features/es-builtins.js +++ b/lib/rules/no-unsupported-features/es-builtins.js @@ -10,6 +10,9 @@ const enumeratePropertyNames = require("../../util/enumerate-property-names") const trackMap = { globals: { + AggregateError: { + [READ]: { supported: "15.0.0" }, + }, Array: { from: { [READ]: { supported: "4.0.0" } }, of: { [READ]: { supported: "4.0.0" } }, @@ -17,6 +20,9 @@ const trackMap = { BigInt: { [READ]: { supported: "10.4.0" }, }, + FinalizationRegistry: { + [READ]: { supported: "14.6.0" }, + }, Map: { [READ]: { supported: "0.12.0" }, }, @@ -63,6 +69,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" }, @@ -119,6 +126,9 @@ const trackMap = { WeakMap: { [READ]: { supported: "0.12.0" }, }, + WeakRef: { + [READ]: { supported: "14.6.0" }, + }, WeakSet: { [READ]: { supported: "0.12.0" }, }, diff --git a/package.json b/package.json index 8e23f2ea..46a36471 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,10 @@ "devDependencies": { "@mysticatea/eslint-plugin": "^10.0.3", "codecov": "^3.3.0", - "eslint": "^6.3.0", + "eslint": "^7.27.0", "eslint-plugin-node": "file:.", "fast-glob": "^2.2.6", - "globals": "^11.12.0", + "globals": "^13.9.0", "mocha": "^6.1.4", "nyc": "^14.0.0", "opener": "^1.5.1", diff --git a/tests/lib/rules/no-unsupported-features/es-builtins.js b/tests/lib/rules/no-unsupported-features/es-builtins.js index 5653ffdc..c3c165ec 100644 --- a/tests/lib/rules/no-unsupported-features/es-builtins.js +++ b/tests/lib/rules/no-unsupported-features/es-builtins.js @@ -62,6 +62,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: [ @@ -175,6 +200,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: [ @@ -1200,6 +1250,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: [ @@ -1998,6 +2091,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: [