Skip to content

[no-fallthrough] Lint rule needs type information to avoid false positives e.g. nested switch #3455

Open
@OliverJAsh

Description

@OliverJAsh
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "no-fallthrough": [2]
  }
}
declare const n: { a: 1; b: 1 | 2 } | { a: 2 };
(() => {
  switch (n.a) {
    case 1: {
      switch (n.b) {
        case 1:
          return 1;
        case 2:
          return 1;
      }
    }
    // ESLint error:
    // Expected a 'break' statement before 'case'.
    case 2: {
      return 2;
    }
  }
})();

Expected Result

No lint error

Actual Result

Lint error (see comment)

Additional Info

I think the TS ESLint plugin needs to provide its own version of no-fallthrough in order to take advantage of type information so we can avoid false positives such as this.

Versions

package version
@typescript-eslint/eslint-plugin latest
@typescript-eslint/parser latest
TypeScript latest
ESLint latest
node latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new base rule extensionNew base rule extension required to handle a TS specific casepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy