-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apparent discrepancy in the definition of a block between rules #16131
Comments
Yeah, that definitely seems inconsistent. Unfortunately, these things happen when you have hundreds of rules to manage. It seems like the best way forward here would be to add the options suggested in #9653 (comment): allowSwitchStart and allowSwitchEnd. Let’s see what the rest of the team thinks. |
Totally not judging. 😁 I would just like to be able to add a comment before the first Looking forward to a possible solution. Thanks! |
/* eslint lines-around-comment: ["error", {
beforeLineComment: true,
afterLineComment: true,
allowBlockStart: true,
allowBlockEnd: true
}]*/
switch (foo) {
// this comment isn't allowed by allowBlockStart: true
case 1:
bar();
break;
// this comment is allowed by allowBlockEnd: true
} |
Oh wow, didn’t realize that. In that case, I agree it’s a bug and we should fix it so allowBlockStart also applies to switch statements. |
I'll prepare a fix for it. |
Thanks @snitin315 |
Thank you @snitin315! Any idea when this fix will be released? |
@kboucher the next release is scheduled on 29th July. |
Environment
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?
@babel/eslint-parser
What did you do?
For the
lines-around-comment
rule, settingallowBlockStart: true
is not respected forswitch
statements.According to this issue: #9653, that is because
switch
statement curly braces are not considered "blocks". See comment: #9653 (comment)However, the
padded-blocks
rule appears to interpretswitch
statement curly braces as blocks which results in a discrepancy that can only be remedied by never including a comment inside aswitch
statement's opening curly brace.Relevant rule configurations:
Sample code
Link to reproduction of issue:
https://eslint.org/play/#eyJ0ZXh0IjoibGV0IHNvbWVWYWx1ZSA9IFwiYVwiO1xuXG5zd2l0Y2ggKHNvbWVWYWx1ZSkge1xuICAgIC8vIHNvbWUgY29tbWVudFxuICBjYXNlICdhJzpcbiAgICBzb21lVmFsdWUgPSBcImJcIjtcbiAgICBicmVhaztcbiAgXG4gIGRlZmF1bHQ6XG4gICAgc29tZVZhbHVlID0gXCJjXCI7XG59Iiwib3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFWZXJzaW9uIjoibGF0ZXN0Iiwic291cmNlVHlwZSI6InNjcmlwdCIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6eyJsaW5lcy1hcm91bmQtY29tbWVudCI6WzIseyJhbGxvd0Jsb2NrU3RhcnQiOnRydWUsImJlZm9yZUxpbmVDb21tZW50Ijp0cnVlLCJiZWZvcmVCbG9ja0NvbW1lbnQiOnRydWUsImFmdGVyQmxvY2tDb21tZW50IjpmYWxzZSwiYWZ0ZXJMaW5lQ29tbWVudCI6ZmFsc2UsImFsbG93QmxvY2tFbmQiOmZhbHNlfV0sInBhZGRlZC1ibG9ja3MiOlsiZXJyb3IiLCJuZXZlciJdfSwiZW52Ijp7ImVzNiI6dHJ1ZX19fQ==
What did you expect to happen?
I expected that setting
allowBlockStart: true
would preclude a violation ofbeforeLineComment: true
in thelines-around-comment
rule.Given the discussion in issue 9653, I would then expect
'padded-blocks': ['error', 'never']
to not result in an error inside aswitch
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 apadded-blocks
error because the two rules do not consistently interpretswitch
case curly braces as blocks.https://eslint.org/play/#eyJ0ZXh0IjoibGV0IHNvbWVWYWx1ZSA9IFwiYVwiO1xuXG5zd2l0Y2ggKHNvbWVWYWx1ZSkge1xuICAgIFxuICAgIC8vIHNvbWUgY29tbWVudFxuICBjYXNlICdhJzpcbiAgICBzb21lVmFsdWUgPSBcImJcIjtcbiAgICBicmVhaztcbiAgXG4gIGRlZmF1bHQ6XG4gICAgc29tZVZhbHVlID0gXCJjXCI7XG59Iiwib3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFWZXJzaW9uIjoibGF0ZXN0Iiwic291cmNlVHlwZSI6InNjcmlwdCIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6eyJsaW5lcy1hcm91bmQtY29tbWVudCI6WzIseyJhbGxvd0Jsb2NrU3RhcnQiOnRydWUsImJlZm9yZUxpbmVDb21tZW50Ijp0cnVlLCJiZWZvcmVCbG9ja0NvbW1lbnQiOnRydWUsImFmdGVyQmxvY2tDb21tZW50IjpmYWxzZSwiYWZ0ZXJMaW5lQ29tbWVudCI6ZmFsc2UsImFsbG93QmxvY2tFbmQiOmZhbHNlfV0sInBhZGRlZC1ibG9ja3MiOlsiZXJyb3IiLCJuZXZlciJdfSwiZW52Ijp7ImVzNiI6dHJ1ZX19fQ==
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: