Why does typescript-eslint enforce camelCase for enumMember?

Viewed 3571

All enum examples in the TypeScript documentation write enum members as PascalCase, like:

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

But @typescript-eslint/naming-convention enforces camelCase (and rejects PascalCase), which means I have to write:

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

Is there a reason why PascalCase should be forbidden for enum members?


The context is a brand new Angular 12 project with the recommended schematics:

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?

1 Answers

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

Related