Skip to content

Commit c833721

Browse files
feat: drop some weird behaving rules
1 parent b8b4609 commit c833721

3 files changed

Lines changed: 5 additions & 257 deletions

File tree

lib/solvro_common_overrides.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ analyzer:
3030
- "**/*.icons.dart"
3131
- "**/firebase_options.dart"
3232
- "lib/l10n/app_localizations*.dart"
33+
- build/**
34+
- "**/build/**"

lib/solvro_forks/solvro_custom_linter.dart

Lines changed: 0 additions & 256 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,26 @@ class SolvroCustomLinterPlugin extends Plugin {
1919
<AnalysisRule>[
2020
AddHapticFeedbackOnUserInteractionRule(),
2121
AvoidConsecutiveSliverToBoxAdapterRule(),
22-
AvoidDynamicRule(),
2322
AvoidHardcodedColorRule(),
2423
AvoidIconButtonWithoutTooltipRule(),
2524
AvoidIconWithoutSemanticLabelRule(),
2625
AvoidImageWithoutSemanticLabelRule(),
2726
AvoidSingleChildRule(),
2827
AvoidSmallInteractiveElementsRule(),
29-
AvoidStringLiteralsInsideWidgetRule(),
3028
AssetImageRule(),
3129
CognitiveComplexityRule(),
3230
DisposeControllersRule(),
3331
FreezedMissingMixinRule(),
3432
FreezedMissingPrivateEmptyConstructorRule(),
3533
HooksAvoidNestingRule(),
3634
HooksAvoidWithinClassRule(),
37-
HooksCallbackConsiderationRule(),
3835
HooksExtendsRule(),
39-
HooksMemoizedConsiderationRule(),
4036
HooksNameConventionRule(),
4137
HooksUnuseWidgetRule(),
4238
PreferIterableAnyRule(),
43-
PreferIterableEveryRule(),
4439
PreferIterableFirstRule(),
4540
PreferIterableLastRule(),
4641
PreferToIncludeSliverInNameRule(),
47-
UnnecessaryNullableReturnTypeRule(),
4842
].forEach(registry.registerWarningRule);
4943
}
5044
}
@@ -73,11 +67,6 @@ NamedExpression? _namedArgument(ArgumentList arguments, String name) {
7367
bool _hasNamedArgument(ArgumentList arguments, String name) =>
7468
_namedArgument(arguments, name) != null;
7569

76-
bool _isNullLiteral(Expression expression) => expression is NullLiteral;
77-
78-
bool _isEmptyString(Expression expression) =>
79-
expression is SimpleStringLiteral && expression.value.isEmpty;
80-
8170
class AvoidIconButtonWithoutTooltipRule extends _SolvroRule {
8271
AvoidIconButtonWithoutTooltipRule()
8372
: super(
@@ -412,27 +401,6 @@ class AssetImageRule extends _SolvroRule {
412401
}
413402
}
414403

415-
class AvoidStringLiteralsInsideWidgetRule extends _SolvroRule {
416-
AvoidStringLiteralsInsideWidgetRule()
417-
: super(
418-
const LintCode(
419-
"avoid_string_literals_inside_widget",
420-
"String literals should not be declared inside a widget.",
421-
),
422-
"Encourages localized strings in widgets.",
423-
);
424-
425-
@override
426-
void registerNodeProcessors(
427-
RuleVisitorRegistry registry,
428-
RuleContext context,
429-
) {
430-
final visitor = _StringLiteralVisitor(this);
431-
registry.addSimpleStringLiteral(this, visitor);
432-
registry.addStringInterpolation(this, visitor);
433-
}
434-
}
435-
436404
class CognitiveComplexityRule extends _SolvroRule {
437405
CognitiveComplexityRule()
438406
: super(
@@ -660,79 +628,6 @@ class HooksUnuseWidgetRule extends _SolvroRule {
660628
}
661629
}
662630

663-
class HooksMemoizedConsiderationRule extends _SolvroRule {
664-
HooksMemoizedConsiderationRule()
665-
: super(
666-
const LintCode(
667-
"hooks_memoized_consideration",
668-
"Consider useMemoized for expensive values created in HookWidget build methods.",
669-
),
670-
"Suggests useMemoized for object creation in hook widgets.",
671-
);
672-
673-
@override
674-
void registerNodeProcessors(
675-
RuleVisitorRegistry registry,
676-
RuleContext context,
677-
) {
678-
registry.addInstanceCreationExpression(
679-
this,
680-
_InstanceVisitor(this, (node) {
681-
if (_insideHookWidget(node) && !_insideHookCall(node)) {
682-
reportAtNode(node);
683-
}
684-
}),
685-
);
686-
}
687-
}
688-
689-
class HooksCallbackConsiderationRule extends _SolvroRule {
690-
HooksCallbackConsiderationRule()
691-
: super(
692-
const LintCode(
693-
"hooks_callback_consideration",
694-
"Consider useCallback for callbacks created in HookWidget build methods.",
695-
),
696-
"Suggests useCallback for callbacks in hook widgets.",
697-
);
698-
699-
@override
700-
void registerNodeProcessors(
701-
RuleVisitorRegistry registry,
702-
RuleContext context,
703-
) {
704-
registry.addFunctionExpression(
705-
this,
706-
_FunctionExpressionVisitor(this, (node) {
707-
if (_insideHookWidget(node) && !_insideHookCall(node)) {
708-
reportAtNode(node);
709-
}
710-
}),
711-
);
712-
}
713-
}
714-
715-
class AvoidDynamicRule extends _SolvroRule {
716-
AvoidDynamicRule()
717-
: super(
718-
const LintCode("avoid_dynamic", "Avoid explicit dynamic types."),
719-
"Disallows explicit dynamic type annotations.",
720-
);
721-
722-
@override
723-
void registerNodeProcessors(
724-
RuleVisitorRegistry registry,
725-
RuleContext context,
726-
) {
727-
registry.addNamedType(
728-
this,
729-
_NamedTypeVisitor(this, (node) {
730-
if (node.name.lexeme == "dynamic") reportAtNode(node);
731-
}),
732-
);
733-
}
734-
}
735-
736631
class DisposeControllersRule extends _SolvroRule {
737632
DisposeControllersRule()
738633
: super(
@@ -777,27 +672,6 @@ class DisposeControllersRule extends _SolvroRule {
777672
}
778673
}
779674

780-
class UnnecessaryNullableReturnTypeRule extends _SolvroRule {
781-
UnnecessaryNullableReturnTypeRule()
782-
: super(
783-
const LintCode(
784-
"unnecessary_nullable_return_type",
785-
"Return type is nullable but the function never returns null.",
786-
),
787-
"Finds nullable return types where null is never returned.",
788-
);
789-
790-
@override
791-
void registerNodeProcessors(
792-
RuleVisitorRegistry registry,
793-
RuleContext context,
794-
) {
795-
final visitor = _NullableReturnVisitor(this);
796-
registry.addFunctionDeclaration(this, visitor);
797-
registry.addMethodDeclaration(this, visitor);
798-
}
799-
}
800-
801675
class PreferIterableAnyRule extends _PreferIterableRule {
802676
PreferIterableAnyRule()
803677
: super(
@@ -807,15 +681,6 @@ class PreferIterableAnyRule extends _PreferIterableRule {
807681
);
808682
}
809683

810-
class PreferIterableEveryRule extends _PreferIterableRule {
811-
PreferIterableEveryRule()
812-
: super(
813-
"prefer_iterable_every",
814-
"Prefer iterable.every(...) over where(...).length checks.",
815-
"every",
816-
);
817-
}
818-
819684
class PreferIterableFirstRule extends _PreferIterableRule {
820685
PreferIterableFirstRule()
821686
: super(
@@ -858,16 +723,6 @@ class _PreferIterableRule extends _SolvroRule {
858723
if (kind == "last" && property == "last") reportAtNode(node);
859724
}),
860725
);
861-
registry.addBinaryExpression(
862-
this,
863-
_BinaryExpressionVisitor(this, (node) {
864-
if (kind != "every") return;
865-
final source = node.toString();
866-
if (source.contains(".where(") && source.contains(".length")) {
867-
reportAtNode(node);
868-
}
869-
}),
870-
);
871726
}
872727
}
873728

@@ -989,15 +844,6 @@ class _ClassVisitor extends SimpleAstVisitor<void> {
989844
void visitClassDeclaration(ClassDeclaration node) => check(node);
990845
}
991846

992-
class _NamedTypeVisitor extends SimpleAstVisitor<void> {
993-
_NamedTypeVisitor(this.rule, this.check);
994-
995-
final AnalysisRule rule;
996-
final void Function(NamedType node) check;
997-
@override
998-
void visitNamedType(NamedType node) => check(node);
999-
}
1000-
1001847
class _PropertyAccessVisitor extends SimpleAstVisitor<void> {
1002848
_PropertyAccessVisitor(this.rule, this.check);
1003849

@@ -1007,40 +853,6 @@ class _PropertyAccessVisitor extends SimpleAstVisitor<void> {
1007853
void visitPropertyAccess(PropertyAccess node) => check(node);
1008854
}
1009855

1010-
class _BinaryExpressionVisitor extends SimpleAstVisitor<void> {
1011-
_BinaryExpressionVisitor(this.rule, this.check);
1012-
1013-
final AnalysisRule rule;
1014-
final void Function(BinaryExpression node) check;
1015-
@override
1016-
void visitBinaryExpression(BinaryExpression node) => check(node);
1017-
}
1018-
1019-
class _FunctionExpressionVisitor extends SimpleAstVisitor<void> {
1020-
_FunctionExpressionVisitor(this.rule, this.check);
1021-
1022-
final AnalysisRule rule;
1023-
final void Function(FunctionExpression node) check;
1024-
@override
1025-
void visitFunctionExpression(FunctionExpression node) => check(node);
1026-
}
1027-
1028-
class _StringLiteralVisitor extends SimpleAstVisitor<void> {
1029-
_StringLiteralVisitor(this.rule);
1030-
1031-
final AnalysisRule rule;
1032-
1033-
@override
1034-
void visitSimpleStringLiteral(SimpleStringLiteral node) {
1035-
if (!_isEmptyString(node) && _insideWidget(node)) rule.reportAtNode(node);
1036-
}
1037-
1038-
@override
1039-
void visitStringInterpolation(StringInterpolation node) {
1040-
if (_insideWidget(node)) rule.reportAtNode(node);
1041-
}
1042-
}
1043-
1044856
class _HardcodedColorVisitor extends SimpleAstVisitor<void> {
1045857
_HardcodedColorVisitor(this.rule, this.context);
1046858

@@ -1242,74 +1054,6 @@ class _ComplexityCounter extends RecursiveAstVisitor<void> {
12421054
}
12431055
}
12441056

1245-
class _NullableReturnVisitor extends SimpleAstVisitor<void> {
1246-
_NullableReturnVisitor(this.rule);
1247-
final AnalysisRule rule;
1248-
1249-
@override
1250-
void visitFunctionDeclaration(FunctionDeclaration node) {
1251-
final returnType = node.returnType;
1252-
if (returnType == null || !returnType.toString().endsWith("?")) return;
1253-
if (!_returnsNull(node.functionExpression.body)) {
1254-
rule.reportAtNode(returnType);
1255-
}
1256-
}
1257-
1258-
@override
1259-
void visitMethodDeclaration(MethodDeclaration node) {
1260-
final returnType = node.returnType;
1261-
if (returnType == null || !returnType.toString().endsWith("?")) return;
1262-
if (!_returnsNull(node.body)) rule.reportAtNode(returnType);
1263-
}
1264-
1265-
bool _returnsNull(FunctionBody body) {
1266-
final visitor = _NullReturnVisitor();
1267-
body.accept(visitor);
1268-
return visitor.found;
1269-
}
1270-
}
1271-
1272-
class _NullReturnVisitor extends RecursiveAstVisitor<void> {
1273-
var found = false;
1274-
1275-
@override
1276-
void visitReturnStatement(ReturnStatement node) {
1277-
if (node.expression case final expression?
1278-
when _isNullLiteral(expression)) {
1279-
found = true;
1280-
}
1281-
}
1282-
}
1283-
1284-
bool _insideWidget(AstNode node) {
1285-
for (AstNode? current = node; current != null; current = current.parent) {
1286-
if (current is ConstructorDeclaration) return true;
1287-
if (current is ClassDeclaration) {
1288-
final superclass = current.extendsClause?.superclass.name.lexeme;
1289-
return superclass != null &&
1290-
(superclass.endsWith("Widget") || superclass == "State");
1291-
}
1292-
}
1293-
return false;
1294-
}
1295-
1296-
bool _insideHookWidget(AstNode node) {
1297-
for (AstNode? current = node; current != null; current = current.parent) {
1298-
if (current is ClassDeclaration) {
1299-
final superclass = current.extendsClause?.superclass.name.lexeme;
1300-
return superclass == "HookWidget" || superclass == "HookConsumerWidget";
1301-
}
1302-
}
1303-
return false;
1304-
}
1305-
1306-
bool _insideHookCall(AstNode node) {
1307-
for (AstNode? current = node; current != null; current = current.parent) {
1308-
if (current is MethodInvocation && _isHookCall(current)) return true;
1309-
}
1310-
return false;
1311-
}
1312-
13131057
bool _isHookCall(MethodInvocation node) =>
13141058
node.methodName.name.startsWith(RegExp("use[A-Z]"));
13151059

lib/src/install_solvro/add_linter.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ ${yamlName == "app" ? _solvroCustomLinterPlugin : ""}""";
2121

2222
const _solvroCustomLinterPlugin = """
2323
solvro_config:
24-
version: ^1.4.2
24+
version: ^1.7.0
25+
diagnostics:
26+
provider_dependencies: false # this works weirdly
2527
""";

0 commit comments

Comments
 (0)