我开发了一个 Angular 项目,并使用 ESLint 制定了修饰符规则,如下protected readonly
所示strictCamelCase
:
{
"selector": ["classProperty"],
"format": ["strictCamelCase"],
"leadingUnderscore": "forbid",
"trailingUnderscore": "forbid",
"modifiers": ["protected", "readonly"]
}
我在我的项目中使用了一些枚举,例如 EnumButtonSize,并且我用它来声明它:
protected readonly EnumButtonSize = EnumButtonSize;
- 修饰符
readonly
应该足够了,但是我在我的项目中使用了 Storybook,然后我必须添加protected
修饰符以使该变量不出现在 Storybook 文档中(另一种方法是在变量上方添加/** */
带有装饰器的注释)@internal
- 这个变量应该在模板中使用,例如
<my-button [buttonSize]="EnumButtonSize.LARGE">
我想添加一条特定的 ESLint 规则来支持 PascalCase 命名的枚举(除了上一条规则之外)。我尝试了类似的方法,但没有成功:
{
"selector": ["classProperty"],
"format": ["StrictPascalCase"],
"leadingUnderscore": "forbid",
"trailingUnderscore": "forbid",
"modifiers": ["protected", "readonly"],
"filter": {
"regex": "^Enum.*",
"match": true
}
},
有人可以帮助我或者有不同的想法吗?