简体   繁体   中英

Using tslint with Angular CLI

I'm attempting to start linting my Angular project. Using Angular 4.x, so I still have an .angular.cli.json file, which contains:

"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:

{
  "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:

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. Additionally, the tsconfig.json in the parent directory (referenced in 'extends' above) contains this:

   "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. However the documentation for Angular CLI's lint command is sparse. Any pointers (even to documentation) appreciated!

I guess tslint is also picking the test.ts related file

in my case tsconfig.spec.json

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

tsconfig.app.json

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

and tsconfig.e2d.json

nothing special to exlcude in this file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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