TSLint 摆脱缺失的空白

TSLint get rid of missing-whitespace

我一直在网上搜索以解决此问题,但无济于事。也许你能帮助我。我收到 tslint 'missing whitespace' 警告,内容如下:

./src/app/content/content.controller.ts 中的警告 [4, 13]: 缺少白色space [5, 21]: 缺少白色space

我想去掉警告

这是代码示例...。基本上,只要我用冒号声明类型,就会发生错误。我不想在它之间放一个 space 所以我希望 linter 不会打扰我...

export class ContentCtrl {
filters:IFilter[];
selectedFilters:IFilter[];
filterToAdd:IFilter;

/** @ngInject */
constructor(private $log:angular.ILogService,
            private $timeout:any,
            private toastr:any,
            private filterService:FilterService) {
    const self = this;

我查看了 tslint.json 文件,但不知道如何删除它。

我看到一个很有前途的 属性 说:"typedef-whitespace"

我将其更改为以下内容,但是没有用:

"typedef-whitespace": [true,
        {
            "callSignature": "noSpace",
            "catchClause": "noSpace",
            "indexSignature": "noSpace",
            "parameter": "noSpace"
        }
    ],

如何消除 'missing whitespace' 错误?

TSLint 似乎抱怨的是 class 属性 声明,所以也许可以尝试将此额外规则添加到 "typedef-whitespace":

"property-declaration": "nospace",

您可以找到有关该规则的更多信息 here

此错误消息来自 whitespace rule。我相信该规则希望您在类型声明中的冒号之前或之后(不确定是哪个)添加 space 。但是,如果您不喜欢这样,您可以完全禁用该规则,或者从您的 tslint.json 文件中删除 check-type 选项。

您应该在 tslint.json 中搜索 whitespace,并将所有结果替换为 false

你的问题可以像这样设置:

"whitespace": [
  false,
  "check-branch",
  "check-decl",
  "check-operator",
  "check-separator",
  "check-type"
],

设置它,如果你写private nima:string,:没有space不会出错。


其他,

如果您将 one-line 的元数据设置为 false,则 class 不能跟在 space.

之后

如果您将no-trailing-whitespace设置为false,该行可以使用制表符。

——结束