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

Commit

Permalink
Allow enabling/disabling tslint using single line comments. (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
mprobst authored and jkillian committed Apr 18, 2016
1 parent 702ebd3 commit f94adea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/enableDisableRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker {
return;
}

if (scanner.getToken() === ts.SyntaxKind.MultiLineCommentTrivia) {
if (scanner.getToken() === ts.SyntaxKind.MultiLineCommentTrivia ||
scanner.getToken() === ts.SyntaxKind.SingleLineCommentTrivia) {
const commentText = scanner.getTokenText();
const startPosition = scanner.getTokenPos();
this.handlePossibleTslintSwitch(commentText, startPosition);
Expand All @@ -45,8 +46,8 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker {
}

private handlePossibleTslintSwitch(commentText: string, startingPosition: number) {
// regex is: start of string followed by "/*" followed by any amount of whitespace followed by "tslint:"
if (commentText.match(/^\/\*\s*tslint:/)) {
// regex is: start of string followed by "/*" or "//" followed by any amount of whitespace followed by "tslint:"
if (commentText.match(/^(\/\*|\/\/)\s*tslint:/)) {
const commentTextParts = commentText.split(":");
// regex is: start of string followed by either "enable" or "disable"
// followed by either whitespace or end of string
Expand Down
4 changes: 4 additions & 0 deletions test/files/enabledisable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ var AAAaA = 'test'
var re;
re = /`/;

// tslint:disable
var AAAaA = 'test'
// tslint:enable

/* tslint:disable:quotemark */
var s = 'xxx';

0 comments on commit f94adea

Please sign in to comment.