-
Notifications
You must be signed in to change notification settings - Fork 24
refactor: migrate member_ordering rule #297
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
Open
solid-illiaaihistov
wants to merge
4
commits into
solid-software:analysis_server_migration
Choose a base branch
from
solid-illiaaihistov:252-migrate-member_ordering
base: analysis_server_migration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2a437b1
refactor: migrate member_ordering rule
be80aec
refactor: extract member group satisfaction logic to extensions and s…
127486b
refactor: unify member ordering diagnostic reporting with a shared he…
a4f609b
refactor: simplify member group satisfaction checks
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
61 changes: 61 additions & 0 deletions
61
lib/src/lints/member_ordering/models/member_group/member_group_extensions.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,61 @@ | ||
| import 'package:solid_lints/src/lints/member_ordering/models/annotation.dart'; | ||
| import 'package:solid_lints/src/lints/member_ordering/models/field_keyword.dart'; | ||
| import 'package:solid_lints/src/lints/member_ordering/models/member_group/constructor_member_group.dart'; | ||
| import 'package:solid_lints/src/lints/member_ordering/models/member_group/field_member_group.dart'; | ||
| import 'package:solid_lints/src/lints/member_ordering/models/member_group/get_set_member_group.dart'; | ||
| import 'package:solid_lints/src/lints/member_ordering/models/member_group/member_group.dart'; | ||
| import 'package:solid_lints/src/lints/member_ordering/models/member_group/method_member_group.dart'; | ||
| import 'package:solid_lints/src/lints/member_ordering/models/member_type.dart'; | ||
| import 'package:solid_lints/src/lints/member_ordering/models/modifier.dart'; | ||
|
|
||
| /// Extension methods for [MemberGroup] to check if a parsed group matches | ||
| /// the properties of this group. | ||
| extension MemberGroupExtensions on MemberGroup { | ||
| /// Checks whether this [MemberGroup] satisfies the properties | ||
| /// of the [parsedGroup]. | ||
| bool satisfies(MemberGroup parsedGroup) { | ||
| if (!_matchesBaseProperties(parsedGroup)) { | ||
| return false; | ||
| } | ||
|
|
||
| final group = this; | ||
| return switch ((group, parsedGroup)) { | ||
| (final ConstructorMemberGroup g, final ConstructorMemberGroup p) => | ||
| _isConstructor(g, p), | ||
| (final MethodMemberGroup g, final MethodMemberGroup p) => _isMethod(g, p), | ||
| (final GetSetMemberGroup g, final GetSetMemberGroup p) => _isGetSet(g, p), | ||
| (final FieldMemberGroup g, final FieldMemberGroup p) => _isField(g, p), | ||
| _ => false, | ||
| }; | ||
| } | ||
|
|
||
| bool _matchesBaseProperties(MemberGroup parsedGroup) => | ||
| (modifier == Modifier.unset || modifier == parsedGroup.modifier) && | ||
| (annotation == Annotation.unset || annotation == parsedGroup.annotation); | ||
|
|
||
| bool _isConstructor( | ||
| ConstructorMemberGroup g, | ||
| ConstructorMemberGroup p, | ||
| ) => | ||
| (!g.isFactory || g.isFactory == p.isFactory) && | ||
| (!g.isNamed || g.isNamed == p.isNamed); | ||
|
|
||
| bool _isMethod(MethodMemberGroup g, MethodMemberGroup p) => | ||
| (!g.isStatic || g.isStatic == p.isStatic) && | ||
| (!g.isNullable || g.isNullable == p.isNullable) && | ||
| (g.name == null || g.name == p.name); | ||
|
|
||
| bool _isGetSet(GetSetMemberGroup g, GetSetMemberGroup p) => | ||
| (g.memberType == p.memberType || | ||
| (g.memberType == MemberType.getterAndSetter && | ||
| (p.memberType == MemberType.getter || | ||
| p.memberType == MemberType.setter))) && | ||
| (!g.isStatic || g.isStatic == p.isStatic) && | ||
| (!g.isNullable || g.isNullable == p.isNullable); | ||
|
|
||
| bool _isField(FieldMemberGroup g, FieldMemberGroup p) => | ||
| (!g.isLate || g.isLate == p.isLate) && | ||
| (!g.isStatic || g.isStatic == p.isStatic) && | ||
| (!g.isNullable || g.isNullable == p.isNullable) && | ||
| (g.keyword == FieldKeyword.unset || g.keyword == p.keyword); | ||
| } |
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 @@ | ||
| import 'package:analyzer/dart/ast/ast.dart'; | ||
| import 'package:solid_lints/src/lints/member_ordering/models/member_order.dart'; | ||
|
|
||
| /// Data class that holds AST class member and it's order info | ||
| class MemberInfo { | ||
| /// AST instance of an [ClassMember] | ||
| final ClassMember classMember; | ||
|
|
||
| /// Class member order info | ||
| final MemberOrder memberOrder; | ||
|
|
||
| /// Creates instance of an [MemberInfo] | ||
| const MemberInfo({ | ||
| required this.classMember, | ||
| required this.memberOrder, | ||
| }); | ||
| } |
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,22 @@ | ||
| /// Data class contains info about current and previous class member names | ||
| class MemberNames { | ||
| /// Name of current class member | ||
| final String currentName; | ||
|
|
||
| /// Name of previous class member | ||
| final String? previousName; | ||
|
|
||
| /// Type name of current class member | ||
| final String currentTypeName; | ||
|
|
||
| /// Type name of previous class member | ||
| final String? previousTypeName; | ||
|
|
||
| /// Creates instance of [MemberNames] | ||
| const MemberNames({ | ||
| required this.currentName, | ||
| required this.currentTypeName, | ||
| this.previousName, | ||
| this.previousTypeName, | ||
| }); | ||
| } |
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,33 @@ | ||
| import 'package:solid_lints/src/lints/member_ordering/models/member_group/member_group.dart'; | ||
| import 'package:solid_lints/src/lints/member_ordering/models/member_names.dart'; | ||
|
|
||
| /// Data class holds information about class member order info | ||
| class MemberOrder { | ||
| /// Indicates if order is wrong | ||
| final bool isWrong; | ||
|
|
||
| /// Indicates if order is wrong alphabetically | ||
| final bool isAlphabeticallyWrong; | ||
|
|
||
| /// Indicates if order is wrong alphabetically by type | ||
| final bool isByTypeWrong; | ||
|
|
||
| /// Info about current and previous class member name | ||
| final MemberNames memberNames; | ||
|
|
||
| /// Info about current member member group | ||
| final MemberGroup memberGroup; | ||
|
|
||
| /// Info about previous member member group | ||
| final MemberGroup? previousMemberGroup; | ||
|
|
||
| /// Creates instance of [MemberOrder] | ||
| const MemberOrder({ | ||
| required this.isWrong, | ||
| required this.isAlphabeticallyWrong, | ||
| required this.isByTypeWrong, | ||
| required this.memberNames, | ||
| required this.memberGroup, | ||
| this.previousMemberGroup, | ||
| }); | ||
| } |
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
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.
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.
I played around refactoring it and I was able to get rid of this file completely:
lib/src/utils/implies.dart:
Add a new method to abstract class MemberGroup:
and same for subclasses and relevant enums:
One thing I'm not entirely sure about is
covariant- maybe we should just checkisin the method instead.WDYT?