[英]How to ignore a particular directory or file for tslint?
正在使用的 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
当前使用 Visual Studio Code,禁用 tslint 的命令是
/* tslint:disable */
有什么需要注意的。 上面的 disable 禁用该页面上的所有 tslint 规则。 如果您想禁用特定规则,您可以指定一个/多个规则。
/* tslint:disable comment-format */
/* tslint:disable:rule1 rule2 rule3 etc.. */
或启用规则
/* tslint:enable comment-format */
除了迈克尔的回答,考虑第二种方法:将linterOptions.exclude添加到 tslint.json
例如,您可能有包含以下几行的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"
]
}
}
更多信息请点击此处。
我不得不使用 **/* 语法来排除文件夹中的文件:
"linterOptions": {
"exclude": [
"src/auto-generated/**/*",
"src/app/auto-generated/**/*"
]
},
这里是 别人谁碰到的问题。 不幸的是,排除文件只有一个未解决的问题: https : //github.com/palantir/tslint/issues/73
所以恐怕答案是否定的。
linterOptions 目前仅由 CLI 处理。 如果您不使用 CLI,那么根据您使用的代码库,您需要在其他地方设置忽略。 webpack、tsconfig 等
作为补充
禁用下一行的所有规则// tslint:disable-next-line
禁用下一行的特定规则: // tslint:disable-next-line:rule1 rule2...
禁用当前行的所有规则: someCode(); // tslint:disable-line
someCode(); // tslint:disable-line
禁用当前行的特定规则: someCode(); // tslint:disable-line:rule1
someCode(); // tslint:disable-line:rule1
可以确认在 tslint 5.11.0 版本上它可以通过定义 exclude 参数来修改 package.json 中的 lint 脚本:
"lint": "ng lint --exclude src/models/** --exclude package.json"
干杯!!
在您的代码示例中添加该部分
"linterOptions": {
"exclude": [
"node_modules/**/*.",
"db/**/*.",
"integrations/**/*."
]
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.