Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule proposal: Unreachable swtich default case #7627

Closed
6 tasks done
kkimdev opened this issue Sep 11, 2023 · 2 comments
Closed
6 tasks done

Rule proposal: Unreachable swtich default case #7627

kkimdev opened this issue Sep 11, 2023 · 2 comments
Labels
duplicate This issue or pull request already exists enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@kkimdev
Copy link

kkimdev commented Sep 11, 2023

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
  • My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

When all the enum cases are listed in a switch statement, default: block is unreachable. To my knowledge, there is no existing rule that detects such cases.

Note: This could be a special case of a more general unreachable code detection rule.

Fail Cases

enum Animal {
    cow
}

const main = (animal: Animal) => {
    switch (animal) {
        case Animal.cow:
            return 3;
        default:
            return 4;
    }
};

Pass Cases

enum Animal {
    cow,
    horse
}

const main = (animal: Animal) => {
    switch (animal) {
        case Animal.cow:
            return 3;
        default:
            return 4;
    }
};

Additional Info

No response

@kkimdev kkimdev added enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Sep 11, 2023
@Josh-Cena
Copy link
Member

Duplicate of #3616

@Josh-Cena Josh-Cena marked this as a duplicate of #3616 Sep 11, 2023
@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2023
@Josh-Cena Josh-Cena added duplicate This issue or pull request already exists and removed triage Waiting for maintainers to take a look labels Sep 11, 2023
@kkimdev
Copy link
Author

kkimdev commented Sep 11, 2023

Thanks!

PR work in progress: #7539

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants