Skip to content

Commit d0df7af

Browse files
expiring-todo-comments: use ConfigCommentParser to test for eslint directives
1 parent 8090bcb commit d0df7af

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

rules/expiring-todo-comments.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {ConfigCommentParser} from '@eslint/plugin-kit';
12
import path from 'node:path';
23
import {isRegExp} from 'node:util/types';
34
import semver from 'semver';
@@ -267,6 +268,8 @@ const DEFAULT_OPTIONS = {
267268
allowWarningComments: true,
268269
};
269270

271+
let configCommentParser;
272+
270273
/** @param {import('eslint').Rule.RuleContext} context */
271274
const create = context => {
272275
const options = {
@@ -284,13 +287,6 @@ const create = context => {
284287

285288
const {sourceCode} = context;
286289
const comments = sourceCode.getAllComments();
287-
288-
const isEslintDirectiveComment = comment => {
289-
// Strip leading whitespace and optional `*` from block comments
290-
const normalizedComment = comment.value.trimStart().replace(/^\*\s*/, '');
291-
return /^eslint(?:-(?:en|dis)able)?(?:-(?:next-)?line)?\b/.test(normalizedComment);
292-
};
293-
294290
const unusedComments = comments
295291
.filter(token => token.type !== 'Shebang')
296292
// Block comments come as one.
@@ -326,7 +322,10 @@ const create = context => {
326322

327323
// eslint-disable-next-line complexity
328324
function processComment(comment) {
329-
if (isEslintDirectiveComment(comment)) {
325+
configCommentParser ??= new ConfigCommentParser();
326+
327+
const directive = configCommentParser.parseDirective(comment.value);
328+
if (directive?.label?.startsWith('eslint')) {
330329
return;
331330
}
332331

0 commit comments

Comments
 (0)