如何忽略tslint的特定目录或文件?

use*_*840 113 javascript ide webstorm typescript tslint

正在使用的IDE是WebStorm 11.0.3,tslint已配置并可正常工作,但由于它尝试解析大型*.d.ts库文件而挂起.

有没有办法忽略特定的文件或目录?

Mic*_*ael 171

使用TSLINT v5.8.0更新

正如Saugat Acharya所提到的,您现在可以更新tslint.json CLI选项:

{
  "extends": "tslint:latest",
  "linterOptions": {
      "exclude": [
          "bin",
          "lib/*generated.js"
      ]
  }
}
Run Code Online (Sandbox Code Playgroud)

更多信息在这里


TSLINT 3.6引入了此功能

tslint \"src/**/*.ts\" -e \"**/__test__/**\"
Run Code Online (Sandbox Code Playgroud)

您现在可以在此处添加--exclude(或-e)查看PR.

CLI

usage: tslint [options] file ...

Options:

-c, --config          configuration file
--force               return status code 0 even if there are lint errors
-h, --help            display detailed help
-i, --init            generate a tslint.json config file in the current working directory
-o, --out             output file
-r, --rules-dir       rules directory
-s, --formatters-dir  formatters directory
-e, --exclude         exclude globs from path expansion
-t, --format          output format (prose, json, verbose, pmd, msbuild, checkstyle)  [default: "prose"]
--test                test that tslint produces the correct output for the specified directory
-v, --version         current version
Run Code Online (Sandbox Code Playgroud)

你正在寻找使用

-e, --exclude         exclude globs from path expansion
Run Code Online (Sandbox Code Playgroud)

  • 多次重复exclude参数 (4认同)
  • 对更新的小修正:它应该是`linterOptions`而不是`cliOptions` (4认同)
  • 值得一提的是,exclude目录中的glob模式应该与`tslint.json`相关 (4认同)

Dea*_*ers 43

我正在使用Visual Studio Code和this

/* tslint:disable */

为我工作.看看这个页面,大约3/4的路上有一些禁用命令https://c9.io/lijunle/tslint

  • 从所有答案中,这是唯一有效的答案。谢谢! (3认同)

ark*_*ise 26

除了迈克尔的答案,还要考虑第二种方法:将linterOptions.exclude添加到tslint.json

例如,您可能拥有tslint.json以下行:

{
  "linterOptions": {
    "exclude": [
      "someDirectory/*.d.ts"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)


Sau*_*rya 14

tslint v5.8.0您开始,您可以在文件中excludelinterOptions密钥下设置一个属性tslint.json:

{
  "extends": "tslint:latest",
  "linterOptions": {
      "exclude": [
          "bin",
          "**/__test__",
          "lib/*generated.js"
      ]
  }
}
Run Code Online (Sandbox Code Playgroud)

更多信息请参见这里.

  • 这应该标记为正确的(并在2017年11月更新)答案. (2认同)

tec*_*000 10

我不得不使用 **/* 语法来排除文件夹中的文件:

    "linterOptions": {
        "exclude": [
          "src/auto-generated/**/*",
          "src/app/auto-generated/**/*"
        ]
    },
Run Code Online (Sandbox Code Playgroud)


Alb*_*rtK 10

作为补充

禁用下一行的所有规则 // tslint:disable-next-line

要禁用下一行的特定规则// tslint:disable-next-line:rule1 rule2...

要禁用当前行的所有规则someCode(); // tslint:disable-line

要禁用当前行的特定规则someCode(); // tslint:disable-line:rule1


Mar*_*cka 9

这里 别人谁碰到的问题.不幸的是,排除文件只有一个未解决的问题:https://github.com/palantir/tslint/issues/73

所以我担心答案是否定的.


小智 6

linterOptions 目前仅由 CLI 处理。如果您不使用 CLI,那么根据您使用的代码库,您需要在其他地方设置忽略。webpack、tsconfig 等