【问题标题】:Stop TSLint removing leading spaces within a HTML element停止 TSLint 删除 HTML 元素中的前导空格
【发布时间】:2019-06-11 14:01:39
【问题描述】:

如何在 VSCode 中配置 TSLint 以不重新格式化我的代码?我不想完全禁用 TSLint 我只想停止它所做的一件事。 我想在 html 标记中保留前导缩进。

        <ng-template [ngIf]="($eventsCount | async) > 0">
            <a href=""
                *ngIf="!($isClosing | async)"
                class="btn--danger"
                confirm="Are you sure?"
                (confirmed)="onCloseAll()">
                Close All
            </a>
        </ng-template>

当我保存上述代码时,TSLint(在 VSCode 中)将其重新格式化为:

        <ng-template [ngIf]="($eventsCount | async) > 0">
            <a href="" *ngIf="!($isClosing | async)" class="btn--danger" confirm="Are you sure?" (confirmed)="onCloseAll()">
                Close All
            </a>
        </ng-template>

我需要在 TSLint 中更改什么规则以阻止它删除我的角度组件 html 中的前导空格?

TSLint 版本:5.9.1

谢谢

【问题讨论】:

标签: html visual-studio-code tslint linter


【解决方案1】:

这不是 TSLint - 这可能是 VS Code 中默认的 HTML 格式化程序。您可能将 formatOnSave 设置为 true,您可以完全禁用它,或者对某些文件类型:

"editor.formatOnSave": true
  "[html]": {
    "editor.formatOnSave": false
}

不过我建议您查看Prettier,他们最近发布了一个功能异常强大/可配置的 HTML 格式化程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 2020-02-24
    • 2018-03-31
    • 2018-07-08
    相关资源
    最近更新 更多