使用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 }
