Prevent confusing if-statement usage with padding-line-between-statements
See original GitHub issueWhat 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:
- Created 4 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
Top GitHub Comments
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.
@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.