简体   繁体   English

为什么 typescript-eslint 强制 enumMember 使用驼峰命名法?

[英]Why does typescript-eslint enforce camelCase for enumMember?

All enum examples in the TypeScript documentation write enum members as PascalCase, like: TypeScript 文档中的所有枚举示例都将枚举成员写为 PascalCase,例如:

enum Direction {
  Up = 1,
  Down,
  Left,
  Right,
}

But @typescript-eslint/naming-convention enforces camelCase (and rejects PascalCase), which means I have to write:但是@typescript-eslint/naming-convention强制使用camelCase(并拒绝PascalCase),这意味着我必须写:

enum Direction {
  up = 1,
  down,
  left,
  right,
}

Is there a reason why PascalCase should be forbidden for enum members?是否有理由禁止枚举成员使用 PascalCase?


The context is a brand new Angular 12 project with the recommended schematics:上下文是一个全新的 Angular 12 项目,带有推荐的原理图:

ng add @angular-eslint/schematics

This makes no sense to me.这对我来说毫无意义。

Is my set-up possibly wrong?我的设置可能有问题吗?

Why would the official naming convention be rejected?为什么官方命名约定会被拒绝?

Add this rule in to the rules section from your 'eslintrc' config file:将此规则添加到“eslintrc”配置文件中的规则部分:

"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尝试根据需要更改“选择器”和“格式”选项: 命名约定可用选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 typescript-eslint 规则添加到 eslint - How to add typescript-eslint rules to eslint ESLint 无法识别“@typescript-eslint/eslint-plugin” - ESLint is not recognizing "@typescript-eslint/eslint-plugin" ESlint & Angular 13: 无法关闭 typescript-eslint/typedef - ESlint & Angular 13: Unable to turn off typescript-eslint/typedef angular-eslint 和 typescript-eslint 之间的区别 - Difference between angular-eslint and typescript-eslint 错误 'this' 到局部变量 @typescript-eslint/no-this-alias 的意外别名 - ERROR Unexpected aliasing of 'this' to local variable @typescript-eslint/no-this-alias Angular & eslint - 未找到规则“@typescript-eslint/space-infix-ops”的定义 - Angular & eslint - Definition for rule '@typescript-eslint/space-infix-ops' was not found 使用“typescript-eslint/recommended”和“@angular-eslint/recommended”扩展多个规则集可以吗? - Extending multiple rule-sets using "typescript-eslint/recommended" with "@angular-eslint/recommended" is this okay to do? Angular 2如何使用camelCase处理属性 - How does Angular 2 handles attributes with camelCase TypeScript:在PascalCase和camelCase之间切换时的奇怪行为 - TypeScript: Strange behaviour when switching between PascalCase and camelCase 为什么打字稿接受数字值作为类型? - Why does typescript accept a number value as a type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM