diff --git a/lib/rules/utils/ast-utils.js b/lib/rules/utils/ast-utils.js index 21742366ce4..ecde099fa02 100644 --- a/lib/rules/utils/ast-utils.js +++ b/lib/rules/utils/ast-utils.js @@ -32,7 +32,6 @@ const thisTagPattern = /^[\s*]*@this/mu; const COMMENTS_IGNORE_PATTERN = /^\s*(?:eslint|jshint\s+|jslint\s+|istanbul\s+|globals?\s+|exported\s+|jscs)/u; -const ESLINT_DIRECTIVE_PATTERN = /^(?:eslint[- ]|(?:globals?|exported) )/u; const LINEBREAKS = new Set(["\r\n", "\r", "\n", "\u2028", "\u2029"]); // A set of node types that can contain a list of statements @@ -909,8 +908,12 @@ module.exports = { const comment = node.value.trim(); return ( - node.type === "Line" && comment.startsWith("eslint-") || - node.type === "Block" && ESLINT_DIRECTIVE_PATTERN.test(comment) + node.type === "Line" && comment.indexOf("eslint-") === 0 || + node.type === "Block" && ( + comment.indexOf("global ") === 0 || + comment.indexOf("eslint ") === 0 || + comment.indexOf("eslint-") === 0 + ) ); }, diff --git a/tests/lib/rules/no-inline-comments.js b/tests/lib/rules/no-inline-comments.js index 7eb0cac730f..463c86eea66 100644 --- a/tests/lib/rules/no-inline-comments.js +++ b/tests/lib/rules/no-inline-comments.js @@ -39,9 +39,6 @@ ruleTester.run("no-inline-comments", rule, { "// A solitary comment", "var a = 1; // eslint-disable-line no-debugger", "var a = 1; /* eslint-disable-line no-debugger */", - "foo(); /* global foo */", - "foo(); /* globals foo */", - "var foo; /* exported foo */", // JSX exception `var a = ( diff --git a/tests/lib/rules/utils/ast-utils.js b/tests/lib/rules/utils/ast-utils.js index 1cd8727b46b..7789de7742c 100644 --- a/tests/lib/rules/utils/ast-utils.js +++ b/tests/lib/rules/utils/ast-utils.js @@ -204,10 +204,7 @@ describe("ast-utils", () => { "// lalala I'm a normal comment", "// trying to confuse eslint ", "//trying to confuse eslint-directive-detection", - "//eslint is awesome", - "//global line comment is not a directive", - "//globals line comment is not a directive", - "//exported line comment is not a directive" + "//eslint is awesome" ].join("\n"); const ast = espree.parse(code, ESPREE_CONFIG); const sourceCode = new SourceCode(code, ast); @@ -250,10 +247,7 @@ describe("ast-utils", () => { "/*eslint-enable no-undef*/", "/* eslint-env {\"es6\": true} */", "/* eslint foo */", - "/*eslint bar*/", - "/*global foo*/", - "/*globals foo*/", - "/*exported foo*/" + "/*eslint bar*/" ].join("\n"); const ast = espree.parse(code, ESPREE_CONFIG); const sourceCode = new SourceCode(code, ast);