Skip to content

Commit

Permalink
Fix: no-unsupported-features has false positive (fixes #59)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Dec 1, 2016
1 parent 4cb5fd7 commit 143f509
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var OPTIONS = Object.keys(features)
var FUNC_TYPE = /^(?:Arrow)?Function(?:Declaration|Expression)$/
var CLASS_TYPE = /^Class(?:Declaration|Expression)$/
var DESTRUCTURING_PARENT_TYPE = /^(?:Function(?:Declaration|Expression)|ArrowFunctionExpression|AssignmentExpression|VariableDeclarator)$/
var TOPLEVEL_SCOPE_TYPE = /^(?:global|function|module)$/
var BINARY_NUMBER = /^0[bB]/
var OCTAL_NUMBER = /^0[oO]/
var UNICODE_ESC = /(\\+)u\{[0-9a-fA-F]+?\}/g
Expand Down Expand Up @@ -454,7 +455,7 @@ module.exports = function(context) {

"FunctionDeclaration": function(node) {
var scope = context.getScope().upper
if (scope.type !== "global" && scope.type !== "function") {
if (!TOPLEVEL_SCOPE_TYPE.test(scope.type)) {
report(node, "blockScopedFunctions")
}
if (node.generator) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"test:lint": "if-node-version \">=4\" eslint lib tests/lib index.js",
"test:mocha": "nyc mocha tests/lib/**/*.js --reporter progress",
"coverage": "nyc report --reporter=lcov && opener ./coverage/lcov-report/index.html",
"watch": "mocha tests/lib/**/*.js --reporter progress --watch --growl",
"test@2": "rimraf \"node_modules/eslint-{config,plugin}-*\" && npm i eslint@2 && npm run test:mocha -- -i -g NOT_SUPPORTED_ON_2",
"codecov": "nyc report -r lcovonly && codecov"
},
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ var VERSIONS = Object.freeze([0.10, 0.12, 4, 5, 6, 7])
function convertPattern(retv, pattern) {
var i = 0

// If this test is on script mode, it should do this test on module mode as well.
if (!pattern.modules &&
pattern.code.indexOf("'use strict'") !== 0 &&
pattern.name.indexOf("non-strict") === -1
) {
convertPattern(
retv,
Object.create(pattern, {modules: {value: true}})
)
}

// Creates error messages.
var errors = []
for (i = 0; i < pattern.errors; ++i) {
Expand Down

0 comments on commit 143f509

Please sign in to comment.