-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored code and reorganized files
- Loading branch information
Showing
11 changed files
with
94 additions
and
76 deletions.
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
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,66 @@ | ||
import 'package:analyzer/dart/analysis/utilities.dart'; | ||
import 'package:analyzer/dart/ast/ast.dart'; | ||
import 'package:analyzer/dart/ast/visitor.dart'; | ||
|
||
/// Parses the provided type string to extract a [NamedType]. | ||
NamedType parseNamedTypeFromString(String typeString) { | ||
try { | ||
final namedTypeFinder = _NamedTypeFinder(); | ||
|
||
final parseResult = parseString(content: "$typeString _;"); | ||
parseResult.unit.visitChildren(namedTypeFinder); | ||
|
||
return namedTypeFinder.foundNamedType!; | ||
} catch (_) { | ||
throw Exception("No NamedType could be parsed from the input " | ||
"typeString: '$typeString'. Ensure it's a valid Dart " | ||
"type declaration."); | ||
} | ||
} | ||
|
||
class _NamedTypeFinder extends GeneralizingAstVisitor<void> { | ||
NamedType? _foundNamedType; | ||
|
||
NamedType? get foundNamedType => _foundNamedType; | ||
|
||
@override | ||
void visitNamedType(NamedType namedType) { | ||
_foundNamedType ??= namedType; | ||
} | ||
} | ||
|
||
/// | ||
extension ChildNamedTypes on NamedType { | ||
/// Retrieves child [NamedType] instances from type arguments. | ||
List<NamedType> get childNamedTypes => | ||
typeArguments?.arguments.whereType<NamedType>().toList() ?? []; | ||
|
||
/// Gets the token name of this type instance. | ||
String get tokenName => name2.toString(); | ||
|
||
/// Checks if the current token name is 'dynamic'. | ||
bool get isDynamic => tokenName == "dynamic"; | ||
|
||
/// Checks if the current token name is 'Object'. | ||
bool get isObject => tokenName == "Object"; | ||
|
||
/// Checks if this node is a subtype of the specified node | ||
/// based on their structures. | ||
bool isSubtypeOf({required NamedType node}) { | ||
if (isDynamic || isObject) return true; | ||
|
||
if (tokenName != node.tokenName) return false; | ||
|
||
if (childNamedTypes.isEmpty) return true; | ||
|
||
if (childNamedTypes.length != node.childNamedTypes.length) return false; | ||
|
||
for (int i = 0; i < childNamedTypes.length; i++) { | ||
if (!childNamedTypes[i].isSubtypeOf(node: node.childNamedTypes[i])) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
14 changes: 14 additions & 0 deletions
14
lint_test/avoid_late_keyword/with_generics/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,14 @@ | ||
analyzer: | ||
plugins: | ||
- ../custom_lint | ||
|
||
custom_lint: | ||
rules: | ||
- avoid_late_keyword: | ||
allow_initialized: true | ||
ignored_types: | ||
- ColorTween | ||
- AnimationController | ||
- Subscription<List<Object?>> | ||
- Subscription<Map<dynamic, String>> | ||
- Subscription<ConcreteTypeWithNoGenerics> |
File renamed without changes.