[英]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.