Skip to content

Commit

Permalink
Give variable name to matched text
Browse files Browse the repository at this point in the history
This simply makes the code a bit easier to read by giving a name to `match[1]`.
  • Loading branch information
captbaritone committed Oct 4, 2019
1 parent c47fa0d commit 8a37587
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,11 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
if (!match) {
return;
}
const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(match[1]);
const directiveText = match[1];
const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(directiveText);

if (warnInlineConfig && (lineCommentSupported || comment.type === "Block")) {
const kind = comment.type === "Block" ? `/*${match[1]}*/` : `//${match[1]}`;
const kind = comment.type === "Block" ? `/*${directiveText}*/` : `//${directiveText}`;

problems.push(createLintingProblem({
ruleId: null,
Expand All @@ -306,14 +307,14 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
return;
}

const directiveValue = trimmedCommentText.slice(match.index + match[1].length);
const directiveValue = trimmedCommentText.slice(match.index + directiveText.length);
let directiveType = "";

if (lineCommentSupported) {
if (comment.loc.start.line === comment.loc.end.line) {
directiveType = match[1].slice("eslint-".length);
directiveType = directiveText.slice("eslint-".length);
} else {
const message = `${match[1]} comment should not span multiple lines.`;
const message = `${directiveText} comment should not span multiple lines.`;

problems.push(createLintingProblem({
ruleId: null,
Expand All @@ -322,7 +323,7 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
}));
}
} else if (comment.type === "Block") {
switch (match[1]) {
switch (directiveText) {
case "exported":
Object.assign(exportedVariables, commentParser.parseStringConfig(directiveValue, comment));
break;
Expand Down

0 comments on commit 8a37587

Please sign in to comment.