如何在TSLint中启用四斜杠开头的无空格注释?
Fixing TSLint's comment-format for Four-Slash Comments
Alright, let's get this sorted out. The issue with your current config is that "ignore-pattern": "//" isn't working because:
- In regular expressions,
//is treated as a comment, so that pattern is effectively invalid. - Even if it were valid, it would match any comment content containing
//, which is way too broad for your needs.
The Correct Configuration
To allow comments starting with //// to skip the space check, use this regex pattern in your TSLint config:
"comment-format": [ true, "check-space", { "ignore-pattern": "^//" } ]
How This Works
- The
^//regex matches comment content that starts with//(remember, for a////comment, the part after the initial//is//yourText). - This tells TSLint to skip the space check only for comments where the
//is immediately followed by another//(i.e.,////overall), which is exactly what you want. - Regular single-slash comments like
//yourTextwill still trigger the space check, keeping your code style consistent for non-special comments.
Example Valid/Invalid Cases
- ✅ Allowed:
////directCommentWithoutSpace(ignored by the rule) - ❌ Still errors:
//directCommentWithoutSpace(violates thecheck-spacerule) - ✅ Allowed:
// Comment with space(follows the rule)
内容的提问来源于stack exchange,提问作者Qwertiy
相关产品推荐
相关产品推荐

