This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[enhancement] show warnings for `var` [bugfix] correctly handle variables shadowed by parameters and catched exceptions [bugfix] don't warn if a variable in a for loop initializer can be const [bugfix] handle more cases in destructuring [bugfix] only fix initialized variables [new-rule-option] `{destructuring: "all"}` to only warn if all variables in a destructuring can be const
- Loading branch information
Showing
9 changed files
with
455 additions
and
182 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// this is not an external module | ||
// variables in the global scope are ignored by prefer-const | ||
let var1 = 0; | ||
let var2 = 0; | ||
{ | ||
let var2 = 1; | ||
{ | ||
var2 = 2; | ||
} | ||
var var3 = 0; | ||
{ | ||
let var3 = 1; | ||
var3 = 2; | ||
let var4 = 0; | ||
~~~~ [Identifier 'var4' is never reassigned; use 'const' instead of 'let'.] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[typescript]: >= 2.1.0 | ||
{ | ||
let d1 = 0; | ||
let d2 = 0; | ||
let d3 = 0; | ||
let d4 = 0; | ||
[(d1), ([d2]), ...[d3 = 1, ...(d4)]] = []; | ||
} | ||
|
||
{ | ||
let d1 = 0; | ||
let d2 = 0; | ||
let d3 = 0; | ||
let d4 = 0; | ||
let d5 = 0; | ||
({ | ||
d1 = 2, | ||
foo: d2, | ||
bar: { | ||
...d3 | ||
}, | ||
baz: {d4} = {}, | ||
...(d5), | ||
} = {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export let foo = 1; | ||
// destructuring | ||
{ | ||
let destructLater = 4; | ||
[destructLater] = 5; | ||
let a: number; | ||
let b: number; | ||
let c: any; | ||
({ eh: a, b, ...c } = { eh: 0, b: 1 }); | ||
} | ||
|
||
let {h, i} = {h: 1, i: 1}; // 'h' can be const | ||
let [j, k] = [1, 1]; // 'j' can be const | ||
let [x1, x3] = [1, 2], [x2] = [3]; // failure for x1, x3 | ||
let {a: {b: {q}, c: {r}}} = { a: { b: { q: 3 }, c: { r: 2 } } }; // 'r' can be const | ||
i = 2; | ||
k = 2; | ||
q = 4; | ||
x2 = 5; | ||
|
||
for (let {o, p} of [{1, 1}, {1, 1}]) { // 'o' can be const | ||
console.log(o); | ||
p = 2; | ||
} | ||
|
||
{ | ||
const [d1, d2] = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export let foo = 1; | ||
// destructuring | ||
{ | ||
let destructLater = 4; | ||
[destructLater] = 5; | ||
let a: number; | ||
let b: number; | ||
let c: any; | ||
({ eh: a, b, ...c } = { eh: 0, b: 1 }); | ||
} | ||
|
||
let {h, i} = {h: 1, i: 1}; // 'h' can be const | ||
let [j, k] = [1, 1]; // 'j' can be const | ||
let [x1, x3] = [1, 2], [x2] = [3]; // failure for x1, x3 | ||
~~ [Identifier 'x1' is never reassigned; use 'const' instead of 'let'.] | ||
~~ [Identifier 'x3' is never reassigned; use 'const' instead of 'let'.] | ||
let {a: {b: {q}, c: {r}}} = { a: { b: { q: 3 }, c: { r: 2 } } }; // 'r' can be const | ||
i = 2; | ||
k = 2; | ||
q = 4; | ||
x2 = 5; | ||
|
||
for (let {o, p} of [{1, 1}, {1, 1}]) { // 'o' can be const | ||
console.log(o); | ||
p = 2; | ||
} | ||
|
||
{ | ||
let [d1, d2] = []; | ||
~~ [Identifier 'd1' is never reassigned; use 'const' instead of 'let'.] | ||
~~ [Identifier 'd2' is never reassigned; use 'const' instead of 'let'.] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"rules": { | ||
"prefer-const": [ | ||
true, | ||
{"destructuring": "all"} | ||
] | ||
} | ||
} |