首页  >  问答  >  正文

Vue 组件的 @typescript-eslint/naming-convention 解决方法

我们启用了此规则: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/naming-convention.md#allowed-selectors-modifiers-and-types

默认情况下,这不允许在对象文字中使用 PascalCase,这对于 vue 组件来说是一个问题

export default defineComponent({
    name: 'MyComponent',
    components: {
      MyOtherComponent,
    },
  })

创建以下警告

对象文字属性名称 MyOtherComponent 必须匹配以下格式之一:camelCase

有没有人找到解决方法?我尝试了所有修改,但找不到一种可以解决问题且不允许在对象文字上使用 Pascal 的修改

P粉785957729P粉785957729206 天前332

全部回复(1)我来回复

  • P粉530519234

    P粉5305192342024-03-27 15:53:40

    我可以重新创建它的唯一方法是使用规则:

    "@typescript-eslint/naming-convention": [
                        "error",
                        {
                            "selector": "class",
                            "format": ["PascalCase"]
                        },
    

    这不是默认的。所以我猜你的 eslintrc 文件中有这个或者正在使用这个集合的默认值。您应该能够覆盖它以使用:

    {
        "selector": "class",
        "format": ["camelCase"]
    }
    

    回复
    0
  • 取消回复