diff --git a/src/rules/noInvalidTemplateStringsRule.ts b/src/rules/noInvalidTemplateStringsRule.ts index 850d295d0ed..85290c8fa52 100644 --- a/src/rules/noInvalidTemplateStringsRule.ts +++ b/src/rules/noInvalidTemplateStringsRule.ts @@ -54,7 +54,7 @@ function walk(ctx: Lint.WalkContext) { * Finds instances of '${' */ const findTemplateString = new RegExp(/\$\{/); - + const index = node.text.search(findTemplateString); if (index !== -1) { /** diff --git a/src/rules/whitespaceRule.ts b/src/rules/whitespaceRule.ts index 3eb6f30caaa..4e50eca8894 100644 --- a/src/rules/whitespaceRule.ts +++ b/src/rules/whitespaceRule.ts @@ -265,11 +265,24 @@ function walk(ctx: Lint.WalkContext) { } break; case ts.SyntaxKind.CommaToken: - case ts.SyntaxKind.SemicolonToken: if (options.separator) { prevTokenShouldBeFollowedByWhitespace = true; } break; + case ts.SyntaxKind.SemicolonToken: + if (!options.separator) { + break; + } + + const nextPosition = range.pos + 1; + const semicolonInTrivialFor = parent.kind === ts.SyntaxKind.ForStatement && + nextPosition !== sourceFile.end && + (sourceFile.text[nextPosition] === ";" || sourceFile.text[nextPosition] === ")"); + + if (!semicolonInTrivialFor) { + prevTokenShouldBeFollowedByWhitespace = true; + } + break; case ts.SyntaxKind.EqualsToken: if (options.decl && parent.kind !== ts.SyntaxKind.JsxAttribute) { prevTokenShouldBeFollowedByWhitespace = true; diff --git a/test/rules/whitespace/all/test.ts.fix b/test/rules/whitespace/all/test.ts.fix index 2c3ae4daa76..d050f5924e0 100644 --- a/test/rules/whitespace/all/test.ts.fix +++ b/test/rules/whitespace/all/test.ts.fix @@ -21,6 +21,9 @@ module M { goto: console.log("hi"); } + for (x = 2; x--;) {} + for (;;) {} + while (i < 1) { ++i; } diff --git a/test/rules/whitespace/all/test.ts.lint b/test/rules/whitespace/all/test.ts.lint index 583406ae5ad..abff917705a 100644 --- a/test/rules/whitespace/all/test.ts.lint +++ b/test/rules/whitespace/all/test.ts.lint @@ -43,6 +43,9 @@ module M { ~ [missing whitespace] } + for (x = 2; x--;) {} + for (;;) {} + while(i < 1){ ~ [missing whitespace] ~ [missing whitespace]