Skip to content

Commit af4473a

Browse files
committed
refactor(eslint): move reg to param
1 parent 818bc25 commit af4473a

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎packages/eslint/lib/plugins/disableNextLine.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ interface CommentState {
66
end: number;
77
}
88

9-
const reg = new RegExp(/\/\/\s*eslint-disable-next-line\b[ \t]*(\S*)\b/g);
10-
11-
export function create(reportsUnusedComments = true): Plugin {
9+
export function create(
10+
reportsUnusedComments = true,
11+
reg = new RegExp(/\/\/\s*eslint-disable-next-line\b[ \t]*(?<ruleId>\S*)\b/g)
12+
): Plugin {
1213
return ({ languageService }) => ({
1314
resolveDiagnostics(fileName, results) {
1415
if (
@@ -21,14 +22,13 @@ export function create(reportsUnusedComments = true): Plugin {
2122
const disabledLines = new Map<number, CommentState>();
2223
const disabledLinesByRules = new Map<string, Map<number, CommentState>>();
2324
for (const comment of sourceFile.text.matchAll(reg)) {
24-
const line =
25-
sourceFile.getLineAndCharacterOfPosition(comment.index).line + 1;
26-
const rule = comment[1];
27-
if (rule) {
28-
if (!disabledLinesByRules.has(rule)) {
29-
disabledLinesByRules.set(rule, new Map());
25+
const line = sourceFile.getLineAndCharacterOfPosition(comment.index).line + 1;
26+
const ruleId = comment.groups?.ruleId;
27+
if (ruleId) {
28+
if (!disabledLinesByRules.has(ruleId)) {
29+
disabledLinesByRules.set(ruleId, new Map());
3030
}
31-
disabledLinesByRules.get(rule)!.set(line, {
31+
disabledLinesByRules.get(ruleId)!.set(line, {
3232
start: comment.index,
3333
end: comment.index + comment[0].length,
3434
});

0 commit comments

Comments
 (0)