【问题标题】:Using tslint with Angular CLI在 Angular CLI 中使用 tslint
【发布时间】:2019-03-14 18:31:10
【问题描述】:

我正在尝试开始检查我的 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'.

即使上面显示的 tsconfig.app.json 中明确排除了 test.ts。此外,父目录中的 tsconfig.json(在上面的“扩展”中引用)包含以下内容:

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

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

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

【问题讨论】:

    标签: angular angular-cli tslint


    【解决方案1】:

    我猜 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

    在这个文件中没有什么特别要排除的

    【讨论】:

    • 你说得对,我的 tsconfig.spec.json 也是类似的。 tsconfig.spec 的目的是什么?而且,有没有办法将它配置为只使用我已经在 tsconfig.json 中定义的路径?无论如何,我手动将正确的路径添加到 tsconfig.spec.json 并且 linting 有效!
    • 有一个主(基本)配置文件,其他从它们扩展而来。 tslint 会将它用于不同的目的,比如一个用于 e2e (ng e2e) 另一个用于业力单元测试 (ng test) 和另一个用于构建您的生产代码 (ng build --prod)。
    猜你喜欢
    • 2018-03-18
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    • 2019-03-12
    • 2017-03-19
    • 2016-12-23
    • 2017-06-23
    • 2017-05-13
    相关资源
    最近更新 更多