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.

Prevent confusing if-statement usage with padding-line-between-statements

See original GitHub issue

What rule do you want to change?

padding-line-between-statements

Does this change cause the rule to produce more or fewer warnings?

Depends on the selected option.

How will the change be implemented? (New option, new default behavior, etc.)?

New option.

Please provide some example code that this change will affect:

if (condition) {
  // stuff
} if (anotherUnrelatedCondition) {
  // more
} 

What does the rule currently do for this code?

With the following setting, the rule enforces a blank line between two if statements.

    "padding-line-between-statements": [
      "error",
      { "blankLine": "always", "prev": "if", "next": "if" }
    ]

Invalid:

if (condition) {
  // stuff
} if (anotherUnrelatedCondition) {
  // more
}

Also Invalid:

if (condition) {
  // stuff
}
if (anotherUnrelatedCondition) {
  // more
}

Correct:

if (condition) {
  // stuff
}

if (anotherUnrelatedCondition) {
  // more
}

What will the rule do after it’s changed?

Provide a way to also allow the following:

if (condition) {
  // stuff
}
if (anotherUnrelatedCondition) {
  // more
}

In other words, I only want to disallow the following confusing code:

if (condition) {
  // stuff
} if (anotherUnrelatedCondition) {
  // more
}

I might have misunderstood how to use padding-line-between-statements, but I don’t believe this issue ( https://github.com/eslint/eslint/issues/7116) is addressed by this rule as @not-an-aardvark’s comment here implied: https://github.com/eslint/eslint/issues/7116#issuecomment-341823385 If I’m just using the rule incorrectly, apologies. But I was not able to configure it so as to solve this standard issue: https://github.com/standard/eslint-config-standard/issues/120

Thanks for being awesome ❤️

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Jul 28, 2019

Definitely open to other options, but I think (setting aside the pain from deprecation of a rule) it might be better to deprecate and rename the rule to “newlines-between-statements” and allow the rule to require no line break, line break with no padding, or line break with padding (possibly with support for multiple blank lines as suggested in another issue?).

Naturally, further discussion would require an RFC, which I don’t have time to write at the moment.

0reactions
platinumazurecommented, Sep 6, 2019

@feross I can’t guarantee it, but if the RFC has enough level of detail and is responsive to feedback, I think it has a pretty good chance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

padding-line-between-statements - Pluggable JavaScript Linter
This rule requires or disallows blank lines between the given 2 kinds of statements. Properly blank lines help developers to understand the code....
Read more >
Eslint rule "padding-line-between-statements" not working as ...
The padding-line-between-statements rule works adding a padding line between two statements. As there is no statement after the return it ...
Read more >
padding-line-between-statements | typescript-eslint
Require or disallow padding lines between statements. Some problems reported by this rule are automatically fixable by the --fix ESLint command line option....
Read more >
padding-line-between-statements - Rules - ESLint
This rule requires or disallows blank lines between the given 2 kinds of statements. Properly blank lines help developers to understand the code....
Read more >
Statement vs Expression – What's the Difference in ...
Learning the syntax of a programming language is key if you want to ... It can sometimes be confusing to differentiate between statements...
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