diff --git a/src/rules/commentFormatRule.ts b/src/rules/commentFormatRule.ts index 3742141e7f5..87efe6663a0 100644 --- a/src/rules/commentFormatRule.ts +++ b/src/rules/commentFormatRule.ts @@ -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); } @@ -138,3 +138,10 @@ function startsWithSpace(commentText: string) { // three slashes (///) also works, to allow for /// 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); +} diff --git a/test/rules/comment-format/upper/test.ts.lint b/test/rules/comment-format/upper/test.ts.lint index 9ed5955f23b..c94e6226882 100644 --- a/test/rules/comment-format/upper/test.ts.lint +++ b/test/rules/comment-format/upper/test.ts.lint @@ -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