Skip to content

Commit 91ebdf4

Browse files
committed
Update: update no-unsupported-features for Node 7.6 supports async/await (fixes #67)
1 parent 1c12cae commit 91ebdf4

File tree

6 files changed

+34
-11
lines changed

6 files changed

+34
-11
lines changed

docs/rules/no-unsupported-features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ The `version` option accepts the following version number:
126126
- `5`
127127
- `6`
128128
- `7`
129+
- `7.6` ... It supports async functions.
129130

130131
### ignores
131132

lib/rules/no-unsupported-features.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const getValueIfString = require("../util/get-value-if-string")
1818
// Helpers
1919
//------------------------------------------------------------------------------
2020

21-
const VERSIONS = [0.10, 0.12, 4, 5, 6, 7]
21+
const VERSIONS = [0.10, 0.12, 4, 5, 6, 7, 7.6]
2222
const OPTIONS = Object.keys(features)
2323
const FUNC_TYPE = /^(?:Arrow)?Function(?:Declaration|Expression)$/
2424
const CLASS_TYPE = /^Class(?:Declaration|Expression)$/
@@ -69,11 +69,8 @@ function parseVersion(comparator) {
6969
const major = comparator.semver.major
7070
const minor = comparator.semver.minor
7171

72-
if (major >= 1) {
73-
return major
74-
}
75-
if (minor >= 10) {
76-
return parseFloat(`0.${minor}`)
72+
if (major >= 1 || minor >= 10) {
73+
return parseFloat(`${major}.${minor}`)
7774
}
7875
return 0.10
7976
}
@@ -174,7 +171,7 @@ function parseOptions(options, defaultVersion) {
174171
}
175172

176173
return Object.freeze({
177-
version: version < 1 ? version.toFixed(2) : version.toFixed(0),
174+
version: version < 1 ? version.toFixed(2) : String(version),
178175
features: Object.freeze(OPTIONS.reduce(
179176
(retv, key) => {
180177
const feature = features[key]

lib/util/features.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ module.exports = {
139139
"asyncAwait": {
140140
alias: ["syntax"],
141141
name: "Async Functions",
142-
node: NaN,
142+
node: 7.6,
143143
},
144144
"trailingCommasInFunctionSyntax": {
145145
alias: ["syntax"],
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"private": true,
3+
"name": "test",
4+
"engines": {
5+
"node": ">=7.5.0"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"private": true,
3+
"name": "test",
4+
"engines": {
5+
"node": ">=7.6.0"
6+
}
7+
}

tests/lib/rules/no-unsupported-features.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const RuleTester = require("eslint").RuleTester
1717
// Helpers
1818
//------------------------------------------------------------------------------
1919

20-
const VERSIONS = Object.freeze([0.10, 0.12, 4, 5, 6, 7])
20+
const VERSIONS = Object.freeze([0.10, 0.12, 4, 5, 6, 7, 7.6])
2121

2222
/**
2323
* Creates test pattern.
@@ -51,7 +51,7 @@ function convertPattern(retv, pattern) {
5151

5252
// Creates each pattern of Node versions.
5353
VERSIONS.forEach(version => {
54-
const versionText = version < 1 ? version.toFixed(2) : version.toFixed(0)
54+
const versionText = version < 1 ? version.toFixed(2) : String(version)
5555

5656
// Skips if ignored
5757
if (pattern.ignores && pattern.ignores.indexOf(version) !== -1) {
@@ -362,7 +362,7 @@ ruleTester.run("no-unsupported-features", rule, [
362362
"class A { async foo() { await obj; } };",
363363
].join("\n"),
364364
errors: 10,
365-
supported: NaN,
365+
supported: 7.6,
366366
ignores: [0.10, 0.12, 4, 5],
367367
},
368368
{
@@ -1041,6 +1041,11 @@ ruleTester.run("no-unsupported-features", rule, [
10411041
parserOptions: {ecmaVersion: 2017},
10421042
options: [{ignores: ["asyncAwait"]}],
10431043
},
1044+
{
1045+
filename: fixture("gte-7.6.0/a.js"),
1046+
code: "var a = async () => 1",
1047+
parserOptions: {ecmaVersion: 2017},
1048+
},
10441049
],
10451050
invalid: [
10461051
{
@@ -1067,5 +1072,11 @@ ruleTester.run("no-unsupported-features", rule, [
10671072
env: {es6: true},
10681073
errors: ["Arrow Functions are not supported yet on Node v0.10."],
10691074
},
1075+
{
1076+
filename: fixture("gte-7.5.0/a.js"),
1077+
code: "var a = async () => 1",
1078+
parserOptions: {ecmaVersion: 2017},
1079+
errors: ["Async Functions are not supported yet on Node v7.5."],
1080+
},
10701081
],
10711082
}))

0 commit comments

Comments
 (0)