This repository was archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 267
fix: correctly handle prefixed enums and static instance fields for prefer-moving-to-variable #1123
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7c084a6
test: add test cases
incendial 492b6f8
fix: correctly handle prefixed enums and static instance fields for p…
incendial d220853
Merge remote-tracking branch 'origin/master' into fix-prefix-prefer-m…
incendial d9fbf65
test: restore test example
incendial 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,8 @@ class GetIt { | |
|
||
T call<T extends Object>() => get<T>; | ||
} | ||
|
||
enum AnotherEnum { | ||
firstValue, | ||
anotherValue, | ||
} |
19 changes: 19 additions & 0 deletions
19
...ers/lint_analyzer/rules/rules_list/prefer_moving_to_variable/examples/prefix_example.dart
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,19 @@ | ||
import 'example.dart' as prefix; | ||
import 'generics_example.dart'; | ||
|
||
void main() { | ||
AnotherEnum.anotherValue; | ||
AnotherEnum.anotherValue; | ||
AnotherEnum.firstValue; | ||
|
||
prefix.SomeValue.firstValue; | ||
prefix.SomeValue.firstValue; | ||
prefix.SomeValue.secondValue; | ||
|
||
prefix.SomeClass.value; | ||
prefix.SomeClass.value; | ||
prefix.instance.field; | ||
|
||
print(prefix.SomeValue.entry1); | ||
print(prefix.SomeValue.entry2); | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try referencing prefix.SomeValue.firstValue
repeatedly
I believe that would match the case where I was seeing false positives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's it! Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, actually, if I duplicate the line 5
AnotherEnum.anotherValue;
the rule will also trigger. So it's not connected to prefixes, maybe you remember other cases?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The strange thing is removing the prefixes did seem to fix the issue in DevTools. That said, I wouldn't want the rule to trigger for duplicated
AnotherEnum.anotherValue
case either. Specifying the enum value name twice seems more idiomatic than defining an unneeded local variable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. And maybe the same should work for the class level static variables. You probably wouldn't want to assign this type of calls to a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that I wouldn't want this firing for class to class level static variables either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for misleading, it was a problem exactly with the prefixes 🤦
Now fixed, thank you!