可变名称`pieGraphLayout`必须匹配以下格式之一:骆驼壳@typescript-eslint/naming-convention

发布于 2025-02-12 03:05:03 字数 2151 浏览 1 评论 0原文

这个问题类似于为什么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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别闹i 2025-02-19 03:05:03

您没有为变量实体定义格式,并且ESLINT使用您的default Selector格式,该格式在提供的配置中为Camelcase

要提供变量的格式,请配置变量选择器。

就您而言,应该有

{
  "selector": "variable",
  "format": [
    "PascalCase"
  ]
},

此处是所有可用选择器的文档。

You don't have defined formats for variable entities, and ESLint uses your default selector format, which is camelCase in the provided configuration.

To provide formats for a variable, please configure variable selector.

In your case, there should be something like

{
  "selector": "variable",
  "format": [
    "PascalCase"
  ]
},

Here is a doc for all available selectors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文