denoland / deno_lint

Blazing fast linter for JavaScript and TypeScript written in Rust
https://lint.deno.land/
MIT License
1.53k stars 172 forks source link

Fallthrough is not allowed when adding comment above switch case #1196

Closed dsherret closed 3 months ago

dsherret commented 1 year ago

I often do stuff like this:

switch (something) {
  case 1:
  // some comment about case 2
  case 2:
    console.log(1);
    break;
  default:
    console.log(2);
    break;
}

There is no fallthrough here, but deno lint warns about it because of the comment on line 3

dsherret commented 1 year ago

Just looked into this and it seems to be explicitly not allowed here: https://github.com/denoland/deno_lint/blob/main/src/rules/no_fallthrough.rs#L271

Eslint seems to only allow it when setting allowEmptyCase (https://eslint.org/docs/latest/rules/no-fallthrough#allowemptycase).

I would argue that the empty case is a formatting concern (the formatter will collapse it) and adding a comment here is mostly used to document a case. With the rule as-is there's no way to document why a specific case exists in a list of cases without adding a deno-lint-ignore comment at the top, so I think we should just allow this because I'm not sure what problem it's trying to prevent.

lucacasonato commented 10 months ago

We should allow it.

koh28 commented 4 months ago

May I work on this issue?