【问题标题】:How to disable Rule: one-line in TSLint如何禁用规则:TSLint 中的单行
【发布时间】:2019-05-12 12:32:15
【问题描述】:
 clearFile()
 {
      (<HTMLInputElement>document.getElementById('uploadFile')).value = "";
 }

[tslint] misplaced opening brace

.

如果我在同一行函数中使用左大括号,它不会像这样给我警告

clearFile(){
      (<HTMLInputElement>document.getElementById('uploadFile')).value = "";
 }

此规则称为“单行”规则 以及如何在 TSLint 中配置它以处理第一种大括号样式

提前致谢

【问题讨论】:

    标签: tslint


    【解决方案1】:

    如果你想全局打开 Goto {ProjectDirectoty}/tslint.json 并在规则中添加 "one-line" : false

    一行有 5 个子规则,分别是“check-catch”、“check-finally”、“check-else”、“check-open-brace”、“check-whitespace”。您可以从名称中理解它,例如对于 catch 您应该或不应该在同一行或下一行写左大括号。

    {
    "extends": "../tslint.json",
    "rules": {
        "one-line" : false,
        "directive-selector": [
            true,
            "attribute",
            "app",
            "camelCase"
        ],
        "component-selector": [
            true,
            "element",
            "app",
            "kebab-case"
        ]
    }
    

    }

    如果您只想关闭特定的子规则,请使用类似的内容

    "one-line": [true, "check-catch", "check-finally", "check-else"]
    

    这 3 条规则会开启,其他 2 条规则会关闭

    如果你想在特定文件中禁用

    /* tslint:disable:rule1 rule2 rule3... */ in that file
    

    【讨论】:

      猜你喜欢
      • 2016-05-17
      • 2018-04-12
      • 2020-07-24
      • 2022-11-03
      • 2019-09-18
      • 2019-06-01
      • 2020-02-26
      • 2019-12-26
      • 2017-09-22
      相关资源
      最近更新 更多