-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [no-unsafe-enum-assignment] add rule #6091
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
feat(eslint-plugin): [no-unsafe-enum-assignment] add rule #6091
Conversation
also fixes for codebase
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
Additional cases that this rule should handle:
Edge cases to think about: declare function fn(arg: Fruit): void;
fn(...[1]);
const x = [1, Fruit.Apple, 2] as const;
const y: readonly Fruit[] = x;
interface Foo<T extends Fruit> { prop: T; }
export const clazz: Foo<Fruit> = class WTF {
static prop = 1;
} |
Yeah, there are a lot of cases to handle here. Basically any identifier and literal has to be checked - including array literals and parameters to generic functions! I don't have the time to work on this rule given other, more important features to work on. So I'm going to close this PR. If anybody else wants to pick it up, please do! Note that the code will likely need to be refactored a good bit to support all the new cases. |
I wonder @JoshuaKGoldberg - do you think this should be built directly into our The reason I originally split up the rules into a set was to isolate the logic for checking assignments in each case to reduce the overall maintenance complexity. They don't currently do some of the checks I've listed (like checking when WDYT? Do we refactor to reuse logic or build into those rules? |
Hmmmmm, my gut reaction is that I'd rather extract those things out into shared utilities. +1 to reusing the logic for sure. Enums really aren't the same use case as |
PR Checklist
Overview
Adds a new
no-unsafe-enum-assignment
rules that prevents assigning literals to enum values.Co-authored-by: @Zamiell