question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-lonely-if: --fix deletes intervening comments

See original GitHub issue

Using 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fiskercommented, Dec 22, 2020
0reactions
fiskercommented, Dec 23, 2020

I’m not against to make the fix more safe, but if we are doing this, we need apply the strategy to all rules.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found