Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update astUtils.isDirectiveComment with globals and exported #15775

Merged
merged 1 commit into from Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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