Skip to content

Commit

Permalink
💥 update node/no-unsupported-features/es-builtins rule to recognize b…
Browse files Browse the repository at this point in the history
…igint and Promise.allSettled
  • Loading branch information
mysticatea committed Sep 4, 2019
1 parent 9ea67c9 commit b91b48d
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 3 deletions.
9 changes: 8 additions & 1 deletion docs/rules/no-unsupported-features/es-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Editor integrations of ESLint would be useful to know it in real-time.

### Supported ECMAScript features

This rule supports ECMAScript 2019.
This rule supports ECMAScript 2019 and proposals that have been approved as Stage 4 by August 2019.
See also [TC39 finished proposals](https://github.com/tc39/proposals/blob/master/finished-proposals.md).

### Configured Node.js version range
Expand Down Expand Up @@ -61,6 +61,13 @@ The `"ignores"` option accepts an array of the following strings.

<details>

**ES2020:**

- `"BigInt"`
- `"BigInt64Array"`
- `"BigUint64Array"`
- `"Promise.allSettled"`

**ES2019:**

- `"Object.fromEntries"`
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,6 +14,9 @@ const trackMap = {
from: { [READ]: { supported: "4.0.0" } },
of: { [READ]: { supported: "4.0.0" } },
},
BigInt: {
[READ]: { supported: "10.4.0" },
},
Map: {
[READ]: { supported: "0.12.0" },
},
Expand Down Expand Up @@ -59,6 +62,7 @@ const trackMap = {
},
Promise: {
[READ]: { supported: "0.12.0" },
allSettled: { [READ]: { supported: "12.9.0" } },
},
Proxy: {
[READ]: { supported: "6.0.0" },
Expand Down Expand Up @@ -97,6 +101,12 @@ const trackMap = {
Uint32Array: {
[READ]: { supported: "0.10.0" },
},
BigInt64Array: {
[READ]: { supported: "10.4.0" },
},
BigUint64Array: {
[READ]: { supported: "10.4.0" },
},
Float32Array: {
[READ]: { supported: "0.10.0" },
},
Expand Down
180 changes: 178 additions & 2 deletions tests/lib/rules/no-unsupported-features/es-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"use strict"

const { RuleTester } = require("eslint")
const globals = require("globals")
const { builtin } = require("globals")
const rule = require("../../../../lib/rules/no-unsupported-features/es-builtins")

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ function concat(patterns) {

const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 2018 },
globals: globals.es2017,
globals: builtin,
})
ruleTester.run(
"no-unsupported-features/es-builtins",
Expand Down Expand Up @@ -128,6 +128,53 @@ ruleTester.run(
},
],
},
{
keyword: "BigInt",
valid: [
{
code: "bigint",
options: [{ version: "10.3.0" }],
},
{
code: "(function(BigInt) { BigInt }(b))",
options: [{ version: "10.3.0" }],
},
{
code: "BigInt",
options: [{ version: "10.4.0" }],
},
],
invalid: [
{
code: "BigInt",
options: [{ version: "10.3.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "BigInt",
supported: "10.4.0",
version: "10.3.0",
},
},
],
},
{
code: "(function() { BigInt })()",
options: [{ version: "10.3.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "BigInt",
supported: "10.4.0",
version: "10.3.0",
},
},
],
},
],
},
{
keyword: "Map",
valid: [
Expand Down Expand Up @@ -1110,6 +1157,49 @@ ruleTester.run(
},
],
},
{
keyword: "Promise.allSettled",
valid: [
{
code: "(function(Promise) { Promise.allSettled }(a))",
options: [{ version: "12.8.1" }],
},
{
code: "Promise.allSettled",
options: [{ version: "12.9.0" }],
},
],
invalid: [
{
code: "Promise.allSettled",
options: [{ version: "12.8.1" }],
errors: [
{
messageId: "unsupported",
data: {
name: "Promise.allSettled",
supported: "12.9.0",
version: "12.8.1",
},
},
],
},
{
code: "function wrap() { Promise.allSettled }",
options: [{ version: "12.8.1" }],
errors: [
{
messageId: "unsupported",
data: {
name: "Promise.allSettled",
supported: "12.9.0",
version: "12.8.1",
},
},
],
},
],
},
{
keyword: "Proxy",
valid: [
Expand Down Expand Up @@ -1650,6 +1740,92 @@ ruleTester.run(
},
],
},
{
keyword: "BigInt64Array",
valid: [
{
code: "(function(BigInt64Array) { BigInt64Array }(b))",
options: [{ version: "10.3.0" }],
},
{
code: "BigInt64Array",
options: [{ version: "10.4.0" }],
},
],
invalid: [
{
code: "BigInt64Array",
options: [{ version: "10.3.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "BigInt64Array",
supported: "10.4.0",
version: "10.3.0",
},
},
],
},
{
code: "(function() { BigInt64Array })()",
options: [{ version: "10.3.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "BigInt64Array",
supported: "10.4.0",
version: "10.3.0",
},
},
],
},
],
},
{
keyword: "BigUint64Array",
valid: [
{
code: "(function(BigUint64Array) { BigUint64Array }(b))",
options: [{ version: "10.3.0" }],
},
{
code: "BigUint64Array",
options: [{ version: "10.4.0" }],
},
],
invalid: [
{
code: "BigUint64Array",
options: [{ version: "10.3.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "BigUint64Array",
supported: "10.4.0",
version: "10.3.0",
},
},
],
},
{
code: "(function() { BigUint64Array })()",
options: [{ version: "10.3.0" }],
errors: [
{
messageId: "unsupported",
data: {
name: "BigUint64Array",
supported: "10.4.0",
version: "10.3.0",
},
},
],
},
],
},
{
keyword: "Float32Array",
valid: [
Expand Down

0 comments on commit b91b48d

Please sign in to comment.