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

feat: Add builtins check for ES2021 to no-unsupported-features/es-builtins rule #153

Merged
merged 1 commit into from
Dec 20, 2023
Merged
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
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 @@ -48,6 +48,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 @@ -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" },
},
Expand Down Expand Up @@ -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" },
Expand Down Expand Up @@ -123,6 +130,9 @@ const trackMap = {
WeakMap: {
[READ]: { supported: "0.12.0" },
},
WeakRef: {
[READ]: { supported: "14.6.0" },
},
WeakSet: {
[READ]: { supported: "0.12.0" },
},
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 @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down