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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34578677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:34:57  来源:igfitidea点击:

How to ignore a particular directory or file for tslint?

javascriptidetypescriptwebstormtslint

提问by user3330840

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?

有没有办法忽略特定的文件或目录?

回答by Michael

Update for tslint v5.8.0

tslint v5.8.0更新

As mentioned by Saugat Acharya, you can now update tslint.jsonCLI Options:

正如Saugat Acharya所提到的,您现在可以更新tslint.jsonCLI 选项:

{
  "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 PRhere.

您现在可以添加 --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

回答by DeadlyChambers

Currently using Visual Studio Code and the command to disable tslint is

当前使用 Visual Studio Code,禁用 tslint 的命令是

/* tslint:disable */

/* tslint:disable */

worked for me. Check out this page, about 3/4 of the way down there are some disable commands https://c9.io/lijunle/tslint

为我工作。查看此页面,大约向下的 3/4 处有一些禁用命令https://c9.io/lijunle/tslint

Something to note. The disable above disables ALL tslint rules on that page. If you want to disable a specific rule half way down the page there is a list of rules. So you can turn off specific things such as

有什么需要注意的。上面的 disable 禁用该页面上的所有 tslint 规则。如果您想在页面下方禁用特定规则,则有一个规则列表。所以你可以关闭特定的东西,比如

/* tslint:disable comment-format */

回答by arkhwise

In addition to Michael's answer, consider a second way: adding linterOptions.excludeto tslint.json

除了迈克尔的回答,考虑第二种方法:将linterOptions.exclude添加到 tslint.json

For example, you may have tslint.jsonwith following lines:

例如,您可能有tslint.json以下几行:

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

回答by Saugat

Starting from tslint v5.8.0you can set an excludeproperty under your linterOptionskey in your tslint.jsonfile:

tslint v5.8.0您可以在文件中excludelinterOptions密钥下设置属性开始tslint.json

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

More information on this here.

更多信息请点击此处

回答by Martin Vseticka

There areotherswho 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.

所以恐怕答案是否定的。

回答by techguy2000

I had to use the **/* syntax to exclude the files in a folder:

我不得不使用 **/* 语法来排除文件夹中的文件:

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

回答by Kris

linterOptions is currently only handled by the 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. webpack, tsconfig, etc

linterOptions 目前仅由 CLI 处理。如果您不使用 CLI,那么根据您使用的代码库,您需要在其他地方设置忽略。webpack、tsconfig 等

回答by Sanid Sa

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!!

干杯!!

回答by AlbertK

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

To disable specific rules for the current line: someCode(); // tslint:disable-line:rule1

禁用当前行的特定规则someCode(); // tslint:disable-line:rule1