Skip to content

Commit

Permalink
Update: update no-unsupported-features for Node 7.6 supports async/aw…
Browse files Browse the repository at this point in the history
…ait (fixes #67)
  • Loading branch information
mysticatea committed Feb 23, 2017
1 parent 1c12cae commit 91ebdf4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/rules/no-unsupported-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ The `version` option accepts the following version number:
- `5`
- `6`
- `7`
- `7.6` ... It supports async functions.

### ignores

Expand Down
11 changes: 4 additions & 7 deletions lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
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]
const VERSIONS = [0.10, 0.12, 4, 5, 6, 7, 7.6]
const OPTIONS = Object.keys(features)
const FUNC_TYPE = /^(?:Arrow)?Function(?:Declaration|Expression)$/
const CLASS_TYPE = /^Class(?:Declaration|Expression)$/
Expand Down Expand Up @@ -69,11 +69,8 @@ function parseVersion(comparator) {
const major = comparator.semver.major
const minor = comparator.semver.minor

if (major >= 1) {
return major
}
if (minor >= 10) {
return parseFloat(`0.${minor}`)
if (major >= 1 || minor >= 10) {
return parseFloat(`${major}.${minor}`)
}
return 0.10
}
Expand Down Expand Up @@ -174,7 +171,7 @@ function parseOptions(options, defaultVersion) {
}

return Object.freeze({
version: version < 1 ? version.toFixed(2) : version.toFixed(0),
version: version < 1 ? version.toFixed(2) : String(version),
features: Object.freeze(OPTIONS.reduce(
(retv, key) => {
const feature = features[key]
Expand Down
2 changes: 1 addition & 1 deletion lib/util/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = {
"asyncAwait": {
alias: ["syntax"],
name: "Async Functions",
node: NaN,
node: 7.6,
},
"trailingCommasInFunctionSyntax": {
alias: ["syntax"],
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/no-unsupported-features/gte-7.5.0/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"name": "test",
"engines": {
"node": ">=7.5.0"
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/no-unsupported-features/gte-7.6.0/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"name": "test",
"engines": {
"node": ">=7.6.0"
}
}
17 changes: 14 additions & 3 deletions tests/lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const RuleTester = require("eslint").RuleTester
// Helpers
//------------------------------------------------------------------------------

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

/**
* Creates test pattern.
Expand Down Expand Up @@ -51,7 +51,7 @@ function convertPattern(retv, pattern) {

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

// Skips if ignored
if (pattern.ignores && pattern.ignores.indexOf(version) !== -1) {
Expand Down Expand Up @@ -362,7 +362,7 @@ ruleTester.run("no-unsupported-features", rule, [
"class A { async foo() { await obj; } };",
].join("\n"),
errors: 10,
supported: NaN,
supported: 7.6,
ignores: [0.10, 0.12, 4, 5],
},
{
Expand Down Expand Up @@ -1041,6 +1041,11 @@ ruleTester.run("no-unsupported-features", rule, [
parserOptions: {ecmaVersion: 2017},
options: [{ignores: ["asyncAwait"]}],
},
{
filename: fixture("gte-7.6.0/a.js"),
code: "var a = async () => 1",
parserOptions: {ecmaVersion: 2017},
},
],
invalid: [
{
Expand All @@ -1067,5 +1072,11 @@ ruleTester.run("no-unsupported-features", rule, [
env: {es6: true},
errors: ["Arrow Functions are not supported yet on Node v0.10."],
},
{
filename: fixture("gte-7.5.0/a.js"),
code: "var a = async () => 1",
parserOptions: {ecmaVersion: 2017},
errors: ["Async Functions are not supported yet on Node v7.5."],
},
],
}))

0 comments on commit 91ebdf4

Please sign in to comment.