Skip to content

Commit

Permalink
Breaking: update no-unsupported-features rule (fixes #79)
Browse files Browse the repository at this point in the history
- Support Node.js 8
- Add about SharedArrayBuffer and Atomics.
- Change the default version to 4 from 0.10.
- Chore: tweak error messages.
- Chore: reduce duplicated messages.
  • Loading branch information
mysticatea committed Jun 1, 2017
1 parent fdd7877 commit 3387336
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 85 deletions.
24 changes: 20 additions & 4 deletions docs/rules/no-unsupported-features.md
Expand Up @@ -3,7 +3,7 @@
Node.js doesn't support all ECMAScript standard features.
This rule reports when you used unsupported ECMAScript 2015-2017 features on the specified Node.js version.

> ※ About ECMAScript 2017, this rule reports only features which have arrived at stage 4 until 2016-10-31.
> ※ About ECMAScript 2017, this rule reports only features which have arrived at stage 4 until 2017-06-01.
> It needs a major version bump in order to cover newer features.
## Rule Details
Expand Down Expand Up @@ -32,7 +32,7 @@ For example of `package.json`:
}
```

If the [engines] field is omitted, this rule chooses `0.12` since it's the minimum version the community is maintaining.
If the [engines] field is omitted, this rule chooses `4` since it's the minimum version the community is maintaining.

Examples of :-1: **incorrect** code for this rule:

Expand Down Expand Up @@ -126,7 +126,8 @@ The `version` option accepts the following version number:
- `5`
- `6`
- `7`
- `7.6` ... It supports async functions.
- `7.6` ... supports async functions.
- `8` ... supports trailing commas in functions.

### ignores

Expand Down Expand Up @@ -157,7 +158,7 @@ The `"ignores"` option accepts an array of the following strings.
- `"modules"`
- `"exponentialOperators"`
- `"asyncAwait"`
- `"trailingCommasInFunctionSyntax"`
- `"trailingCommasInFunctions"`
- `"runtime"` (group)
- `"globalObjects"` (group)
- `"typedArrays"` (group)
Expand All @@ -179,6 +180,8 @@ The `"ignores"` option accepts an array of the following strings.
- `"Reflect"`
- `"Promise"`
- `"Symbol"`
- `"SharedArrayBuffer"`
- `"Atomics"`
- `"staticMethods"` (group)
- `"Object.*"` (group)
- `"Object.assign"`
Expand Down Expand Up @@ -232,6 +235,19 @@ The `"ignores"` option accepts an array of the following strings.
- `"Symbol.toPrimitive"`
- `"Symbol.toStringTag"`
- `"Symbol.unscopables"`
- `"Atomics.*"` (group)
- `"Atomics.add"`
- `"Atomics.and"`
- `"Atomics.compareExchange"`
- `"Atomics.exchange"`
- `"Atomics.wait"`
- `"Atomics.wake"`
- `"Atomics.isLockFree"`
- `"Atomics.load"`
- `"Atomics.or"`
- `"Atomics.store"`
- `"Atomics.sub"`
- `"Atomics.xor"`
- `"extends"` (group)
- `"extendsArray"`
- `"extendsRegExp"`
Expand Down
32 changes: 24 additions & 8 deletions lib/rules/no-unsupported-features.js
Expand Up @@ -18,7 +18,7 @@ const getValueIfString = require("../util/get-value-if-string")
// Helpers
//------------------------------------------------------------------------------

const VERSIONS = [0.10, 0.12, 4, 5, 6, 7, 7.6]
const VERSIONS = [0.10, 0.12, 4, 5, 6, 7, 7.6, 8]
const OPTIONS = Object.keys(features)
const FUNC_TYPE = /^(?:Arrow)?Function(?:Declaration|Expression)$/
const CLASS_TYPE = /^Class(?:Declaration|Expression)$/
Expand All @@ -32,6 +32,7 @@ const NEW_BUILTIN_TYPES = [
"Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array",
"Int32Array", "Uint32Array", "Float32Array", "Float64Array", "DataView",
"Map", "Set", "WeakMap", "WeakSet", "Proxy", "Reflect", "Promise", "Symbol",
"SharedArrayBuffer", "Atomics",
]
const SUBCLASSING_TEST_TARGETS = [
"Array", "RegExp", "Function", "Promise", "Boolean", "Number", "String",
Expand All @@ -57,6 +58,10 @@ const PROPERTY_TEST_TARGETS = {
"hasInstance", "isConcatSpreadablec", "iterator", "species", "replace",
"search", "split", "match", "toPrimitive", "toStringTag", "unscopables",
],
Atomics: [
"add", "and", "compareExchange", "exchange", "wait", "wake",
"isLockFree", "load", "or", "store", "sub", "xor",
],
}

/**
Expand All @@ -79,7 +84,7 @@ function parseVersion(comparator) {
* Gets default version configuration of this rule.
*
* This finds and reads 'package.json' file, then parses 'engines.node' field.
* If it's nothing, this returns '0.10'.
* If it's nothing, this returns '4'.
*
* @param {string} filename - The file name of the current linting file.
* @returns {number} The default version configuration.
Expand Down Expand Up @@ -111,7 +116,7 @@ function getDefaultVersion(filename) {
// ignore
}

return 0.10
return 4
}

/**
Expand Down Expand Up @@ -388,6 +393,17 @@ function create(context) {
// Check new global variables.
for (const name of NEW_BUILTIN_TYPES) {
for (const reference of getReferences([name])) {
// Ignore if it's using new static methods.
const node = reference.identifier
const parentNode = node.parent
const properties = PROPERTY_TEST_TARGETS[name]
if (properties && parentNode.type === "MemberExpression") {
const propertyName = (parentNode.computed ? getValueIfString : getIdentifierName)(parentNode.property)
if (properties.indexOf(propertyName) !== -1) {
continue
}
}

report(reference.identifier, name)
}
}
Expand Down Expand Up @@ -432,7 +448,7 @@ function create(context) {
report(node, "asyncAwait")
}
if (hasTrailingCommaForFunction(node)) {
report(node, "trailingCommasInFunctionSyntax")
report(node, "trailingCommasInFunctions")
}
},

Expand All @@ -454,7 +470,7 @@ function create(context) {
report(node, "asyncAwait")
}
if (hasTrailingCommaForFunction(node)) {
report(node, "trailingCommasInFunctionSyntax")
report(node, "trailingCommasInFunctions")
}
},

Expand All @@ -466,7 +482,7 @@ function create(context) {
report(node, "asyncAwait")
}
if (hasTrailingCommaForFunction(node)) {
report(node, "trailingCommasInFunctionSyntax")
report(node, "trailingCommasInFunctions")
}
},

Expand Down Expand Up @@ -549,7 +565,7 @@ function create(context) {

"CallExpression"(node) {
if (hasTrailingCommaForCall(node)) {
report(node, "trailingCommasInFunctionSyntax")
report(node, "trailingCommasInFunctions")
}
},

Expand Down Expand Up @@ -599,7 +615,7 @@ function create(context) {
}
}
if (hasTrailingCommaForCall(node)) {
report(node, "trailingCommasInFunctionSyntax")
report(node, "trailingCommasInFunctions")
}
},

Expand Down

0 comments on commit 3387336

Please sign in to comment.