如何从 angular cli 中的 linting ignore/exclude 一些 files/directory

How to ignore/exclude some files/directory from linting in angular cli

类似于

我是 运行 以下命令来检查我的 angular2 typeScript 代码。

ng lint

它很好地证明了所有的 linting 错误。

但我希望我的供应商文件夹(比方说 "src/app/quote/services/generated/**/*")不应该包含在衬里的时候。

我知道这可以使用 tslint 命令完成,如下所示 ()

tslint \"src/**/*.ts\" -e \"**/__test__/**\"

但是在angularcli中参数是什么?如何从 tslint 中排除一些文件?

注意:我的 Angular Cli 版本是:@angular/cli: 1.0.0-rc.0

Angular6+ 开始,.angular-cli.json 已被 angular.json 取代,但您仍然可以在其 lint 部分添加排除路径。

"lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": [
          "src/tsconfig.app.json",
          "src/tsconfig.spec.json"
        ],
        "exclude": [
          "**/node_modules/**"      // excluded directories
        ]
      }
    }

根据 angular-cli issue#5063,您可以像这样在 .angular-cli.json 中添加排除路径:

"lint": [
{
  "project": "src/tsconfig.app.json",
  "exclude": "**/node_modules/**/*"   // the node_modules for example
}]

发现它必须是一个 blob 模式..

如果你想要多个 files/directories 只需在你的 .angular-cli.json

中使用一个数组
"exclude": [
 "**/*whatever.pipe.ts", 
 "**/*whatever_else.component.ts"
]

你的angular-cli.json文件应该是这样的-

"lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ]

您需要删除 "src/tsconfig.spec.json" 的 lint 路径。因此,要么删除第二个对象,要么对其进行注释。 您更新的 lint 数组应该是这样的-

"lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ]