-
-
Notifications
You must be signed in to change notification settings - Fork 963
fix(inference): improved inference for assignment types #8119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
06c85ff
fix(inference): improved inference for assignment types
ematipico e5508bb
tests and clippy
ematipico 7b39a52
grammar
ematipico fa78da4
remove repeated code
ematipico 128a9a4
inspire rule based on feedback
ematipico b700ad7
feedback
ematipico 3d8fc1f
Merge branch 'main' into fix/inference-assignments
ematipico e0955f4
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,20 @@ | ||
| --- | ||
| "@biomejs/biome": patch | ||
| --- | ||
|
|
||
| Improved the detection of the rule `noUnnecessaryConditions`. Now the rule isn't triggered for variables that are mutated inside a module. | ||
|
|
||
| This logic deviates from the original rule, hence `noUnnecessaryConditions` is now marked as "inspired". | ||
|
|
||
| In the following example, `hey` starts as `false`, but then it's assigned to a string. The rule isn't triggered inside the `if` check. | ||
|
|
||
| ```js | ||
| let hey = false; | ||
|
|
||
| function test() { | ||
| hey = "string"; | ||
| } | ||
|
|
||
| if (hey) {} | ||
|
|
||
| ``` | ||
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@biomejs/biome": patch | ||
| --- | ||
|
|
||
| Improved the type inference engine, by resolving types for variables that are assigned to multiple values. |
4 changes: 4 additions & 0 deletions
4
crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
9 changes: 9 additions & 0 deletions
9
crates/biome_js_analyze/tests/specs/nursery/noUnnecessaryConditions/validAssignment.ts
This file contains hidden or 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,9 @@ | ||
| // should not generate diagnostics | ||
|
|
||
| let hey = false; | ||
|
|
||
| function test() { | ||
| hey = "string" | ||
| } | ||
|
|
||
| if (hey) {} |
17 changes: 17 additions & 0 deletions
17
crates/biome_js_analyze/tests/specs/nursery/noUnnecessaryConditions/validAssignment.ts.snap
This file contains hidden or 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 @@ | ||
| --- | ||
| source: crates/biome_js_analyze/tests/spec_tests.rs | ||
| expression: validAssignment.ts | ||
| --- | ||
| # Input | ||
| ```ts | ||
| // should not generate diagnostics | ||
|
|
||
| let hey = false; | ||
|
|
||
| function test() { | ||
| hey = "string" | ||
| } | ||
|
|
||
| if (hey) {} | ||
|
|
||
| ``` |
This file contains hidden or 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 hidden or 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
71 changes: 71 additions & 0 deletions
71
crates/biome_module_graph/tests/snapshots/test_widening_via_assignment.snap
This file contains hidden or 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,71 @@ | ||
| --- | ||
| source: crates/biome_module_graph/tests/snap/mod.rs | ||
| expression: content | ||
| --- | ||
| # `index.ts` (Not imported by resolver) | ||
|
|
||
| ## Source | ||
|
|
||
| ```ts | ||
| let hey = false; | ||
| function f() { | ||
| hey = true; | ||
| } | ||
| ``` | ||
|
|
||
| ## Module Info | ||
|
|
||
| ``` | ||
| Exports { | ||
| No exports | ||
| } | ||
| Imports { | ||
| No imports | ||
| } | ||
| ``` | ||
|
|
||
| ## Registered types | ||
|
|
||
| ``` | ||
| Module TypeId(0) => bool: false | ||
|
|
||
| Module TypeId(1) => bool: true | ||
|
|
||
| Module TypeId(2) => unknown | ||
|
|
||
| Module TypeId(3) => Module(0) TypeId(0) | Module(0) TypeId(1) | ||
|
|
||
| Module TypeId(4) => void | ||
|
|
||
| Module TypeId(5) => sync Function "f" { | ||
| accepts: { | ||
| params: [] | ||
| type_args: [] | ||
| } | ||
| returns: Module(0) TypeId(4) | ||
| } | ||
| ``` | ||
|
|
||
| # Module Resolver | ||
|
|
||
| ## Registered types | ||
|
|
||
| ``` | ||
| Full TypeId(0) => bool: false | ||
|
|
||
| Full TypeId(1) => bool: true | ||
|
|
||
| Full TypeId(2) => unknown | ||
|
|
||
| Full TypeId(3) => Module(0) TypeId(0) | Module(0) TypeId(1) | ||
|
|
||
| Full TypeId(4) => void | ||
|
|
||
| Full TypeId(5) => sync Function "f" { | ||
| accepts: { | ||
| params: [] | ||
| type_args: [] | ||
| } | ||
| returns: Module(0) TypeId(4) | ||
| } | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.