使用的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__/**\"
您现在可以添加--exclude(或-e),请参见PR。
命令行界面
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
Currently using Visual Studio Code and the command to disable tslint is
/* tslint:disable */
Something to note. The disable above disables ALL tslint rules on that page. If you want to disable a specific rule you can specify one/multiple rules.
/* tslint:disable comment-format */
/* tslint:disable:rule1 rule2 rule3 etc.. */
Or enable a rule
/* tslint:enable comment-format */
More in depth on TSLint rule flags
除了Michael的答案之外,请考虑第二种方法:向tslint.json添加linterOptions.exclude
例如,您可能有tslint.json
以下几行:
{
"linterOptions": {
"exclude": [
"someDirectory/*.d.ts"
]
}
}
从开始,tslint v5.8.0
您可以在文件exclude
的linterOptions
密钥下设置属性tslint.json
:
{
"extends": "tslint:latest",
"linterOptions": {
"exclude": [
"bin",
"**/__test__",
"lib/*generated.js"
]
}
}
更多信息请参见这里。
这里是 别人谁碰到的问题。不幸的是,排除文件只有一个公开的问题:https : //github.com/palantir/tslint/issues/73
因此,恐怕答案是否定的。
我必须使用** / *语法来排除文件夹中的文件:
"linterOptions": {
"exclude": [
"src/auto-generated/**/*",
"src/app/auto-generated/**/*"
]
},
linterOptions当前仅由CLI处理。如果不使用CLI,则根据所使用的代码库,您需要在其他位置设置忽略。webpack,tsconfig等
可以在tslint 5.11.0版本上通过定义exclude参数修改package.json中的lint脚本来确认其工作正常:
"lint": "ng lint --exclude src/models/** --exclude package.json"
干杯!!
作为补充
禁用下一行的所有规则 // tslint:disable-next-line
要禁用下一行的特定规则:// tslint:disable-next-line:rule1 rule2...
要禁用当前行的所有规则:someCode(); // tslint:disable-line
要禁用当前行的特定规则:someCode(); // tslint:disable-line:rule1
在代码示例中添加该部分
"linterOptions": {
"exclude": [
"node_modules/**/*.",
"db/**/*.",
"integrations/**/*."
]
},
文章标签:ide , javascript , tslint , typescript , webstorm
版权声明:本文为原创文章,版权归 javascript 所有,欢迎分享本文,转载请保留出处!
评论已关闭!