Skip to content
10 changes: 10 additions & 0 deletions rules/expiring-todo-comments.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {ConfigCommentParser} from '@eslint/plugin-kit';
import path from 'node:path';
import {isRegExp} from 'node:util/types';
import semver from 'semver';
Expand Down Expand Up @@ -267,6 +268,8 @@ const DEFAULT_OPTIONS = {
allowWarningComments: true,
};

let configCommentParser;

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const options = {
Expand Down Expand Up @@ -319,6 +322,13 @@ const create = context => {

// eslint-disable-next-line complexity
function processComment(comment) {
configCommentParser ??= new ConfigCommentParser();

const directive = configCommentParser.parseDirective(comment.value);
if (directive?.label?.startsWith('eslint')) {
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