【发布时间】:2016-04-07 07:54:21
【问题描述】:
正在使用的 IDE 是 WebStorm 11.0.3,tslint 已配置并且可以工作,但是它挂起,因为它尝试解析大型 *.d.ts 库文件。
有没有办法忽略特定的文件或目录?
【问题讨论】:
标签: javascript ide typescript webstorm tslint
正在使用的 IDE 是 WebStorm 11.0.3,tslint 已配置并且可以工作,但是它挂起,因为它尝试解析大型 *.d.ts 库文件。
有没有办法忽略特定的文件或目录?
【问题讨论】:
标签: javascript ide typescript webstorm tslint
有areothers谁遇到了问题。不幸的是,排除文件只有一个未解决的问题:https://github.com/palantir/tslint/issues/73
所以恐怕答案是否定的。
【讨论】:
正如Saugat Acharya 所述,您现在可以更新 tslint.json CLI 选项:
{
"extends": "tslint:latest",
"linterOptions": {
"exclude": [
"bin",
"lib/*generated.js"
]
}
}
更多信息in this pull request.
此功能已通过tslint 3.6 引入
tslint \"src/**/*.ts\" -e \"**/__test__/**\"
您现在可以在此处添加 --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
你正在考虑使用
-e, --exclude exclude globs from path expansion
【讨论】:
linterOptions而不是cliOptions
tslint.json
目前使用Visual Studio Code,禁用tslint的命令是
/* tslint: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"
]
}
}
有关此here 的更多信息。
【讨论】:
cliOptions替换为linterOptions。
linterOptions 当前仅由 CLI 处理。 如果您不使用 CLI,则根据您使用的代码库,您需要在其他地方设置忽略。 webpack、tsconfig 等
【讨论】:
我必须使用 **/* 语法来排除文件夹中的文件:
"linterOptions": {
"exclude": [
"src/auto-generated/**/*",
"src/app/auto-generated/**/*"
]
},
【讨论】:
可以通过定义排除参数来修改 package.json 中的 lint 脚本来确认在 tslint 5.11.0 版本上它可以工作:
"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/**/*."
]
},
【讨论】: