-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix avoid-late if initialized #71
Merged
yurii-prykhodko-solid
merged 27 commits into
solid-software:release-v0.1.0
from
maxxlab:avoid_late_feature
Nov 17, 2023
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
da4b854
Fix avoid-late if initialized
maxxlab f5f5bf2
Update lint_test/avoid_late_keyword_test.dart
maxxlab e34f822
Apply suggestions from code review
maxxlab 2633fc9
Custom avoid-late
maxxlab f5a4a81
Fix naming
maxxlab 78eef07
Apply suggestions from code review
maxxlab 8aeeeb2
Avoid late simplified
maxxlab 13b5e61
Update lib/lints/avoid_late_keyword/models/avoid_late_keyword_paramet…
maxxlab 83629fe
Avoid-late ignored_types
maxxlab 13a6d16
Avoid-late ignored_types formatted
maxxlab 56abdb6
Update lib/lints/avoid_late_keyword/models/avoid_late_keyword_paramet…
maxxlab 6315eca
Avoid-late ignored_types fix
maxxlab 78246e9
Merge branch 'avoid_late_feature' of https://github.com/maxxlab/solid…
maxxlab dbd6bdf
Avoid-late ignored_types Fix
maxxlab d215871
Avoid-late allow_initialized testcases
maxxlab f639d91
Update lint_test/avoid_late_keyword_allow_initialized_test/pubspec.yaml
maxxlab 850cfaa
Update lib/lints/avoid_late_keyword/models/avoid_late_keyword_paramet…
maxxlab b426d49
Allow subclasses for avoid-late whitelist
solid-yuriiprykhodko b023b8c
Fix naming
solid-yuriiprykhodko b4fe907
Merge pull request #1 from yurii-prykhodko-solid/ignore-late-subclasses
maxxlab 662dc49
Short-circuit of there's no ignored types
solid-yuriiprykhodko 41fe9ab
Short-circuit earlier
solid-yuriiprykhodko 8167c07
Merge pull request #2 from yurii-prykhodko-solid/ignore-late-subclasses
maxxlab fbf2270
Update lib/lints/avoid_late_keyword/avoid_late_keyword_rule.dart
maxxlab 2037550
Avoid-late ignored_types tests
maxxlab e3a85fa
Merge branch 'avoid_late_feature' of https://github.com/maxxlab/solid…
maxxlab bb69baa
Avoid-late add testcases
maxxlab 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 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
28 changes: 28 additions & 0 deletions
28
lib/lints/avoid_late_keyword/models/avoid_late_keyword_parameters.dart
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 @@ | ||
/// A data model class that represents the "avoid late keyword" input | ||
/// parameters. | ||
class AvoidLateKeywordParameters { | ||
/// Allow immediately initialised late variables. | ||
/// | ||
/// ```dart | ||
/// late var ok = 0; // ok when allowInitialized == true | ||
/// late var notOk; // initialized elsewhere, not allowed | ||
/// ``` | ||
final bool allowInitialized; | ||
|
||
/// Types that would be ignored by avoid-late rule | ||
final Iterable<String> ignoredTypes; | ||
|
||
/// Constructor for [AvoidLateKeywordParameters] model | ||
const AvoidLateKeywordParameters({ | ||
this.allowInitialized = false, | ||
this.ignoredTypes = const [], | ||
}); | ||
|
||
/// Method for creating from json data | ||
factory AvoidLateKeywordParameters.fromJson(Map<String, Object?> json) => | ||
AvoidLateKeywordParameters( | ||
allowInitialized: json['allow_initialized'] as bool? ?? false, | ||
ignoredTypes: | ||
List<String>.from(json['ignored_types'] as Iterable? ?? []), | ||
); | ||
} |
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
10 changes: 10 additions & 0 deletions
10
lint_test/avoid_late_keyword_allow_initialized_test/analysis_options.yaml
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,10 @@ | ||
analyzer: | ||
plugins: | ||
- ../custom_lint | ||
|
||
custom_lint: | ||
rules: | ||
- avoid_late_keyword: | ||
allow_initialized: false | ||
ignored_types: | ||
- Animation |
76 changes: 76 additions & 0 deletions
76
.../avoid_late_keyword_allow_initialized_test/avoid_late_keyword_allow_initialized_test.dart
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,76 @@ | ||
// ignore_for_file: prefer_const_declarations, unused_local_variable, prefer_match_file_name | ||
// ignore_for_file: avoid_global_state | ||
|
||
abstract class Animation {} | ||
|
||
class AnimationController implements Animation {} | ||
|
||
class SubAnimationController extends AnimationController {} | ||
|
||
class ColorTween {} | ||
|
||
/// Check "late" keyword fail | ||
/// | ||
/// `avoid_late_keyword` | ||
/// allow_initialized option disabled | ||
class AvoidLateKeyword { | ||
late final Animation animation1; | ||
|
||
late final animation2 = AnimationController(); | ||
|
||
late final animation3 = SubAnimationController(); | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final ColorTween colorTween1; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final colorTween2 = ColorTween(); | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final colorTween3 = colorTween2; | ||
|
||
late final AnimationController controller1; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final field1 = 'string'; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final String field2; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final String field3 = 'string'; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final field4; | ||
|
||
void test() { | ||
late final Animation animation1; | ||
|
||
late final animation2 = AnimationController(); | ||
|
||
late final animation3 = SubAnimationController(); | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final ColorTween colorTween1; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final colorTween2 = ColorTween(); | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final colorTween3 = colorTween2; | ||
|
||
late final AnimationController controller1; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final local1 = 'string'; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final String local2; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final String local4 = 'string'; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final local3; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
lint_test/avoid_late_keyword_allow_initialized_test/pubspec.yaml
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,11 @@ | ||
name: avoid_late_keyword_allow_initialized_test | ||
publish_to: none | ||
|
||
environment: | ||
sdk: '>=3.0.0 <4.0.0' | ||
|
||
dependencies: | ||
|
||
dev_dependencies: | ||
solid_lints: | ||
path: ../../ |
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 |
---|---|---|
@@ -1,21 +1,64 @@ | ||
// ignore_for_file: prefer_const_declarations, unused_local_variable, prefer_match_file_name | ||
// ignore_for_file: avoid_global_state | ||
|
||
class ColorTween {} | ||
|
||
class AnimationController {} | ||
|
||
class SubAnimationController extends AnimationController {} | ||
|
||
class NotAllowed {} | ||
|
||
/// Check "late" keyword fail | ||
/// | ||
/// `avoid_late_keyword` | ||
/// allow_initialized option enabled | ||
class AvoidLateKeyword { | ||
/// expect_lint: avoid_late_keyword | ||
late final ColorTween colorTween; | ||
|
||
late final AnimationController controller1; | ||
|
||
late final SubAnimationController controller2; | ||
|
||
late final controller3 = AnimationController(); | ||
|
||
late final controller4 = SubAnimationController(); | ||
|
||
late final field1 = 'string'; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late String field2; | ||
late final String field2; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final field3; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final NotAllowed na1; | ||
|
||
late final na2 = NotAllowed(); | ||
|
||
void test() { | ||
late final ColorTween colorTween; | ||
|
||
late final AnimationController controller1; | ||
|
||
late final SubAnimationController controller2; | ||
|
||
late final controller3 = AnimationController(); | ||
|
||
late final controller4 = SubAnimationController(); | ||
|
||
late final local1 = 'string'; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final field3 = 'string'; | ||
late final String local2; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late String field4; | ||
late final local3; | ||
|
||
/// expect_lint: avoid_late_keyword | ||
late final NotAllowed na1; | ||
|
||
late final na2 = NotAllowed(); | ||
} | ||
} |
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.
Let's also test
allow_initialized == false
+ ignored types.