Skip to content

Commit 8090bcb

Browse files
expiring-todo-comments: should not flag eslint disable comments
1 parent 8deb085 commit 8090bcb

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

rules/expiring-todo-comments.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ const create = context => {
284284

285285
const {sourceCode} = context;
286286
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+
287294
const unusedComments = comments
288295
.filter(token => token.type !== 'Shebang')
289296
// Block comments come as one.
@@ -319,6 +326,10 @@ const create = context => {
319326

320327
// eslint-disable-next-line complexity
321328
function processComment(comment) {
329+
if (isEslintDirectiveComment(comment)) {
330+
return;
331+
}
332+
322333
if (ignoreRegexes.some(ignore => ignore.test(comment.value))) {
323334
return;
324335
}

test/expiring-todo-comments.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ test({
114114
code: '// TODO [2001-01-01]: quite old',
115115
options: [{date: '2000-01-01'}],
116116
},
117+
{
118+
code: `// eslint-disable-next-line rule-to-test/expiring-todo-comments
119+
// TODO without a date`,
120+
options: [{allowWarningComments: false}],
121+
},
122+
{
123+
code: `/* eslint-disable rule-to-test/expiring-todo-comments */
124+
// TODO without a date
125+
// fixme [2000-01-01]: too old'
126+
/* eslint-enable rule-to-test/expiring-todo-comments */`,
127+
options: [{allowWarningComments: false}],
128+
},
117129
],
118130
invalid: [
119131
{

0 commit comments

Comments
 (0)