为什么 typescript-eslint 强制 enumMember 使用驼峰命名法? [英] Why does typescript-eslint enforce camelCase for enumMember?
问题描述
TypeScript 文档中的所有枚举示例编写枚举成员为 PascalCase,喜欢:
All enum examples in the TypeScript documentation write enum members as PascalCase, like:
enum Direction {
Up = 1,
Down,
Left,
Right,
}
但是 @typescript-eslint/naming-convention 强制camelCase(并拒绝PascalCase),这意味着我必须写:
But @typescript-eslint/naming-convention enforces camelCase (and rejects PascalCase), which means I have to write:
enum Direction {
up = 1,
down,
left,
right,
}
是否有理由禁止枚举成员使用 PascalCase?
Is there a reason why PascalCase should be forbidden for enum members?
上下文是一个全新的 Angular 12 项目,带有推荐原理图:
The context is a brand new Angular 12 project with the recommended schematics:
ng add @angular-eslint/schematics
这对我来说毫无意义.
This makes no sense to me.
我的设置可能有误吗?
为什么官方命名约定会被拒绝?
Why would the official naming convention be rejected?
推荐答案
将此规则添加到eslintrc"配置文件中的规则部分:
Add this rule in to the rules section from your 'eslintrc' config file:
"rules": {
...,
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "variable",
"format": ["camelCase", "UPPER_CASE", "PascalCase"]
}
]
}
尝试更改选择器"和格式"您需要的选项:命名约定可用选项
Try to change "selector" and "format" options as you need: naming-convention available options
这篇关于为什么 typescript-eslint 强制 enumMember 使用驼峰命名法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!