Skip to content

Commit 143f509

Browse files
committed
Fix: no-unsupported-features has false positive (fixes #59)
1 parent 4cb5fd7 commit 143f509

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lib/rules/no-unsupported-features.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var OPTIONS = Object.keys(features)
2323
var FUNC_TYPE = /^(?:Arrow)?Function(?:Declaration|Expression)$/
2424
var CLASS_TYPE = /^Class(?:Declaration|Expression)$/
2525
var DESTRUCTURING_PARENT_TYPE = /^(?:Function(?:Declaration|Expression)|ArrowFunctionExpression|AssignmentExpression|VariableDeclarator)$/
26+
var TOPLEVEL_SCOPE_TYPE = /^(?:global|function|module)$/
2627
var BINARY_NUMBER = /^0[bB]/
2728
var OCTAL_NUMBER = /^0[oO]/
2829
var UNICODE_ESC = /(\\+)u\{[0-9a-fA-F]+?\}/g
@@ -454,7 +455,7 @@ module.exports = function(context) {
454455

455456
"FunctionDeclaration": function(node) {
456457
var scope = context.getScope().upper
457-
if (scope.type !== "global" && scope.type !== "function") {
458+
if (!TOPLEVEL_SCOPE_TYPE.test(scope.type)) {
458459
report(node, "blockScopedFunctions")
459460
}
460461
if (node.generator) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"test:lint": "if-node-version \">=4\" eslint lib tests/lib index.js",
1717
"test:mocha": "nyc mocha tests/lib/**/*.js --reporter progress",
1818
"coverage": "nyc report --reporter=lcov && opener ./coverage/lcov-report/index.html",
19+
"watch": "mocha tests/lib/**/*.js --reporter progress --watch --growl",
1920
"test@2": "rimraf \"node_modules/eslint-{config,plugin}-*\" && npm i eslint@2 && npm run test:mocha -- -i -g NOT_SUPPORTED_ON_2",
2021
"codecov": "nyc report -r lcovonly && codecov"
2122
},

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ var VERSIONS = Object.freeze([0.10, 0.12, 4, 5, 6, 7])
2929
function convertPattern(retv, pattern) {
3030
var i = 0
3131

32+
// If this test is on script mode, it should do this test on module mode as well.
33+
if (!pattern.modules &&
34+
pattern.code.indexOf("'use strict'") !== 0 &&
35+
pattern.name.indexOf("non-strict") === -1
36+
) {
37+
convertPattern(
38+
retv,
39+
Object.create(pattern, {modules: {value: true}})
40+
)
41+
}
42+
3243
// Creates error messages.
3344
var errors = []
3445
for (i = 0; i < pattern.errors; ++i) {

0 commit comments

Comments
 (0)