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

Commit

Permalink
Fixed whitespace rule for trivial for cases. (#3132)
Browse files Browse the repository at this point in the history
  • Loading branch information
WiseBird authored and ajafff committed Aug 15, 2017
1 parent 1197e15 commit b6e4328
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
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

0 comments on commit b6e4328

Please sign in to comment.