Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

amareshsm
Copy link
Member

@amareshsm amareshsm commented Jul 4, 2022

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?

@eslint-github-bot eslint-github-bot bot added triage An ESLint team member will look at this issue soon feature This change adds a new feature to ESLint labels Jul 4, 2022
@netlify
Copy link

netlify bot commented Jul 4, 2022

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit f0638f4
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/62f6d45ea62f0100094114c7

@mdjermanovic mdjermanovic added rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Jul 5, 2022
Copy link
Member

@mdjermanovic mdjermanovic left a 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

lib/rules/no-empty.js Outdated Show resolved Hide resolved
lib/rules/no-empty.js Show resolved Hide resolved
@mdjermanovic
Copy link
Member

@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];
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can move.

Comment on lines +103 to +111
suggest: [
{
messageId: "suggestComment",
data: { type: "switch" },
fix(fixer) {
return fixer.replaceTextRange(range, " /* empty */ ");
}
}
]
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update.

@mdjermanovic
Copy link
Member

@amareshsm are you still working on this?

@snitin315
Copy link
Contributor

I'll finish this.

@snitin315
Copy link
Contributor

Closing in favor of #16470

@snitin315 snitin315 closed this Oct 30, 2022
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Apr 29, 2023
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule Change: no-empty suggest to add comments inside empty blocks
3 participants