no-lonely-if: --fix deletes intervening comments
See original GitHub issueUsing eslint --fix
with the unicorn/no-lonely-if
rule can result in comments being unexpectedly deleted.
if (
foo
// comment one
) {
// comment two
if (
// comment three
bar
// comment four
) {
baz();
}
}
is fixed to
if (
foo && bar
// comment one
) {
baz();
}
I would expect something more like
if (
foo &&
// comment one
// comment two
// comment three
bar
// comment four
) {
baz();
}
Configuration:
{
"plugins": ["unicorn"],
"rules": {
"unicorn/no-lonely-if": "error"
}
}
Versions: eslint@7.16.0
, eslint-plugin-unicorn@24.0.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
no-lonely-if - Pluggable JavaScript Linter - ESLint
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >disallow if statements as the only statement in else blocks (no ...
This rule disallows if statements as the only statement in else blocks. Examples of incorrect code for this rule: /*eslint no-lonely-if: "error"*/ ...
Read more >Loneliness and social isolation interventions for older adults
The aim of this scoping review was to describe the range of interventions to reduce loneliness and social isolation among older adults that...
Read more >Eleanor Oliphant Is Completely Fine Quotes by Gail Honeyman
619 quotes from Eleanor Oliphant Is Completely Fine: 'If someone asks you how you are, you are meant to say FINE. You are...
Read more >Your social ties, your personal public sphere, your responsibility ...
User intervention against incivility is a significant element of democratic norm enforcement on ... I would simply delete the comment and forget the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is by design, it’s tested https://github.com/sindresorhus/eslint-plugin-unicorn/blob/582ca342b4f2587bb83eddf686a959d1ae940994/test/no-lonely-if.js#L93-L113, but you can improve it if you like.
I’m not against to make the fix more safe, but if we are doing this, we need apply the strategy to all rules.