Ale*_*ruh 5 naming-conventions typescript eslint eslintrc typescript-eslint
我一直在使用typescript-eslint和eslint-plugin向项目添加linting,我需要不同的 linting 规则来处理类和接口的属性。目前我正在使用命名约定规则。
对于类属性,strictCamelCase 效果很好。但是对于接口属性,我需要同时允许strictCamelCase 和PascalCase。
我想在任何地方都使用 strictCamelCase,但是在我们的代码中有些地方我需要使用 DB 列作为属性。例如:
class ActivitySearchModel extends common.Model {
attributes: {
ResultID: number;
StartDateTime: moment.Moment;
EndDateTime: moment.Moment;
Label: string;
};
}
Run Code Online (Sandbox Code Playgroud)
这种结构在整个代码库中无处不在,无法合理更改。除了这些属性,其他一切都是strictCamelCase。
是否有一种简单的方法可以为接口属性和类属性强制执行不同的命名约定?更好的是,有没有办法只允许在属性上使用 PascalCase?是让它工作自定义规则的唯一方法吗?
当前设置的 eslintrc 的相关部分:
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": ["strictCamelCase"]
},
{
"selector": "memberLike",
"modifiers": ["private"],
"format": ["strictCamelCase"],
"leadingUnderscore": "require"
},
{
"selector": "property",
"format": ["strictCamelCase", "PascalCase"]
},
{
"selector": "property",
"modifiers": ["private"],
"format": ["strictCamelCase", "PascalCase"],
"leadingUnderscore": "require"
}
],
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1561 次 |
最近记录: |