Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

no-switch-case-fall-through thrown on nested switch statements where all cases of inner switch have return statements #1538

Closed
sumitkmr opened this issue Sep 2, 2016 · 3 comments

Comments

@sumitkmr
Copy link

sumitkmr commented Sep 2, 2016

Bug Report

  • TSLint version: 3.2.0
  • TypeScript version: 1.8.10
  • Running TSLint via: Node.js API

TypeScript code being linted

function foo (a: number, b: number): number {
    switch (a) {
        case 1:
            switch (b) {
                case 2:
                    return 1;
                default:
                    return 2;
            }
        default:
            return 3;
    }
}

with tslint.json configuration:

(include if relevant)

Actual behavior

Throws no-switch-case-fall-through at line before default case of the outer loop.

Expected behavior

No error.

@Buuhuu
Copy link

Buuhuu commented Sep 29, 2016

Same for

function(a: number, b:number): void {
    switch (a) {
        case 1:
            if (b > 10) {
                return;
            } else {
                return;
            }
        case 2:
            return;
        default:
            return;
    }
}

@michaeljota
Copy link

michaeljota commented Oct 14, 2016

It does not even need to be nested to throw.

function(a: number, b:number): void {
    switch (a) {
        case 1: {
            return;
        } // Throws
        case 2:
            return;
        default:
            return;
    }
}

@raveclassic
Copy link

Same here - no-switch-case-fall-through doesn't recognize break/return inside case blocks case ... { ... }.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants