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.

Apparent discrepancy in the definition of a block between rules

See original GitHub issue

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, 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";
}

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

https://eslint.org/play/#eyJ0ZXh0IjoibGV0IHNvbWVWYWx1ZSA9IFwiYVwiO1xuXG5zd2l0Y2ggKHNvbWVWYWx1ZSkge1xuICAgIFxuICAgIC8vIHNvbWUgY29tbWVudFxuICBjYXNlICdhJzpcbiAgICBzb21lVmFsdWUgPSBcImJcIjtcbiAgICBicmVhaztcbiAgXG4gIGRlZmF1bHQ6XG4gICAgc29tZVZhbHVlID0gXCJjXCI7XG59Iiwib3B0aW9ucyI6eyJwYXJzZXJPcHRpb25zIjp7ImVjbWFWZXJzaW9uIjoibGF0ZXN0Iiwic291cmNlVHlwZSI6InNjcmlwdCIsImVjbWFGZWF0dXJlcyI6e319LCJydWxlcyI6eyJsaW5lcy1hcm91bmQtY29tbWVudCI6WzIseyJhbGxvd0Jsb2NrU3RhcnQiOnRydWUsImJlZm9yZUxpbmVDb21tZW50Ijp0cnVlLCJiZWZvcmVCbG9ja0NvbW1lbnQiOnRydWUsImFmdGVyQmxvY2tDb21tZW50IjpmYWxzZSwiYWZ0ZXJMaW5lQ29tbWVudCI6ZmFsc2UsImFsbG93QmxvY2tFbmQiOmZhbHNlfV0sInBhZGRlZC1ibG9ja3MiOlsiZXJyb3IiLCJuZXZlciJdfSwiZW52Ijp7ImVzNiI6dHJ1ZX19fQ==

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
snitin315commented, Jul 28, 2022

@kboucher the next release is scheduled on 29th July.

1reaction
snitin315commented, Jul 19, 2022

I’ll prepare a fix for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apparent discrepancy definition and meaning | Collins English ...
Apparent discrepancy definition: If there is a discrepancy between two things that ought to be the same, ... Meaning, pronunciation, translations and examples....
Read more >
40 CFR § 264.72 - Manifest discrepancies. - Law.Cornell.Edu
(a) Manifest discrepancies are: (1) Significant differences (as defined by paragraph (b) of this section) between the quantity or type of hazardous waste ......
Read more >
text-decoration: apparent discrepancy between appearance ...
So, the discrepancy here lies in the difference between a computed value and a used value. The definitions can be found in section...
Read more >
The Gage block handbook - GovInfo
provide the means and methods for comparing standards used in science, engineering,manufacturing, commerce, industry, and education with the standards adopted ...
Read more >
Leg Length Discrepancy - Physiopedia
Leg length discrepancy (LLD) or anisomelia, is defined as a condition in which ... giving an apparent LLD despite equal lengths from 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