Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add builtins check for ES2021 to no-unsupported-features/es-builtins rule #284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions docs/rules/no-unsupported-features/es-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ The `"ignores"` option accepts an array of the following strings.

<details>

**ES2021:**

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

**ES2020:**

- `"BigInt"`
Expand Down
10 changes: 10 additions & 0 deletions lib/rules/no-unsupported-features/es-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ 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" } },
},
BigInt: {
[READ]: { supported: "10.4.0" },
},
FinalizationRegistry: {
[READ]: { supported: "14.6.0" },
},
Map: {
[READ]: { supported: "0.12.0" },
},
Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -119,6 +126,9 @@ const trackMap = {
WeakMap: {
[READ]: { supported: "0.12.0" },
},
WeakRef: {
[READ]: { supported: "14.6.0" },
},
WeakSet: {
[READ]: { supported: "0.12.0" },
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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
Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down