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

Fixed whitespace rule for trivial for cases. #3132

Merged
merged 3 commits into from
Aug 15, 2017
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
2 changes: 1 addition & 1 deletion src/rules/noInvalidTemplateStringsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function walk(ctx: Lint.WalkContext<void>) {
* Finds instances of '${'
*/
const findTemplateString = new RegExp(/\$\{/);

const index = node.text.search(findTemplateString);
if (index !== -1) {
/**
Expand Down
15 changes: 14 additions & 1 deletion src/rules/whitespaceRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,24 @@ function walk(ctx: Lint.WalkContext<Options>) {
}
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;
Expand Down
3 changes: 3 additions & 0 deletions test/rules/whitespace/all/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module M {
goto: console.log("hi");
}

for (x = 2; x--;) {}
for (;;) {}

while (i < 1) {
++i;
}
Expand Down
3 changes: 3 additions & 0 deletions test/rules/whitespace/all/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ module M {
~ [missing whitespace]
}

for (x = 2; x--;) {}
for (;;) {}

while(i < 1){
~ [missing whitespace]
~ [missing whitespace]
Expand Down