将 tslint 与 Angular CLI 结合使用

Using tslint with Angular CLI

我正在尝试开始检查我的 Angular 项目。使用 Angular 4.x,所以我还有一个 .angular.cli.json 文件,其中包含:

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

这条路径的tsconfig.app.json就是:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "baseUrl": "",
    "types": []
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

但是,当我在父目录(或 "ng lint my-app",其中 my-app 是我的项目名称)中执行 "ng lint" 时,我在我的项目中只得到 test.ts 的错误根:

CedarsReport/src/test.ts[16, 13]: Identifier '__karma__' is never reassigned; use 'const' instead of 'let'.
CedarsReport/src/test.ts[17, 13]: Identifier 'require' is never reassigned; use 'const' instead of 'let'.

即使 test.ts 在上面显示的 tsconfig.app.json 中被明确排除。此外,父目录中的 tsconfig.json(在上面的 'extends' 中引用)包含:

   "include": [
        "src/app/**/*",
        "src/*.ts",
        "src/*.html"
   ],

我想应该会导致我的所有源代码都被检查 (??),但这似乎也没有发生。

我猜我对如何正确设置 'ng lint' 有一些误解,因此它知道我想要检查的源文件在哪里,以及我想要排除的内容。然而 documentation for Angular CLI's lint command 是稀疏的。任何指针(甚至文档)表示赞赏!

我猜 tslint 也在选择 test.ts 相关文件

就我而言 tsconfig.spec.json

  "files": [
    "test.ts"
  ],
  "include": [
    "**/*.spec.ts",
    "**/*.d.ts"
  ]

tsconfig.app.json

"exclude": ["test.ts", "**/*.spec.ts"]

tsconfig.e2d.json

在此文件中没有什么特别需要排除的