使用的IDE是WebStorm 11.0.3,已经配置并启用了tslint,但是因为尝试解析较大的*.d.ts库文件,导致卡顿。
有没有一种方法可以忽略特定的文件或目录?
使用的IDE是WebStorm 11.0.3,已经配置并启用了tslint,但是因为尝试解析较大的*.d.ts库文件,导致卡顿。
有没有一种方法可以忽略特定的文件或目录?
正如Saugat Acharya所提到的,您现在可以更新tslint.json CLI选项:
{
"extends": "tslint:latest",
"linterOptions": {
"exclude": [
"bin",
"lib/*generated.js"
]
}
}
更多信息 在此拉取请求中。
这个功能是在 tslint 3.6 中引入的。
tslint \"src/**/*.ts\" -e \"**/__test__/**\"
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
您正在考虑使用
-e, --exclude exclude globs from path expansion
目前使用的是Visual Studio Code,禁用tslint的命令是
/* tslint:disable */
需要注意的是,上面的“disable”禁用了该页面上的所有tslint规则。如果要禁用特定的规则,则可以指定一个/多个规则。
/* tslint:disable comment-format */
/* tslint:disable:rule1 rule2 rule3 etc.. */
或者启用一个规则
/* tslint:enable comment-format */
/* tslint:disable:TS2322 */
没有起作用。你确定你可以在第二个代码块中忽略规则吗? - Bullsized除了Michael的回答,还可以考虑第二种方法:在tslint.json中添加linterOptions.exclude。
例如,您可能有以下行的tslint.json
:
{
"linterOptions": {
"exclude": [
"someDirectory/*.d.ts"
]
}
}
从 tslint v5.8.0
开始,您可以在 tslint.json
文件中的 linterOptions
键下设置一个 exclude
属性:
{
"extends": "tslint:latest",
"linterOptions": {
"exclude": [
"bin",
"**/__test__",
"lib/*generated.js"
]
}
}
关于这个更多信息在此处。
cliOptions
替换为 linterOptions
。 - Saugat我必须使用 **/* 语法来排除文件夹中的文件:
"linterOptions": {
"exclude": [
"src/auto-generated/**/*",
"src/app/auto-generated/**/*"
]
},
// tslint:disable-next-line
要禁用下一行的特定规则// tslint:disable-next-line:rule1 rule2...
要禁用当前行的所有规则someCode(); // tslint:disable-line
要禁用当前行的特定规则someCode(); // tslint:disable-line:rule1
有其他人遇到了这个问题。不幸的是,目前只有一个开放的问题可以排除文件:https://github.com/palantir/tslint/issues/73
所以恐怕答案是否定的。
linterOptions目前只由CLI处理。如果您没有使用CLI,则根据您使用的代码库,您需要在其他地方设置忽略。webpack、tsconfig等。
可以确认,在tslint 5.11.0版本中,通过在package.json文件的lint脚本中定义exclude参数来修改它可以正常运行:
"lint": "ng lint --exclude src/models/** --exclude package.json"
干杯!!
将这个部分添加到您的代码示例中
"linterOptions": {
"exclude": [
"node_modules/**/*.",
"db/**/*.",
"integrations/**/*."
]
},
linterOptions
而不是cliOptions
。 - JeB