英文:
Using @typescript-eslint/naming-convention is it possible to select class properties that are not static?
问题
以下是代码部分的中文翻译:
export class ConsentOptionsWidget {
public static NULL_CATEGORY_PLACEHOLDER = '选择订阅频道';
public static EMAIL_CHANNEL = '电子邮件';
public header_name!: string;
public consentStatement!: string;
}
"@typescript-eslint/naming-convention": [
"error",
{
"format": ["snake_case"],
"modifiers": ["public"],
"selector": "classProperty"
}
]
我已经为您翻译了代码部分,如有需要,请告诉我是否还需要其他帮助。
英文:
I have the following typescript:
export class ConsentOptionsWidget {
public static NULL_CATEGORY_PLACEHOLDER = 'Opt in to channel';
public static EMAIL_CHANNEL = 'Email';
public header_name!: string;
public consentStatement!: string;
}
and my eslint rule:
"@typescript-eslint/naming-convention": [
"error",
{
"format": ["snake_case"],
"modifiers": ["public"],
"selector": "classProperty"
}
]
I only want the rule to apply to header_name
and consentStatement
with consentStatement
generating an error. But, as is, consentStatement
, NULL_CATEGORY_PLACEHOLDER
and EMAIL_CHANNEL
generate errors.
According to the project maintainers, even though the docs say "The name must match all of the modifiers" modifiers
is actually a superset so public
matches anything with public
regardless of any other modifiers.
答案1
得分: 1
You could add another descriptor with no format requirement for public static properties.
"@typescript-eslint/naming-convention": [
"error",
{
"format": ["snake_case"],
"modifiers": ["public"],
"selector": "classProperty"
},
{
"modifiers": ["public", "static"],
"selector": "classProperty"
}
]
英文:
You could add another descriptor with no format requirement for public static properties.
"@typescript-eslint/naming-convention": [
"error",
{
"format": ["snake_case"],
"modifiers": ["public"],
"selector": "classProperty"
},
{
"modifiers": ["public", "static"],
"selector": "classProperty"
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论