简体   繁体   English

如何忽略 tslint 的特定目录或文件?

[英]How to ignore a particular directory or file for tslint?

The IDE being used is WebStorm 11.0.3, the tslint is configured and works, but, it hangs because it tries to parse large *.d.ts library files.正在使用的 IDE 是 WebStorm 11.0.3,tslint 已配置并可以工作,但是由于它尝试解析大型 *.d.ts 库文件而挂起。

Is there a way to ignore a particular file or directory?有没有办法忽略特定的文件或目录?

Update for tslint v5.8.0 tslint v5.8.0更新

As mentioned by Saugat Acharya , you can now update tslint.json CLI Options:正如Saugat Acharya所提到的,您现在可以更新tslint.json CLI 选项:

{
  "extends": "tslint:latest",
  "linterOptions": {
      "exclude": [
          "bin",
          "lib/*generated.js"
      ]
  }
}

More information in this pull request .此拉取请求中的更多信息。


This feature has been introduced with tslint 3.6此功能已在tslint 3.6 中引入

tslint \"src/**/*.ts\" -e \"**/__test__/**\"

You can now add --exclude (or -e) see PR here.您现在可以添加 --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

you are looking at using你正在考虑使用

-e, --exclude         exclude globs from path expansion

Currently using Visual Studio Code and the command to disable tslint is当前使用 Visual Studio Code,禁用 tslint 的命令是

/* tslint:disable */

Something to note.有什么需要注意的。 The disable above disables ALL tslint rules on that page.上面的 disable 禁用该页面上的所有 tslint 规则。 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更深入地了解 TSLint 规则标志

In addition to Michael's answer, consider a second way: adding linterOptions.exclude to tslint.json除了迈克尔的回答,考虑第二种方法:将linterOptions.exclude添加到 tslint.json

For example, you may have tslint.json with following lines:例如,您可能有包含以下几行的tslint.json

{
  "linterOptions": {
    "exclude": [
      "someDirectory/*.d.ts"
    ]
  }
}

Starting from tslint v5.8.0 you can set an exclude property under your linterOptions key in your tslint.json file:tslint v5.8.0开始,您可以在tslint.json文件中的linterOptions键下设置exclude属性:

{
  "extends": "tslint:latest",
  "linterOptions": {
      "exclude": [
          "bin",
          "**/__test__",
          "lib/*generated.js"
      ]
  }
}

More information on this here .更多信息请点击此处

I had to use the **/* syntax to exclude the files in a folder:我不得不使用 **/* 语法来排除文件夹中的文件:

    "linterOptions": {
        "exclude": [
          "src/auto-generated/**/*",
          "src/app/auto-generated/**/*"
        ]
    },

There are others who encountered the problem.这里 别人谁碰到的问题。 Unfortunately, there is only an open issue for excluding files: https://github.com/palantir/tslint/issues/73不幸的是,排除文件只有一个未解决的问题: https : //github.com/palantir/tslint/issues/73

So I'm afraid the answer is no.所以恐怕答案是否定的。

linterOptions is currently only handled by the CLI. linterOptions 目前仅由 CLI 处理。 If you're not using CLI then depending on the code base you're using you'll need to set the ignore somewhere else.如果您不使用 CLI,那么根据您使用的代码库,您需要在其他地方设置忽略。 webpack, tsconfig, etc webpack、tsconfig 等

As an addition作为补充

To disable all rules for the next line // tslint:disable-next-line禁用下一行的所有规则// tslint:disable-next-line

To disable specific rules for the next line : // tslint:disable-next-line:rule1 rule2...禁用下一行的特定规则// tslint:disable-next-line:rule1 rule2...

To disable all rules for the current line : someCode(); // tslint:disable-line禁用当前行的所有规则someCode(); // tslint:disable-line someCode(); // tslint:disable-line

To disable specific rules for the current line : someCode(); // tslint:disable-line:rule1禁用当前行的特定规则someCode(); // tslint:disable-line:rule1 someCode(); // tslint:disable-line:rule1

Can confirm that on version tslint 5.11.0 it works by modifying lint script in package.json by defining exclude argument:可以确认在 tslint 5.11.0 版本上它可以通过定义 exclude 参数来修改 package.json 中的 lint 脚本:

"lint": "ng lint --exclude src/models/** --exclude package.json"

Cheers!!干杯!!

add the section in your code example在您的代码示例中添加该部分

"linterOptions": {
"exclude": [
  "node_modules/**/*.",
  "db/**/*.",
  "integrations/**/*."
]

}, },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM