Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: update astUtils.isDirectiveComment with globals and `exporte…
…d` (#15775)
  • Loading branch information
mdjermanovic committed Apr 14, 2022
1 parent 3bca59e commit 413f1d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
9 changes: 3 additions & 6 deletions lib/rules/utils/ast-utils.js
Expand Up @@ -32,6 +32,7 @@ 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
Expand Down Expand Up @@ -908,12 +909,8 @@ module.exports = {
const comment = node.value.trim();

return (
node.type === "Line" && comment.indexOf("eslint-") === 0 ||
node.type === "Block" && (
comment.indexOf("global ") === 0 ||
comment.indexOf("eslint ") === 0 ||
comment.indexOf("eslint-") === 0
)
node.type === "Line" && comment.startsWith("eslint-") ||
node.type === "Block" && ESLINT_DIRECTIVE_PATTERN.test(comment)
);
},

Expand Down
3 changes: 3 additions & 0 deletions tests/lib/rules/no-inline-comments.js
Expand Up @@ -39,6 +39,9 @@ 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 = (
Expand Down
10 changes: 8 additions & 2 deletions tests/lib/rules/utils/ast-utils.js
Expand Up @@ -204,7 +204,10 @@ describe("ast-utils", () => {
"// lalala I'm a normal comment",
"// trying to confuse eslint ",
"//trying to confuse eslint-directive-detection",
"//eslint is awesome"
"//eslint is awesome",
"//global line comment is not a directive",
"//globals line comment is not a directive",
"//exported line comment is not a directive"
].join("\n");
const ast = espree.parse(code, ESPREE_CONFIG);
const sourceCode = new SourceCode(code, ast);
Expand Down Expand Up @@ -247,7 +250,10 @@ describe("ast-utils", () => {
"/*eslint-enable no-undef*/",
"/* eslint-env {\"es6\": true} */",
"/* eslint foo */",
"/*eslint bar*/"
"/*eslint bar*/",
"/*global foo*/",
"/*globals foo*/",
"/*exported foo*/"
].join("\n");
const ast = espree.parse(code, ESPREE_CONFIG);
const sourceCode = new SourceCode(code, ast);
Expand Down

0 comments on commit 413f1d5

Please sign in to comment.