Skip to content

Commit 5f409ff

Browse files
lubiensindresorhus
andcommitted
Set allowWarningComments for expiring-todo-comments default value to true (#400)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent c3326d2 commit 5f409ff

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

docs/rules/expiring-todo-comments.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TODO comments are useful when a piece of code needs some work. Unfortunately the
1010

1111
With this rule, a TODO can have a condition right from the beginning to define its lifespan. When the condition is met, ESLint will take care of reporting that there's work to be done.
1212

13-
This rule also defines by default that **there must be no TODO comment without conditions** so that you should take more care before simply adding tasks with no life expectancy. For more information read the section [`eslint/no-warning-comments`](#disallow-warning-comments-no-warning-comments) below. To disable this behavior see [`allowWarningComments`](#allowWarningComments) below.
13+
This rule will ignore all TODOs without conditions. For more information, read the below [`eslint/no-warning-comments`](#disallow-warning-comments-no-warning-comments) section.
1414

1515
Quick overview of conditions:
1616

@@ -133,13 +133,13 @@ You can also use block comments to specify TODOs with conditions. Each line can
133133

134134
This rule implements [`eslint/no-warning-comments`](https://eslint.org/docs/rules/no-warning-comments).
135135

136-
The sole difference is that first we check for **valid conditions** to apply this rule. If no valid conditions are met, we fall back to `eslint/no-warning-comments`, and you'll see something like `Unexpected 'todo' comment.`
136+
The sole difference is that first we check for **valid conditions** to apply this rule. If no valid conditions are met, we fall back to `eslint/no-warning-comments` if [`allowWarningComments`](#allowWarningComments) is set to `false` (default `true`) and you'll see something like `Unexpected 'todo' comment.`
137137

138138
The reason behind this is that now that you have a powerful rule to make sure there are no stray TODOs on your code, you should strive for best pratices. Don't just add TODO comments and leave them forever. Define conditions to justify the presence of warning comments.
139139

140-
With that in mind, **you should disable** that ESLint rule in favor of this one as you will get its same behavior and more.
140+
With that in mind, you **could** disable that ESLint rule in favor of this one as you will get its same behavior and more.
141141

142-
You can also opt for `allowWarningComments` on this rule and have both rules coexist (See [`allowWarningComments`](#allowWarningComments) below).
142+
Since by default the option `allowWarningComments` is `true`, both rules can coexist even with different reporting levels. For example, one might want to error when conditions are met, but just warn on TODOs without conditions (See [`allowWarningComments`](#allowWarningComments) below).
143143

144144
## Legacy Branches
145145

@@ -268,13 +268,15 @@ If you just want to add a verb, make sure to explicitly include the default ones
268268
### allowWarningComments
269269

270270
Type: `boolean`<br>
271-
Default: `false`
271+
Default: `true`
272272

273273
Ignore TODOs without conditions.
274274

275-
As mentioned before, the [`eslint/no-warning-comments` rule](#disallow-warning-comments-no-warning-comments) will be triggered when there are no valid conditions on a TODO comment. If you want only triggering TODO conditions to be reported, you can disable this fallback rule with this option.
275+
As mentioned before, the [`eslint/no-warning-comments` rule](#disallow-warning-comments-no-warning-comments) will be triggered when there are no valid conditions on a TODO comment.
276+
277+
This is helpful if you want to use **both** this rule and the [`eslint/no-warning-comments` rule](#disallow-warning-comments-no-warning-comments), **but want different warning levels**, as it's not possible to set multiple warning levels on the same rule.
276278

277-
This is also helpful if you want to use **both** this rule and the [`eslint/no-warning-comments` rule](#disallow-warning-comments-no-warning-comments), **but want different warning levels** as it's not possible to set multiple warning levels on the same rule.
279+
If you want this rule to trigger on stray TODO conditions, you can enable this fallback rule with this option.
278280

279281
```js
280282
"unicorn/expiring-todo-comments": [

rules/expiring-todo-comments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const create = context => {
177177
const options = {
178178
terms: ['todo', 'fixme', 'xxx'],
179179
ignoreDatesOnPullRequests: true,
180-
allowWarningComments: false,
180+
allowWarningComments: true,
181181
...context.options[0]
182182
};
183183

test/expiring-todo-comments.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,18 @@ ruleTester.run('expiring-todo-comments', rule, {
9494
*/`,
9595
{
9696
code: '// TODO',
97-
options: [{allowWarningComments: true}],
9897
errors: []
9998
},
10099
{
101100
code: '// TODO [invalid]',
102-
options: [{allowWarningComments: true}],
103101
errors: []
104102
},
105103
{
106104
code: '// TODO [] might have [some] that [try [to trick] me]',
107-
options: [{allowWarningComments: true}],
108105
errors: []
109106
},
110107
{
111108
code: '// TODO [but [it will]] [fallback] [[[ to the default ]]] rule [[',
112-
options: [{allowWarningComments: true}],
113109
errors: []
114110
}
115111
],
@@ -261,31 +257,38 @@ ruleTester.run('expiring-todo-comments', rule, {
261257
},
262258
{
263259
code: '// TODO',
264-
errors: [noWarningCommentError()]
260+
errors: [noWarningCommentError()],
261+
options: [{allowWarningComments: false}]
265262
},
266263
{
267264
code: '// TODO []',
268-
errors: [noWarningCommentError()]
265+
errors: [noWarningCommentError()],
266+
options: [{allowWarningComments: false}]
269267
},
270268
{
271269
code: '// TODO [no meaning at all]',
272-
errors: [noWarningCommentError()]
270+
errors: [noWarningCommentError()],
271+
options: [{allowWarningComments: false}]
273272
},
274273
{
275274
code: '// TODO [] might have [some] that [try [to trick] me]',
276-
errors: [noWarningCommentError()]
275+
errors: [noWarningCommentError()],
276+
options: [{allowWarningComments: false}]
277277
},
278278
{
279279
code: '// TODO [but [it will]] [fallback] [[[ to the default ]]] rule [[[',
280-
errors: [noWarningCommentError()]
280+
errors: [noWarningCommentError()],
281+
options: [{allowWarningComments: false}]
281282
},
282283
{
283284
code: '// TODO [engine:npm@>=10000]: Unsupported engine',
284-
errors: [noWarningCommentError()]
285+
errors: [noWarningCommentError()],
286+
options: [{allowWarningComments: false}]
285287
},
286288
{
287289
code: '// TODO [engine:somethingrandom@>=10000]: Unsupported engine',
288-
errors: [noWarningCommentError()]
290+
errors: [noWarningCommentError()],
291+
options: [{allowWarningComments: false}]
289292
},
290293
{
291294
code: '// TODO [2000-01-01, >1]: Combine date with package version',

0 commit comments

Comments
 (0)