-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[naming-convention] enumMembers should be default PascalCase #7879
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
Comments
Some codebases use camelCase for enums, some PascalCase. I suspect we should allow both for the default convention. |
I'm not sure about this, tbh. Either that means one of:
Could do a sourcegraph query of public githubs to roughly determine which it is. If it's the 3rd then making this change would be bad as it would allow inconsistency in codebases - IMO you want one or the other in a codebase - not both. |
I agree with @JoshuaKGoldberg that camelCase should be added for backward compatibility reasons. And for the casing, I searched npm homepage Popular libraries and fronend packages sorted by popularity I omit any package which does not have built-in typescript (even it as
For the above repo, only Webpack and Preact is using camelCase enum. Others are all using PascalCase mostly. A lot of repo includes camelCase (or lowercase) to represent the same keyword strings, e.g.: const enum Log {
debug = 'debug',
info = 'info',
// ...
} And some libraries like Vue use UPPERCASE for internal usage of enum to slim package size: // this is internal and only used to slim pro size
export const enum LifecycleHooks {
BEFORE_CREATE = 'bc',
CREATED = 'c',
BEFORE_MOUNT = 'bm',
MOUNTED = 'm',
BEFORE_UPDATE = 'bu',
UPDATED = 'u',
BEFORE_UNMOUNT = 'bum',
UNMOUNTED = 'um',
DEACTIVATED = 'da',
ACTIVATED = 'a',
RENDER_TRIGGERED = 'rtg',
RENDER_TRACKED = 'rtc',
ERROR_CAPTURED = 'ec',
SERVER_PREFETCH = 'sp'
} enum for other usage are mostly PascalCase, and follows TypeScript docs/blogs syntax. So I still insist my point @bradzacher, at least PascalCase should be added to defaults. Nobody would expect that codes having the same syntax as TypeScript docs example are "incorrect" with this linter. |
Another reason according to my usage, using PascalCase for enum makes it easier to recognize them through codes: // Probably a class property
Abc.def
// TypeScript enum / const enum
Abc.Def
// object property
abc.def |
I also agree to add PascalCase by default. The reason we don't get these requests often is because (a) people don't bother reading the default options and figuring out if they will work well; they just hand-configure them anyway (b) they don't know about conventions and/or they don't read the TS docs, so they trust the default options and they just use camelCase all along since they created the project (c) they don't use enums at all (d) they don't find it meaningful to argue about configurable default options. But I think it's a nice improvement both for developer education and alignment with conventions. |
In theory, per #8792, we're feature freezing this rule. It's reached the point of complexity where we're having a hard time justifying working on it. In practice, I think this is a nice and straightforward enough improvement for users that we can allow it regardless. cc @Josh-Cena |
Before You File a Proposal Please Confirm You Have Done The Following...
Description
Code like this fails with the default option:
However, I think using PascalCase for enum member should be the default option, as this is the default syntax in TypeScript official docs, blogs and examples.
E.g.:
Other things to report and could be a feature request
The problem is affecting me because we are not providing a keyword to enable the default naming convention and "make some tweaks over it". I.E.: In this case, I can not simply add the green line below, instead I have to redeclare the whole "option". That is not convinient for me accross projects.
Impacted Configurations
Additional Info
No response
The text was updated successfully, but these errors were encountered: