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

@typescript-eslint/naming-convention: enumMember should not be in strictCamelCase #43

Closed
jonahsnider opened this issue Oct 5, 2021 · 5 comments

Comments

@jonahsnider
Copy link

selector: ['variable', 'function', 'classProperty', 'objectLiteralProperty', 'parameterProperty', 'classMethod', 'objectLiteralMethod', 'typeMethod', 'accessor', 'enumMember'],

enumMembers should not be in strictCamelCase.

TypeScript documentation doesn't make a specific recommendation of enum member naming, although they exclusively use StrictPascalCase and UPPER_CASE (both of which are reasonable).

@sindresorhus
Copy link
Member

sindresorhus commented Oct 5, 2021

It was an intentional choice. I'm aware the TS docs use pascal-case, but it honestly makes no sense to me. Enum cases are members, and all other kinds of members are camel-case.

I think the Swift style enum casing looks the best and makes the most sense:

enum CardSuit {
	case clubs
	case diamonds
	case hearts
	case spades
}

@jonahsnider
Copy link
Author

jonahsnider commented Oct 6, 2021

That seems like a weird decision to make, we aren't writing Swift, we're writing TypeScript. It's also not accurate to compare enum members to other object members. Enum values are readonly constants which have never had the same naming convention as regular variables/object members. Node.js themselves use UPPER_CASE for enum values (ex. os.constants.signals).

Also worth mentioning is that enum members are implicitly types as well as values:

enum Color {
	R, G, B
}

const value: Color.R = Color.R;

Having this rule seems like a mistake and I think most other XO users will agree. I'd recommend simply removing the enumMember naming rule entirely, instead leave it up to developers to pick a naming convention they like.

@EdJoPaTo
Copy link

EdJoPaTo commented Oct 6, 2021

Interestingly I dont seem to use enums in TypeScript (rg "enum" --glob "*.ts" -A 5).
Personally I use string unions (type Something = 'foo' | 'bar') in these cases. And I seem to use camelCase for the values there.

My other language Rust where I use enums PascalCase is used (or the linter warns about not using it)

@sindresorhus
Copy link
Member

That seems like a weird decision to make, we aren't writing Swift, we're writing TypeScript.

TypeScript makes a ton of mistakes and weird choices by default.

Node.js themselves use UPPER_CASE for enum values (ex. os.constants.signals).

Those are not enum values though. And Node.js is not a good example of well-done APIs.

Also worth mentioning is that enum members are implicitly types as well as values:

This would be totally fine too:

const value: Color.r = Color.r;

Having this rule seems like a mistake and I think most other XO users will agree.

I think most people don't use TS enums as they're weirdly designed and also doesn't fit with JS. Most people use unions.

@sindresorhus
Copy link
Member

That being said, I don't use TS enums, so I agree with just ignoring it in the rule: https://github.com/xojs/eslint-config-xo-typescript/releases/tag/v0.45.2

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

No branches or pull requests

3 participants