You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode未读取.eslintrc.json,Angular项目ESLint规则失效求助

问题:Angular项目ESLint组件选择器前缀规则不生效

我的Angular项目中ESLint报出组件选择器错误,提示内容如下:
The selector should start with one of these prefixes: "app" (https://angular.io/guide/styleguide#style-02-07)eslint@angular-eslint/component-selector

但我已经在./client/.eslintrc.json里配置了自定义的前缀规则:

"rules": {
    "no-console": "error",
    "@angular-eslint/component-selector": [
        "error",
        {
            "prefix": ["one"],
            "style": "kebab-case",
            "type": "element"
        }
    ],
    "@angular-eslint/directive-selector": [
        "error",
        {
            "prefix": ["one"],
            "style": "camelCase",
            "type": "attribute"
        }
    ]
}

明显VSCode没有加载这个配置,我尝试过以下两种调整但都无效(Mac系统):

  • 在VSCode的settings.json中添加配置:"eslint.workingDirectories": ["./client"]
  • 在VSCode的settings.json中添加配置:"eslint.nodePath": "/Users/user-name/project-folder/project-name/client/.eslintrc.json"

解决方法

经过排查发现,项目中存在另一个.eslintrc.json文件(位于上级目录或根目录),该文件的规则优先级更高,覆盖了./client目录下的配置。删除冲突的配置文件,或者将两个配置文件的规则合并后,ESLint即可正确应用自定义的组件选择器前缀规则。

内容的提问来源于stack exchange,提问作者Newsha Nik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 20:45:38