简体   繁体   English

在Angular CLI中使用tslint

[英]Using tslint with Angular CLI

I'm attempting to start linting my Angular project. 我试图开始整理我的Angular项目。 Using Angular 4.x, so I still have an .angular.cli.json file, which contains: 使用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"
    }
],

The tsconfig.app.json at this path is simply: 此路径上的tsconfig.app.json很简单:

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

However, when I execute "ng lint" in the parent directory (or "ng lint my-app", where my-app is my project's name), I get errors only for test.ts in my project root: 但是,当我在父目录(或“ 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'.

even though test.ts is specifically excluded in tsconfig.app.json shown above. 即使在上面显示的tsconfig.app.json中明确排除了test.ts。 Additionally, the tsconfig.json in the parent directory (referenced in 'extends' above) contains this: 此外,父目录(在上面的“扩展”中引用)中的tsconfig.json包含以下内容:

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

which I imagine should result in all my source code being linted (??), but this doesn't seem to be happening either. 我想这应该导致我的所有源代码都被掉线(??),但这似乎也没有发生。

I'm guessing I'm mis-understanding something about how to properly set up 'ng lint' so it knows where my source files are that I want linted, and what I want excluded. 我猜想我对如何正确设置'ng lint'有误解,因为它知道我的源文件在哪里,我想删除这些文件以及我想排除的文件。 However the documentation for Angular CLI's lint command is sparse. 但是,Angular CLI的lint命令文档很少。 Any pointers (even to documentation) appreciated! 任何指针(甚至指向文档)都表示赞赏!

I guess tslint is also picking the test.ts related file 我想tslint也在选择与test.ts相关的文件

in my case tsconfig.spec.json 就我而言tsconfig.spec.json

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

tsconfig.app.json tsconfig.app.json

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

and tsconfig.e2d.json tsconfig.e2d.json

nothing special to exlcude in this file 在这个文件中没有什么特别的地方

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM