Skip to content

unnecessary_nesting_linter() can catch else { if () } where the braces could be dropped #2317

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

Closed
MichaelChirico opened this issue Nov 19, 2023 · 4 comments · Fixed by #2462
Closed
Labels
false-negative code that should lint, but doesn't
Milestone

Comments

@MichaelChirico
Copy link
Collaborator

if (x == 'a') 1 else { if (x == 'b') 2 else 3 }

else { is not considered by the current logic.

@MichaelChirico MichaelChirico added the false-negative code that should lint, but doesn't label Nov 19, 2023
@AshesITR
Copy link
Collaborator

Maybe instead add a linter that lints else { if () ... } if there are no expressions after the if expr-block?
Might fit into brace_linter()"do not put { between else and if if the if branch is the only statement in the else block." or something more readable with the same intent...

@MichaelChirico
Copy link
Collaborator Author

could also appropriate for unnecessary_nested_if_linter(), or unnecessary_nesting_linter()?

(we might want to merge those two both as unnecessary_nesting_linter?)

@MichaelChirico MichaelChirico added this to the 3.2.0 milestone Dec 5, 2023
@MichaelChirico
Copy link
Collaborator Author

@IndrajeetPatil WDYT about subsuming unnecessary_nested_if_linter() into unnecessary_nesting_linter()?

@IndrajeetPatil
Copy link
Collaborator

That's a great idea!

@MichaelChirico MichaelChirico changed the title Extend if_switch_linter() for cases with braces unnecessary_nesting_linter() can catch else { if () } where the braces could be dropped Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-negative code that should lint, but doesn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants