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
feat: suggest to add comments inside empty blocks #16096
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
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.
Can you add suggestions
property to errors in "invalid" test cases, to test this change?
Example: https://github.com/eslint/eslint/blob/main/tests/lib/rules/no-useless-escape.js
24c281d
to
f0638f4
Compare
@amareshsm PR is still missing the tests update (#16096 (review)) |
@@ -51,6 +53,7 @@ module.exports = { | |||
|
|||
return { | |||
BlockStatement(node) { | |||
const range = [node.range[0] + 1, node.range[1] - 1]; |
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.
Can we move this into fix(fixer)
, since it's needed only for the fix, and at this point it isn't clear what the range
represents.
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.
yes, we can move.
suggest: [ | ||
{ | ||
messageId: "suggestComment", | ||
data: { type: "switch" }, | ||
fix(fixer) { | ||
return fixer.replaceTextRange(range, " /* empty */ "); | ||
} | ||
} | ||
] |
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.
The implementation is correct, but adding a comment inside an empty SwitchStatement doesn't really help, because it's still considered an error by this rule (playground link) so it seems we should provide these suggestions only for BlockStatement nodes.
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.
In other words, this rule shouldn't provide suggestion to add a comment inside an empty switch statement, because that won't fix the lint problem reported by this rule.
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 will update.
@amareshsm are you still working on this? |
I'll finish this. |
Closing in favor of #16470 |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add auto fix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Suggest adding comments inside empty block statements.
Fixes #15899
Is there anything you'd like reviewers to focus on?