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.

Allow `commentPattern: null` in no-fallthrough

See original GitHub issue

What rule do you want to change?

no-fallthrough

Does this change cause the rule to produce more or fewer warnings?

more

How will the change be implemented? (New option, new default behavior, etc.)?

The existing option "commentPattern" will allow null value.

This will be the official way to disable the commentPattern feature of this rule for users who prefer explicit eslint-disable comments or maybe want to completely disallow falling through case clauses.

A current workaround is to set a pattern that can never match.

Refs: #13260, #13627

Please provide some example code that this change will affect:

/* eslint no-fallthrough: "error" */

switch (foo) {
  case 1:
    bar();

  // eslint-disable-next-line no-fallthrough  
  case 2:
    baz();  
}

What does the rule currently do for this code?

When run with --report-unused-disable-directives, ESLint reports:

  7:3  error  Unused eslint-disable directive (no problems were reported from 'no-fallthrough')

This is because the comment happens to be both an eslint-disable directive and a directive for the no-fallthrough rule (since the comment matches the default commentPattern) at the same time, so no-fallthrough actually doesn’t report an error.

What will the rule do after it’s changed?

If "commentPattern": null is set, no comments will match.

I think that this option ideally shouldn’t have a default value, but that might be a big breaking change.

Are you willing to submit a pull request to implement this change?

Yes.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nzakascommented, Oct 14, 2020

Oops misinterpreted the earlier comment. Even without a breaking change, I’d still prefer not changing the current behavior and just documenting the problem. It seems like the issue is more one of people not understanding how to use the rule rather than a problem with the rule itself.

0reactions
mdjermanoviccommented, Dec 12, 2022

I realized that the purpose of this rule is actually to mark intentional fall-throughs, not to disallow fall-throughs, so this proposal doesn’t make sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-fallthrough - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
no-switch-case-fall-through - Rule
Rule: no-switch-case-fall-through. Disallows falling through case statements. For example, the following is not allowed:.
Read more >
fluid-eslint | Yarn - Package Manager
Docs: Add new formatters to API docs (Ian VanSchooten); New: Implement autofixing (fixes #3134) (Nicholas C. Zakas); Fix: Remove temporary "allow-null" ...
Read more >
Diff - 402e1b6e55e9041dfd1a93580e45e5c5dba1db55^!
(#6485) (Nick Heiner) +* 5668236 Fix: Allow objectsInObjects ... Mills) +* 2b39461 Update: `commentPattern` option for `default-case` rule ...
Read more >
How do I safely fix ESLint`no-fallthrough` error for intentional ...
... 'rules': {'no-fallthrough': ['error', {'commentPattern': 'break[\\s\\w]*omitted'}] ... and in your code: switch(foo) { case 1: doSomething ...
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