Skip to content

Commit 95a288b

Browse files
authored
expiring-todo-comments: Add ignoreDates option (#2892)
1 parent 43630c4 commit 95a288b

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

docs/rules/expiring-todo-comments.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,26 @@ Imagine you maintain a `main` branch at a version such as 10 and always keep wor
234234

235235
## Options
236236

237+
### ignoreDates
238+
239+
Type: `boolean`\
240+
Default: `false`
241+
242+
Disables expired `Expiry Date` diagnostics.
243+
244+
This option does not disable date argument validation. For example, TODO comments with multiple dates are still reported as invalid.
245+
246+
This is useful when your CI system runs on pull request branches but cannot reliably expose pull request context to tooling, like some `push`-only GitHub Actions workflows.
247+
248+
```js
249+
"unicorn/expiring-todo-comments": [
250+
"error",
251+
{
252+
"ignoreDates": true
253+
}
254+
]
255+
```
256+
237257
### ignoreDatesOnPullRequests
238258

239259
Type: `boolean`\

rules/expiring-todo-comments.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ function semverComparisonForOperator(operator) {
266266
const DEFAULT_OPTIONS = {
267267
terms: ['todo', 'fixme', 'xxx'],
268268
ignore: [],
269+
ignoreDates: false,
269270
ignoreDatesOnPullRequests: true,
270271
allowWarningComments: true,
271272
};
@@ -357,7 +358,7 @@ const create = context => {
357358
uses++;
358359
const [expirationDate] = dates;
359360

360-
const shouldIgnore = options.ignoreDatesOnPullRequests && ci.isPR;
361+
const shouldIgnore = options.ignoreDates || (options.ignoreDatesOnPullRequests && ci.isPR);
361362
if (!shouldIgnore && reachedDate(expirationDate, options.date)) {
362363
context.report({
363364
loc: sourceCode.getLoc(comment),
@@ -552,6 +553,9 @@ const schema = [
552553
type: 'array',
553554
uniqueItems: true,
554555
},
556+
ignoreDates: {
557+
type: 'boolean',
558+
},
555559
ignoreDatesOnPullRequests: {
556560
type: 'boolean',
557561
},

test/expiring-todo-comments.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ test({
109109
code: '// TODO [2001-01-01]: quite old',
110110
options: [{date: '2000-01-01'}],
111111
},
112+
{
113+
code: '// TODO [2000-01-01]: too old but ignored in all environments',
114+
options: [{ignoreDates: true, ignoreDatesOnPullRequests: false}],
115+
},
112116
{
113117
code: `// eslint-disable-next-line rule-to-test/expiring-todo-comments
114118
// TODO without a date`,
@@ -203,6 +207,11 @@ test({
203207
code: '// TODO [2200-12-12, 2200-12-12]: Multiple dates',
204208
errors: [avoidMultipleDatesError('2200-12-12, 2200-12-12', 'Multiple dates')],
205209
},
210+
{
211+
code: '// TODO [2200-12-12, 2200-12-12]: Multiple dates are still invalid',
212+
errors: [avoidMultipleDatesError('2200-12-12, 2200-12-12', 'Multiple dates are still invalid')],
213+
options: [{ignoreDates: true}],
214+
},
206215
{
207216
code: '// TODO [>1]: if your package.json version is >1',
208217
errors: [reachedPackageVersionError('>1', 'if your package.json version is >1')],

0 commit comments

Comments
 (0)