问题描述
我一直在使用typescript-eslint和eslint-plugin向项目添加绒毛,对于类和接口的属性,我需要不同的绒毛规则。目前,我正在使用naming-convention规则。
对于类属性,strictCamelCase效果很好。但是对于接口属性,我需要同时使用strictCamelCase和PascalCase。
我想在任何地方都使用strictCamelCase,但是在我们的代码中有一些地方需要使用数据库列作为属性。例如:
class ActivitySearchModel extends common.Model {
attributes: {
ResultID: number;
StartDateTime: moment.Moment;
EndDateTime: moment.Moment;
Label: string;
};
}
此结构在代码库中普遍存在,无法进行合理更改。除了这些属性外,其他所有内容都是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"]
},"PascalCase"],"leadingUnderscore": "require"
}
],
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)