Apparent discrepancy in the definition of a block between rules
See original GitHub issueEnvironment
Node version: 16.14.1 npm version: 8.5.0 Local ESLint version: 7.32.0 Global ESLint version: N/A Operating System: OS X
What parser are you using?
What did you do?
For the lines-around-comment
rule, setting allowBlockStart: true
is not respected for switch
statements.
According to this issue: https://github.com/eslint/eslint/issues/9653, that is because switch
statement curly braces are not considered “blocks”. See comment: https://github.com/eslint/eslint/issues/9653#issuecomment-347386313
However, the padded-blocks
rule appears to interpret switch
statement curly braces as blocks which results in a discrepancy that can only be remedied by never including a comment inside a switch
statement’s opening curly brace.
Relevant rule configurations:
'lines-around-comment': [
2,
{
allowArrayStart: true,
allowBlockStart: true,
allowObjectStart: true,
beforeBlockComment: true,
beforeLineComment: true,
},
],
'padded-blocks': ['error', 'never'],
Sample code
let someValue = "a";
switch (someValue) {
// some comment
case 'a':
someValue = "b";
break;
default:
someValue = "c";
}
What did you expect to happen?
I expected that setting allowBlockStart: true
would preclude a violation of beforeLineComment: true
in the lines-around-comment
rule.
Given the discussion in issue 9653, I would then expect 'padded-blocks': ['error', 'never']
to not result in an error inside a switch
statement’s opening curly brace.
What actually happened?
To visualize, visit the reproduction and add a line break before the comment. Note that the lines-around-comment
error becomes a padded-blocks
error because the two rules do not consistently interpret switch
case curly braces as blocks.
Participation
- I am willing to submit a pull request for this issue.
Additional comments
No response
Issue Analytics
- State:
- Created a year ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
@kboucher the next release is scheduled on 29th July.
I’ll prepare a fix for it.