Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(scope-manager): fix assertion assignments not being marked as wri…
- Loading branch information
1 parent
14bdc2e
commit fa68492
Showing
9 changed files
with
253 additions
and
6 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/eslint-plugin/tests/eslint-rules/prefer-const.test.ts
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,24 @@ | ||
import rule from 'eslint/lib/rules/prefer-const'; | ||
import { RuleTester } from '../RuleTester'; | ||
|
||
const ruleTester = new RuleTester({ | ||
parser: '@typescript-eslint/parser', | ||
}); | ||
|
||
ruleTester.run('prefer-const', rule, { | ||
valid: [ | ||
` | ||
let x: number | undefined = 1; | ||
x! += 1; | ||
`, | ||
` | ||
let x: number | undefined = 1; | ||
(<number>x) += 1; | ||
`, | ||
` | ||
let x: number | undefined = 1; | ||
(x as number) += 1; | ||
`, | ||
], | ||
invalid: [], | ||
}); |
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
2 changes: 2 additions & 0 deletions
2
packages/scope-manager/tests/fixtures/type-assertion/assignment/angle-bracket-assignment.ts
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,2 @@ | ||
let x: number | undefined = 1; | ||
(<number>x) += 1; |
62 changes: 62 additions & 0 deletions
62
...s/scope-manager/tests/fixtures/type-assertion/assignment/angle-bracket-assignment.ts.shot
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,62 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`type-assertion assignment angle-bracket-assignment 1`] = ` | ||
ScopeManager { | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2 { | ||
defs: Array [ | ||
VariableDefinition$1 { | ||
name: Identifier<"x">, | ||
node: VariableDeclarator$1, | ||
}, | ||
], | ||
name: "x", | ||
references: Array [ | ||
Reference$1 { | ||
identifier: Identifier<"x">, | ||
init: true, | ||
isRead: false, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: true, | ||
resolved: Variable$2, | ||
writeExpr: Literal$2, | ||
}, | ||
Reference$2 { | ||
identifier: Identifier<"x">, | ||
init: false, | ||
isRead: true, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: true, | ||
resolved: Variable$2, | ||
writeExpr: Literal$3, | ||
}, | ||
], | ||
isValueVariable: true, | ||
isTypeVariable: false, | ||
}, | ||
], | ||
scopes: Array [ | ||
GlobalScope$1 { | ||
block: Program$4, | ||
isStrict: false, | ||
references: Array [ | ||
Reference$1, | ||
Reference$2, | ||
], | ||
set: Map { | ||
"const" => ImplicitGlobalConstTypeVariable, | ||
"x" => Variable$2, | ||
}, | ||
type: "global", | ||
upper: null, | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2, | ||
], | ||
}, | ||
], | ||
} | ||
`; |
2 changes: 2 additions & 0 deletions
2
packages/scope-manager/tests/fixtures/type-assertion/assignment/as-assignment.ts
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,2 @@ | ||
let x: number | undefined = 1; | ||
(x as number) += 1; |
62 changes: 62 additions & 0 deletions
62
packages/scope-manager/tests/fixtures/type-assertion/assignment/as-assignment.ts.shot
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,62 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`type-assertion assignment as-assignment 1`] = ` | ||
ScopeManager { | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2 { | ||
defs: Array [ | ||
VariableDefinition$1 { | ||
name: Identifier<"x">, | ||
node: VariableDeclarator$1, | ||
}, | ||
], | ||
name: "x", | ||
references: Array [ | ||
Reference$1 { | ||
identifier: Identifier<"x">, | ||
init: true, | ||
isRead: false, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: true, | ||
resolved: Variable$2, | ||
writeExpr: Literal$2, | ||
}, | ||
Reference$2 { | ||
identifier: Identifier<"x">, | ||
init: false, | ||
isRead: true, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: true, | ||
resolved: Variable$2, | ||
writeExpr: Literal$3, | ||
}, | ||
], | ||
isValueVariable: true, | ||
isTypeVariable: false, | ||
}, | ||
], | ||
scopes: Array [ | ||
GlobalScope$1 { | ||
block: Program$4, | ||
isStrict: false, | ||
references: Array [ | ||
Reference$1, | ||
Reference$2, | ||
], | ||
set: Map { | ||
"const" => ImplicitGlobalConstTypeVariable, | ||
"x" => Variable$2, | ||
}, | ||
type: "global", | ||
upper: null, | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2, | ||
], | ||
}, | ||
], | ||
} | ||
`; |
2 changes: 2 additions & 0 deletions
2
packages/scope-manager/tests/fixtures/type-assertion/assignment/non-null-assignment.ts
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,2 @@ | ||
let x: number | undefined = 1; | ||
x! += 1; |
62 changes: 62 additions & 0 deletions
62
packages/scope-manager/tests/fixtures/type-assertion/assignment/non-null-assignment.ts.shot
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,62 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`type-assertion assignment non-null-assignment 1`] = ` | ||
ScopeManager { | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2 { | ||
defs: Array [ | ||
VariableDefinition$1 { | ||
name: Identifier<"x">, | ||
node: VariableDeclarator$1, | ||
}, | ||
], | ||
name: "x", | ||
references: Array [ | ||
Reference$1 { | ||
identifier: Identifier<"x">, | ||
init: true, | ||
isRead: false, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: true, | ||
resolved: Variable$2, | ||
writeExpr: Literal$2, | ||
}, | ||
Reference$2 { | ||
identifier: Identifier<"x">, | ||
init: false, | ||
isRead: true, | ||
isTypeReference: false, | ||
isValueReference: true, | ||
isWrite: true, | ||
resolved: Variable$2, | ||
writeExpr: Literal$3, | ||
}, | ||
], | ||
isValueVariable: true, | ||
isTypeVariable: false, | ||
}, | ||
], | ||
scopes: Array [ | ||
GlobalScope$1 { | ||
block: Program$4, | ||
isStrict: false, | ||
references: Array [ | ||
Reference$1, | ||
Reference$2, | ||
], | ||
set: Map { | ||
"const" => ImplicitGlobalConstTypeVariable, | ||
"x" => Variable$2, | ||
}, | ||
type: "global", | ||
upper: null, | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2, | ||
], | ||
}, | ||
], | ||
} | ||
`; |