Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Update comment-format/check-uppercase to ignore rule flags (fixes #1417) #1473

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/rules/commentFormatRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CommentWalker extends Lint.SkippableTokenAwareRuleWalker {
}
}
if (this.hasOption(OPTION_UPPERCASE)) {
if (!startsWithUppercase(commentText)) {
if (!startsWithUppercase(commentText) && !isRuleFlag(commentText)) {
const uppercaseFailure = this.createFailure(startPosition, width, Rule.UPPERCASE_FAILURE);
this.addFailure(uppercaseFailure);
}
Expand Down Expand Up @@ -138,3 +138,10 @@ function startsWithSpace(commentText: string) {
// three slashes (///) also works, to allow for ///<reference>
return firstCharacter === " " || firstCharacter === "/";
}

function isRuleFlag(commentText: string): boolean {
// regex is: start of string followed by "/*" or "//"
// followed by any amount of whitespace followed by "tslint:"
// followed by either "enable" or "disable"
return /^(\/\*|\/\/)\s*tslint:(enable|disable)/.test(commentText);
}
13 changes: 13 additions & 0 deletions test/rules/comment-format/upper/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,18 @@ class Clazz { // This comment is correct

`${location.protocol}//${location.hostname}`

// tslint should show error here
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [upper]

// tslint: not a rule flag
~~~~~~~~~~~~~~~~~~~~~~~~ [upper]

//tslint:disable-next-line:no-unused-expression
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [space]
class Invalid {}

// tslint:disable-next-line:no-unused-expression
class Valid {}

[upper]: comment must start with uppercase letter
[space]: comment must start with a space