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

Commit

Permalink
[docs] Fix prefer-while docs (#3888)
Browse files Browse the repository at this point in the history
- Updated docs to make sense semantically (use vars that should exist in the scope of each for-loop)
- Updated tests with same issue
  • Loading branch information
rwaskiewicz authored and giladgray committed May 10, 2018
1 parent 9132ace commit 681218d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/rules/code-examples/preferWhile.examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ export const codeExamples = [
"rules": { "prefer-while": true }
`,
pass: Lint.Utils.dedent`
for(let x = 1; x < 10; x++) {
console.log(x);
for(let i = 1; i < 10; i++) {
console.log(i);
}
for (let i = 0; i < 10; x+=1) {
console.log(x);
for (let i = 0; i < 10; i+=1) {
console.log(i);
}
for (let i = 0; i < 10;) {
Expand All @@ -39,11 +39,11 @@ export const codeExamples = [
`,
fail: Lint.Utils.dedent`
for(;;) {
console.log(x);
console.log('Hello World');
}
for(;true===true;) {
console.log(x);
console.log('Hello World');
}
`,
},
Expand Down
12 changes: 6 additions & 6 deletions test/rules/prefer-while/test.ts.fix
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// for loops without an initializer, termination condition, and incrementor should be updated
while (true) {
console.log(x);
console.log('Hello World');
}

// for loops without an initializer and incrementor should be updated
while (true===true) {
console.log(x);
console.log('Hello World');
}

// for loops with an initializer, termination condition, and incrementor using '++' should remain untouched
for(let x = 1; x < 10; x++) {
console.log(x);
for (let i = 1; i < 10; i++) {
console.log(i);
}

// for loops with an initializer, termination condition, and incrementor using '+=' should remain untouched
for (let i = 0; i < 10; x+=1) {
console.log(x);
for (let i = 0; i < 10; i+=1) {
console.log(i);
}

// for loops with an initializer and termination condition should remain untouched
Expand Down
12 changes: 6 additions & 6 deletions test/rules/prefer-while/test.ts.lint
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// for loops without an initializer, termination condition, and incrementor should be updated
for(;;) {
~~~~~~~ [Prefer `while` loops instead of `for` loops without an initializer and incrementor.]
console.log(x);
console.log('Hello World');
}

// for loops without an initializer and incrementor should be updated
for(;true===true;) {
~~~~~~~~~~~~~~~~~~ [Prefer `while` loops instead of `for` loops without an initializer and incrementor.]
console.log(x);
console.log('Hello World');
}

// for loops with an initializer, termination condition, and incrementor using '++' should remain untouched
for(let x = 1; x < 10; x++) {
console.log(x);
for (let i = 1; i < 10; i++) {
console.log(i);
}

// for loops with an initializer, termination condition, and incrementor using '+=' should remain untouched
for (let i = 0; i < 10; x+=1) {
console.log(x);
for (let i = 0; i < 10; i+=1) {
console.log(i);
}

// for loops with an initializer and termination condition should remain untouched
Expand Down

0 comments on commit 681218d

Please sign in to comment.