Skip to content

Commit

Permalink
Set allowWarningComments for expiring-todo-comments default value…
Browse files Browse the repository at this point in the history
… to `true` (#400)

Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
lubien and sindresorhus committed Oct 3, 2019
1 parent c3326d2 commit 5f409ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
16 changes: 9 additions & 7 deletions docs/rules/expiring-todo-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TODO comments are useful when a piece of code needs some work. Unfortunately the

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.

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.
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.

Quick overview of conditions:

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

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

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.`
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.`

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.

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

You can also opt for `allowWarningComments` on this rule and have both rules coexist (See [`allowWarningComments`](#allowWarningComments) below).
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).

## Legacy Branches

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

Type: `boolean`<br>
Default: `false`
Default: `true`

Ignore TODOs without conditions.

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.
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.

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.

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.
If you want this rule to trigger on stray TODO conditions, you can enable this fallback rule with this option.

```js
"unicorn/expiring-todo-comments": [
Expand Down
2 changes: 1 addition & 1 deletion rules/expiring-todo-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const create = context => {
const options = {
terms: ['todo', 'fixme', 'xxx'],
ignoreDatesOnPullRequests: true,
allowWarningComments: false,
allowWarningComments: true,
...context.options[0]
};

Expand Down
25 changes: 14 additions & 11 deletions test/expiring-todo-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,18 @@ ruleTester.run('expiring-todo-comments', rule, {
*/`,
{
code: '// TODO',
options: [{allowWarningComments: true}],
errors: []
},
{
code: '// TODO [invalid]',
options: [{allowWarningComments: true}],
errors: []
},
{
code: '// TODO [] might have [some] that [try [to trick] me]',
options: [{allowWarningComments: true}],
errors: []
},
{
code: '// TODO [but [it will]] [fallback] [[[ to the default ]]] rule [[',
options: [{allowWarningComments: true}],
errors: []
}
],
Expand Down Expand Up @@ -261,31 +257,38 @@ ruleTester.run('expiring-todo-comments', rule, {
},
{
code: '// TODO',
errors: [noWarningCommentError()]
errors: [noWarningCommentError()],
options: [{allowWarningComments: false}]
},
{
code: '// TODO []',
errors: [noWarningCommentError()]
errors: [noWarningCommentError()],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [no meaning at all]',
errors: [noWarningCommentError()]
errors: [noWarningCommentError()],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [] might have [some] that [try [to trick] me]',
errors: [noWarningCommentError()]
errors: [noWarningCommentError()],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [but [it will]] [fallback] [[[ to the default ]]] rule [[[',
errors: [noWarningCommentError()]
errors: [noWarningCommentError()],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [engine:npm@>=10000]: Unsupported engine',
errors: [noWarningCommentError()]
errors: [noWarningCommentError()],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [engine:somethingrandom@>=10000]: Unsupported engine',
errors: [noWarningCommentError()]
errors: [noWarningCommentError()],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [2000-01-01, >1]: Combine date with package version',
Expand Down

0 comments on commit 5f409ff

Please sign in to comment.