简体   繁体   中英

How to use different tslint.json for *.spec.ts files

I have a set of tslint rules defined for my Angular application. However, for spec files, I'd like to use more relaxed set of rules (eg disable the newline-per-chained-call rule for nice expect statements), but I cannot figure it how to do that in IntelliJ IDEA.

Angular CLI works fine because in the CLI configuration there is a section that maps proper tsconfig.json files (with proper exclusions/inclusions) with corresponding tslint files. However, IntelliJ doesn't respect that.

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

IntelliJ since version 2018.1 supports multiple tsconfig.json files (see: https://youtrack.jetbrains.com/issue/WEB-28091 ), although it looks like still doesn't support multiple tslint configs.

I also found a solution to create a local scope and disable some inspections for it, but I'd rather want it to be defined by tslint rules for people not using IntelliJ.

An alternative would be to place tests in a separate directory and place a tslint.json inside it, but that's not what Angular recommends and it's not what people are used to in Angular.

TsLint service in IDEA works just in the same way as TSLint cli - it looks for a configuration file named tslint.json in the directory of the file being linted and, if not found, searches ancestor directories. So the only solution is placing separate configuration files in your spec dirs. If you need the service to follow Angular rules here, please feel free to create a feature request in youtrack, https://youtrack.jetbrains.com/issues/WEB . If it gets enough votes, it will be considered for future versions

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