TSLint: comment must start with a space (comment-format)

使用AngularCli创建项目后。

TypeScript报错:

TSLint: comment must start with a space (comment-format)

 

注释必须从一个空格开始(comment-format)

 

也就是说//之后必须跟随一个空格。

 

TSLint是一个TypeScript验证工具,用于检测代码。

 

在项目下的tslint.json中定义。AngularCli自动生成的规则很严格。

 

如何取消这个错误?

除了按照规范在//之后加一个空格即可。

 

另一个方法是,tslint.json中配置,放宽检测条件。

根据错误提示最后的(comment-format),知道这个错误在tslint.json是由comment-format属性控制的。so,打开tslint.json:

 

 

 "comment-format": [
      true,
      "check-space"
    ],


改为false即可。

 

 

tslint所有规则:https://palantir.github.io/tslint/rules/

 

-----------------------------------------------------------------------------

 

comment-format规则:

 

规则:注释格式

 

执行单行注释的格式化规则。

合理

帮助您在代码库中保持一致,可读的风格。

配置

可以提供三个参数:

  • "check-space" 要求所有单行注释必须以空格开头 // comment
    • 请注意,对于以多个斜线开头的注释,例如///,忽略前导斜杠
    • TypeScript 引用注释被完全忽略
  • "check-lowercase" 要求注释的第一个非空白字符必须为小写(如果适用)。
  • "check-uppercase" 要求注释的第一个非空白字符必须是大写(如果适用)。

可以作为最后一个参数传递的对象的异常"check-lowercase""check-uppercase"可以管理。

这个对象可以提供两个选项之一:

* `"ignore-words"`  - array of strings - words that will be ignored at the beginning of the comment.
* `"ignore-pattern"` - string - RegExp pattern that will be ignored at the beginning of the comment.

例子

“comment-format”:[true,“check-space”,“check-bigcase”]
“comment-format”:[true,“check-smallcase”,{“ignore-words”:[“TODO”,“HACK”]}]
“comment-format”:[true,“check-smallcase”,{“ignore-pattern”:“STD \\ w {2,3} \\ b”}]

样板

{
  "type": "array",
  "items": {
    "anyOf": [
      {
        "type": "string",
        "enum": [
          "check-space",
          "check-lowercase",
          "check-uppercase"
        ]
      },
      {
        "type": "object",
        "properties": {
          "ignore-words": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "ignore-pattern": {
            "type": "string"
          }
        },
        "minProperties": 1,
        "maxProperties": 1
      }
    ]
  },
  "minLength": 1,
  "maxLength": 4
}

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值