Skip to content
11 changes: 11 additions & 0 deletions rules/expiring-todo-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ const create = context => {

const {sourceCode} = context;
const comments = sourceCode.getAllComments();

const isEslintDirectiveComment = comment => {
// Strip leading whitespace and optional `*` from block comments
const normalizedComment = comment.value.trimStart().replace(/^\*\s*/, '');
return /^eslint(?:-(?:en|dis)able)?(?:-(?:next-)?line)?\b/.test(normalizedComment);
};

const unusedComments = comments
.filter(token => token.type !== 'Shebang')
// Block comments come as one.
Expand Down Expand Up @@ -319,6 +326,10 @@ const create = context => {

// eslint-disable-next-line complexity
function processComment(comment) {
if (isEslintDirectiveComment(comment)) {
return;
}

if (ignoreRegexes.some(ignore => ignore.test(comment.value))) {
return;
}
Expand Down
12 changes: 12 additions & 0 deletions test/expiring-todo-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ test({
code: '// TODO [2001-01-01]: quite old',
options: [{date: '2000-01-01'}],
},
{
code: `// eslint-disable-next-line rule-to-test/expiring-todo-comments
// TODO without a date`,
options: [{allowWarningComments: false}],
},
{
code: `/* eslint-disable rule-to-test/expiring-todo-comments */
// TODO without a date
// fixme [2000-01-01]: too old'
/* eslint-enable rule-to-test/expiring-todo-comments */`,
options: [{allowWarningComments: false}],
},
],
invalid: [
{
Expand Down
Loading