代码之家  ›  专栏  ›  技术社区  ›  ANKIT HALDAR

自动修复TSLint警告

  •  81
  • ANKIT HALDAR  · 技术社区  · 8 年前
        [64, 1]: space indentation expected
        [15, 27]: Missing semicolon
        [109, 36]: missing whitespace
        [111, 24]: missing whitespace
        [70, 1]: Consecutive blank lines are forbidden
    

    我一直收到来自TSLint的类似警告。有大量警告,手动修复将非常困难。

    自动修复

    6 回复  |  直到 7 年前
        1
  •  144
  •   JKillian    8 年前

    您可以使用 --fix option

    tslint --fix -c ./config/tslint.json 'src/**/*{.ts,.tsx}'
    

    1. 提交对代码所做的更改
    2. 使用 类似上面的标志
    3. 快速回顾TSLint所做的更改

    这样,你永远不会被一个错误的恶意自动更正所震惊。

        2
  •  24
  •   ANKIT HALDAR    8 年前
    tslint --fix --project ./tsconfig.json
    

    这是自动修复所有错误的根文件夹

        3
  •  13
  •   splash    5 年前

    通过@angular/cli,您可以使用 ng lint --fix

        4
  •  9
  •   Viswa    5 年前

    也许这可以帮助一些人寻找自动修复保存!

      "source.fixAll.tslint": true
    

    更新后,转到任何文件并尝试提供一些空格,它将tslint警告消息显示为“尾随空格”,当您保存(Ctrl+S)时,此警告将消失。虽然它是手动显示的,但我们通常倾向于在编辑后尝试保存文件,到那时它将自动修复。

    快乐的编码!

        5
  •  4
  •   Gregor Albert    6 年前

    如果您使用 WebStrom公司 ,则可以在中创建文件观察程序

    enter image description here

    保存时( ),将修复当前文件。

        6
  •  3
  •   Caal Saal VI    7 年前

    如果您使用的是webpack。您可以使用tslint loader:

    {
        test: /\.ts$/,
        loader: 'tslint-loader',
        enforce: 'pre',
        options: {
          fix: true
        }
      }
    

    请在此处阅读更多信息: tslint-loader

    推荐文章