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

Created on 2 Sep 2016  ·  3Comments  ·  Source: palantir/tslint

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.

P2 Fixed Bug

Most helpful comment

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

All 3 comments

Same for

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dashmug picture dashmug  ·  3Comments

cateyes99 picture cateyes99  ·  3Comments

SwintDC picture SwintDC  ·  3Comments

denkomanceski picture denkomanceski  ·  3Comments

adidahiya picture adidahiya  ·  3Comments