可变名称`pieGraphLayout`必须匹配以下格式之一:骆驼壳@typescript-eslint/naming-convention
这个问题类似于为什么Eslint将类别视为可变的类别在命名规则中?,但是那个很老,我现在看不到处理的一致性。
当我从静态导入类类型时,Eslint会识别它并应用类命名规则,例如:
import { PieGraphLayout } from import("../console.worker-types");
当我使用动态导入进行此操作时,我会遇到错误:
const { PieGraphLayout } = await import("../console.worker-types");
导致:
变量名称
pieGraphlayout
必须匹配以下格式之一:骆驼壳eSlint@typescript-eslint/naming-convention
我必须抑制此警告,但希望如果可能的话,请改用我的ESLINT规则。我目前的命名规则是:
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": [
"camelCase"
],
"filter": {
"regex": "^_",
"match": false
}
},
{
"selector": "class",
"format": [
"PascalCase"
]
},
{
"selector": "typeParameter",
"format": [
"PascalCase"
]
},
{
"selector": "enum",
"format": [
"PascalCase"
]
},
{
"selector": "enumMember",
"format": [
"PascalCase"
]
},
{
"selector": "typeAlias",
"format": [
"PascalCase"
]
},
{
"selector": "interface",
"format": [
"PascalCase"
],
"prefix": [
"I"
]
}
],
需要更改什么,以便ESLINT不再对这种动态进口发出警告?
This is a question similar to Why eslint consider class as variable in naming-convention rule?, but that one is pretty old and I see no consistency in the handling now.
When I statically import a class type then ESLint recognizes it as such and applies the class naming rule, for example:
import { PieGraphLayout } from import("../console.worker-types");
When I do this with a dynamic import, however, I get an error:
const { PieGraphLayout } = await import("../console.worker-types");
leads to:
Variable name
PieGraphLayout
must match one of the following formats: camelCase eslint@typescript-eslint/naming-convention
I have to suppress this warning, but would like to modify my ESLint rules instead, if possible. My current naming-convention rule is:
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": [
"camelCase"
],
"filter": {
"regex": "^_",
"match": false
}
},
{
"selector": "class",
"format": [
"PascalCase"
]
},
{
"selector": "typeParameter",
"format": [
"PascalCase"
]
},
{
"selector": "enum",
"format": [
"PascalCase"
]
},
{
"selector": "enumMember",
"format": [
"PascalCase"
]
},
{
"selector": "typeAlias",
"format": [
"PascalCase"
]
},
{
"selector": "interface",
"format": [
"PascalCase"
],
"prefix": [
"I"
]
}
],
What needs to be changed so that ESLint no longer gives a warning for such dynamic imports?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有为
变量
实体定义格式,并且ESLINT使用您的default
Selector格式,该格式在提供的配置中为Camelcase
。要提供变量的格式,请配置
变量
选择器。就您而言,应该有
此处是所有可用选择器的文档。
You don't have defined formats for
variable
entities, and ESLint uses yourdefault
selector format, which iscamelCase
in the provided configuration.To provide formats for a variable, please configure
variable
selector.In your case, there should be something like
Here is a doc for all available selectors.