我最近已经将我的@typescript-eslint/eslint-plugin和@typescript-eslint/parser从5.9.1更新到了5.38.1,这使得我的eslint .开始抱怨代码中不允许使用纯数字对象索引。是否有办法将我的ESLint配置为强制执行约定,但不排除数字?
编辑:如下面的例子所示,只有当数值指数不在方括号内时,才会出现警告。因此,代码中的修复看起来很容易--只需在任何常量中添加方括号--但是如果ESLint一致地做出反应,那就更好了!
我的.eslintrc包含以下内容:
'@typescript-eslint/naming-convention': ['warn', {
'selector': 'property',
'format': ['strictCamelCase']
}],我希望能够有一个对象(例如,在测试文件中),例如:
{
0: true, // should be accepted; currently raises a warning
8: false, // should be accepted; currently raises a warning
[12]: true, // accepted
"foo": "bar", // accepted
"foo-bar": "baz" // should cause a warning because not strictCamelCase
}上面的数字索引给出了以下错误:
warning Object Literal Property name `3` must match one of the following formats: strictCamelCase @typescript-eslint/naming-convention发布于 2022-10-04 10:52:34
我能够使用规则中描述的filter属性获得预期的结果。
'@typescript-eslint/naming-convention': ['warn', {
'selector': 'property',
'format': ['strictCamelCase'],
'filter': { 'regex': '\\d+', 'match': false }
}],这样做的目的是将仅由数字组成的属性名称排除在根据camel case格式进行检查之外。模式'\\d+'与所需的仅数字标识符匹配。
https://stackoverflow.com/questions/73909962
复制相似问题