【问题标题】:How to ignore a particular directory or file for tslint?如何忽略 tslint 的特定目录或文件?
【发布时间】:2016-04-07 07:54:21
【问题描述】:

正在使用的 IDE 是 WebStorm 11.0.3,tslint 已配置并且可以工作,但是它挂起,因为它尝试解析大型 *.d.ts 库文件。

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

【问题讨论】:

    标签: javascript ide typescript webstorm tslint


    【解决方案1】:

    areothers谁遇到了问题。不幸的是,排除文件只有一个未解决的问题:https://github.com/palantir/tslint/issues/73

    所以恐怕答案是否定的。

    【讨论】:

      【解决方案2】:

      tslint v5.8.0更新

      正如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
      • 还值得一提的是,exclude 目录中的 glob 模式应该是相对于tslint.json
      【解决方案3】:

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

      /* tslint:disable */
      

      注意事项。上面的禁用会禁用该页面上的所有 tslint 规则。如果要禁用特定规则,可以指定一个/多个规则。

      /* tslint:disable comment-format */
      /* tslint:disable:rule1 rule2 rule3 etc.. */
      

      或启用规则

      /* tslint:enable comment-format */
      

      More in depth on TSLint rule flags

      【讨论】:

      • 从所有答案中,这是唯一有效的答案。谢谢!
      【解决方案4】:

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

      例如,您的tslint.json 可能包含以下几行:

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

      【讨论】:

        【解决方案5】:

        tslint v5.8.0 开始,您可以在tslint.json 文件中的linterOptions 键下设置exclude 属性:

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

        有关此here 的更多信息。

        【讨论】:

        • 这应该被标记为正确的(并于 2017 年 11 月更新)答案。
        • 正确的做法是将cliOptions替换为linterOptions
        【解决方案6】:

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

        【讨论】:

          【解决方案7】:

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

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

          【讨论】:

            【解决方案8】:

            可以通过定义排除参数来修改 package.json 中的 lint 脚本来确认在 tslint 5.11.0 版本上它可以工作:

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

            干杯!!

            【讨论】:

            • 您是指其他答案,还是只是想为该问题提供替代答案?
            【解决方案9】:

            作为补充

            禁用下一行的所有规则 // tslint:disable-next-line

            要禁用下一行的特定规则// tslint:disable-next-line:rule1 rule2...

            禁用当前行的所有规则someCode(); // tslint:disable-line

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

            【讨论】:

              【解决方案10】:

              在您的代码示例中添加该部分

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

              },

              【讨论】:

                猜你喜欢
                • 2016-08-22
                • 2020-03-14
                • 1970-01-01
                • 2019-08-10
                • 2017-01-27
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2017-05-10
                相关资源
                最近更新 更多