-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update: Fixes multiline no-warning-comments rule. (fixes #9884) #10381
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sstern6, thanks for contributing!
Apologies, I've only now had a chance to look at the rule docs fully and I think I led you astray.
There's a location
option in the rule, which can be "start" or "anywhere" (defaults to "start"). I think we only want to make changes for { location: "anywhere" }
at this point. (For { location: "start" }
, the only change we would want to make is to allow some extra non-word characters at the start of the comment before identifying the real "starting word" of the comment, but that can/should be done in a separate PR.)
It might be worth stepping through the code with { location: "anywhere" }
to see how that code works and what alternate paths it takes. Does it generate a different regex? etc.
I've left comments on the test cases that I think need to be changed. Let me know if anything doesn't make sense. Sorry for the confusion I accidentally led you into. Thanks!
lib/rules/no-warning-comments.js
Outdated
} else { | ||
prefix = ""; | ||
} | ||
|
||
return new RegExp(prefix + escaped + suffix, "i"); | ||
return new RegExp(prefix + escaped + suffix + eitherOrWordBoundary + term + wordBoundary, "i"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be really helpful to have a comment here showing what the regex should look like for an example term.
Also: Based on the issues I've identified in the tests, we want to make sure that this regex is only augmented when { location: "anywhere" }
option is specified.
@@ -24,15 +24,10 @@ ruleTester.run("no-warning-comments", rule, { | |||
{ code: "// any comment", options: [{ terms: ["fixme", "todo"] }] }, | |||
"// any comment", | |||
{ code: "// any comment", options: [{ location: "anywhere" }] }, | |||
{ code: "// any comment with TODO, FIXME or XXX", options: [{ location: "start" }] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should still be valid: the rule option { location: "start" }
means only flag the comment if it starts with TODO/FIXME/XXX.
@@ -24,15 +24,10 @@ ruleTester.run("no-warning-comments", rule, { | |||
{ code: "// any comment", options: [{ terms: ["fixme", "todo"] }] }, | |||
"// any comment", | |||
{ code: "// any comment", options: [{ location: "anywhere" }] }, | |||
{ code: "// any comment with TODO, FIXME or XXX", options: [{ location: "start" }] }, | |||
"// any comment with TODO, FIXME or XXX", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be valid as well: { location: "start" }
appears to be the rule default. This should only be flagged if the { location: "anywhere" }
option is explicitly specified.
{ code: "/* any block comment */", options: [{ terms: ["fixme"] }] }, | ||
{ code: "/* any block comment */", options: [{ terms: ["fixme", "todo"] }] }, | ||
"/* any block comment */", | ||
{ code: "/* any block comment */", options: [{ location: "anywhere" }] }, | ||
{ code: "/* any block comment with TODO, FIXME or XXX */", options: [{ location: "start" }] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be valid since the term is not at the start of the comment.
{ code: "/* any block comment */", options: [{ terms: ["fixme"] }] }, | ||
{ code: "/* any block comment */", options: [{ terms: ["fixme", "todo"] }] }, | ||
"/* any block comment */", | ||
{ code: "/* any block comment */", options: [{ location: "anywhere" }] }, | ||
{ code: "/* any block comment with TODO, FIXME or XXX */", options: [{ location: "start" }] }, | ||
"/* any block comment with TODO, FIXME or XXX */", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be valid since the term is not at the start of the comment.
@@ -50,11 +45,15 @@ ruleTester.run("no-warning-comments", rule, { | |||
{ code: "// any fixme or todo", options: [{ terms: ["fixme", "todo"], location: "anywhere" }], errors: [{ message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'todo' comment." }] }, | |||
{ code: "/* any fixme or todo */", options: [{ terms: ["fixme", "todo"], location: "anywhere" }], errors: [{ message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'todo' comment." }] }, | |||
{ code: "/* any fixme or todo */", options: [{ location: "anywhere" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }] }, | |||
{ code: "/* fixme and todo */", errors: [{ message: "Unexpected 'fixme' comment." }] }, | |||
{ code: "/* fixme and todo */", errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only be invalid with 2 messages if { location: "anywhere" }
is specified as an option.
{ code: "/* any fixme */", options: [{ location: "anywhere" }], errors: [{ message: "Unexpected 'fixme' comment." }] }, | ||
{ code: "/* fixme! */", options: [{ terms: ["fixme"] }], errors: [{ message: "Unexpected 'fixme' comment." }] }, | ||
{ code: "// regex [litera|$]", options: [{ terms: ["[litera|$]"], location: "anywhere" }], errors: [{ message: "Unexpected '[litera|$]' comment." }] }, | ||
{ code: "/* eslint one-var: 2 */", options: [{ terms: ["eslint"] }], errors: [{ message: "Unexpected 'eslint' comment." }] }, | ||
{ code: "/* eslint one-var: 2 */", options: [{ terms: ["one"], location: "anywhere" }], errors: [{ message: "Unexpected 'one' comment." }] } | ||
{ code: "/* eslint one-var: 2 */", options: [{ terms: ["one"], location: "anywhere" }], errors: [{ message: "Unexpected 'one' comment." }] }, | ||
{ code: "/* any block comment with TODO, FIXME or XXX */", options: [{ location: "start" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only be invalid when { location: "anywhere" }
is specified.
{ code: "/* eslint one-var: 2 */", options: [{ terms: ["one"], location: "anywhere" }], errors: [{ message: "Unexpected 'one' comment." }] } | ||
{ code: "/* eslint one-var: 2 */", options: [{ terms: ["one"], location: "anywhere" }], errors: [{ message: "Unexpected 'one' comment." }] }, | ||
{ code: "/* any block comment with TODO, FIXME or XXX */", options: [{ location: "start" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, | ||
{ code: "/* any block comment with (TODO, FIXME's or XXX!) */", options: [{ location: "start" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only be invalid when { location: "anywhere" }
is specified.
{ code: "/* eslint one-var: 2 */", options: [{ terms: ["one"], location: "anywhere" }], errors: [{ message: "Unexpected 'one' comment." }] }, | ||
{ code: "/* any block comment with TODO, FIXME or XXX */", options: [{ location: "start" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, | ||
{ code: "/* any block comment with (TODO, FIXME's or XXX!) */", options: [{ location: "start" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, | ||
{ code: "/** \n *any block comment \n*with (TODO, FIXME's or XXX!) **/", options: [{ location: "start" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only be invalid when { location: "anywhere" }
is specified.
{ code: "/* any block comment with TODO, FIXME or XXX */", options: [{ location: "start" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, | ||
{ code: "/* any block comment with (TODO, FIXME's or XXX!) */", options: [{ location: "start" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, | ||
{ code: "/** \n *any block comment \n*with (TODO, FIXME's or XXX!) **/", options: [{ location: "start" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, | ||
{ code: "// any comment with TODO, FIXME or XXX", options: [{ location: "start" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only be invalid when { location: "anywhere" }
is specified.
Oh, forgot to mention: This should be an "Update" since this is a bugfix that potentially increases the number of warnings the user might experience. Please change the commit message accordingly. Thanks! |
Thanks for the feedback @platinumazure addressed all comments and split the logic between location Thanks |
Sorry for losing track of this. Marking this as accepted, since the corresponding issue is accepted. @sstern6 Do you mind updating the description to reference the issue? @platinumazure have your comments been addressed? |
Apologies @sstern6 and @kaicataldo, yes, my concerns are addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for contributing to ESLint!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I apologize, I missed one thing.
Since this fix will increase warnings, this needs to be prefixed with "Update:" instead of "Fix:". Once that is done, this is ready to go. Thanks and sorry for missing that!
Renaming this when we squash and merge to ensure this gets into today's RC release
Thanks for contributing to ESLint! |
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[x ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Updated the RegExp to look for the term provided in the body of the comment, not just the beginning.
Is there anything you'd like reviewers to focus on?
Please review new test cases add/moved from valid to invalid. The examples on the documentation were not throwing errors https://eslint.org/docs/2.0.0/rules/no-warning-comments as stated, ie:
Previous to the PR was not throwing any errors.
Only had 1 error not 2 errors:
Thank you
Fixes: #9884