From e9e56f618e6768a5c54bc78b8f0a5faabe059f62 Mon Sep 17 00:00:00 2001 From: solid-glebvorobey <132369081+solid-glebvorobey@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:42:19 +0200 Subject: [PATCH 1/8] Fixed analyzer issue, fixed linter --- .../avoid_debug_print_in_release_rule.dart | 2 +- .../avoid_final_with_getter_rule.dart | 8 ++-- .../visitors/getter_variable_visitor.dart | 2 +- .../avoid_global_state_rule.dart | 4 +- .../avoid_late_keyword_rule.dart | 2 +- .../avoid_non_null_assertion_rule.dart | 2 +- .../avoid_returning_widgets_rule.dart | 2 +- .../avoid_unnecessary_set_state_rule.dart | 2 +- ...void_unnecessary_type_assertions_rule.dart | 4 +- .../avoid_unnecessary_type_casts_rule.dart | 2 +- .../avoid_unrelated_type_assertions_rule.dart | 6 +-- .../avoid_unused_parameters_rule.dart | 2 +- .../avoid_using_api_linter.dart | 28 ++++++++----- .../cyclomatic_complexity_rule.dart | 2 +- .../double_literal_format_rule.dart | 6 +-- .../function_lines_of_code_rule.dart | 10 ++--- .../member_ordering/member_ordering_rule.dart | 12 +++--- .../visitors/member_ordering_visitor.dart | 12 ++---- .../newline_before_return_rule.dart | 2 +- .../no_empty_block/no_empty_block_rule.dart | 2 +- .../no_equal_then_else_rule.dart | 2 +- .../no_magic_number/no_magic_number_rule.dart | 8 ++-- .../number_of_parameters_rule.dart | 8 ++-- .../prefer_conditional_expressions_rule.dart | 8 ++-- .../prefer_early_return_rule.dart | 2 +- .../lints/prefer_first/prefer_first_rule.dart | 2 +- .../lints/prefer_last/prefer_last_rule.dart | 2 +- .../prefer_match_file_name_rule.dart | 4 +- .../proper_super_calls_rule.dart | 8 ++-- lib/src/utils/types_utils.dart | 40 +++++++------------ pubspec.yaml | 6 +-- 31 files changed, 93 insertions(+), 109 deletions(-) diff --git a/lib/src/lints/avoid_debug_print_in_release/avoid_debug_print_in_release_rule.dart b/lib/src/lints/avoid_debug_print_in_release/avoid_debug_print_in_release_rule.dart index 1a3e7aa..b92accb 100644 --- a/lib/src/lints/avoid_debug_print_in_release/avoid_debug_print_in_release_rule.dart +++ b/lib/src/lints/avoid_debug_print_in_release/avoid_debug_print_in_release_rule.dart @@ -122,7 +122,7 @@ your `debugPrint` call in a `!kReleaseMode` check.""", return; } - reporter.reportErrorForNode(code, node); + reporter.atNode(node, code); } /// Returns null if doesn't have right operand diff --git a/lib/src/lints/avoid_final_with_getter/avoid_final_with_getter_rule.dart b/lib/src/lints/avoid_final_with_getter/avoid_final_with_getter_rule.dart index 497faa2..93b1989 100644 --- a/lib/src/lints/avoid_final_with_getter/avoid_final_with_getter_rule.dart +++ b/lib/src/lints/avoid_final_with_getter/avoid_final_with_getter_rule.dart @@ -64,12 +64,10 @@ class AvoidFinalWithGetterRule extends SolidLintRule { node.accept(visitor); for (final element in visitor.getters) { - reporter.reportErrorForNode( - code, + reporter.atNode( element.getter, - null, - null, - element, + code, + data: element, ); } }); diff --git a/lib/src/lints/avoid_final_with_getter/visitors/getter_variable_visitor.dart b/lib/src/lints/avoid_final_with_getter/visitors/getter_variable_visitor.dart index 6809ac8..912abfd 100644 --- a/lib/src/lints/avoid_final_with_getter/visitors/getter_variable_visitor.dart +++ b/lib/src/lints/avoid_final_with_getter/visitors/getter_variable_visitor.dart @@ -35,7 +35,7 @@ extension on MethodDeclaration { expression: SimpleIdentifier( staticElement: Element( declaration: PropertyAccessorElement( - variable: PropertyInducingElement(:final id) + variable2: PropertyInducingElement(:final id) ) ) ) diff --git a/lib/src/lints/avoid_global_state/avoid_global_state_rule.dart b/lib/src/lints/avoid_global_state/avoid_global_state_rule.dart index f86fe5b..1b4d1e4 100644 --- a/lib/src/lints/avoid_global_state/avoid_global_state_rule.dart +++ b/lib/src/lints/avoid_global_state/avoid_global_state_rule.dart @@ -63,13 +63,13 @@ class AvoidGlobalStateRule extends SolidLintRule { context.registry.addTopLevelVariableDeclaration( (node) => node.variables.variables .where((variable) => variable.isPublicMutable) - .forEach((node) => reporter.reportErrorForNode(code, node)), + .forEach((node) => reporter.atNode(node, code)), ); context.registry.addFieldDeclaration((node) { if (!node.isStatic) return; node.fields.variables .where((variable) => variable.isPublicMutable) - .forEach((node) => reporter.reportErrorForNode(code, node)); + .forEach((node) => reporter.atNode(node, code)); }); } } diff --git a/lib/src/lints/avoid_late_keyword/avoid_late_keyword_rule.dart b/lib/src/lints/avoid_late_keyword/avoid_late_keyword_rule.dart index baa207f..70380c0 100644 --- a/lib/src/lints/avoid_late_keyword/avoid_late_keyword_rule.dart +++ b/lib/src/lints/avoid_late_keyword/avoid_late_keyword_rule.dart @@ -76,7 +76,7 @@ class AvoidLateKeywordRule extends SolidLintRule { ) { context.registry.addVariableDeclaration((node) { if (_shouldLint(node)) { - reporter.reportErrorForNode(code, node); + reporter.atNode(node, code); } }); } diff --git a/lib/src/lints/avoid_non_null_assertion/avoid_non_null_assertion_rule.dart b/lib/src/lints/avoid_non_null_assertion/avoid_non_null_assertion_rule.dart index 5638588..8d687fd 100644 --- a/lib/src/lints/avoid_non_null_assertion/avoid_non_null_assertion_rule.dart +++ b/lib/src/lints/avoid_non_null_assertion/avoid_non_null_assertion_rule.dart @@ -86,7 +86,7 @@ class AvoidNonNullAssertionRule extends SolidLintRule { } } - reporter.reportErrorForNode(code, node); + reporter.atNode(node, code); }); } } diff --git a/lib/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart b/lib/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart index 18d908d..1645232 100644 --- a/lib/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart +++ b/lib/src/lints/avoid_returning_widgets/avoid_returning_widgets_rule.dart @@ -101,7 +101,7 @@ class AvoidReturningWidgetsRule final isOverriden = node.declaredElement?.hasOverride ?? false; if (isWidgetReturned && !isOverriden && !isIgnored) { - reporter.reportErrorForNode(code, node); + reporter.atNode(node, code); } }); } diff --git a/lib/src/lints/avoid_unnecessary_setstate/avoid_unnecessary_set_state_rule.dart b/lib/src/lints/avoid_unnecessary_setstate/avoid_unnecessary_set_state_rule.dart index a0cea2b..37d7113 100644 --- a/lib/src/lints/avoid_unnecessary_setstate/avoid_unnecessary_set_state_rule.dart +++ b/lib/src/lints/avoid_unnecessary_setstate/avoid_unnecessary_set_state_rule.dart @@ -84,7 +84,7 @@ class AvoidUnnecessarySetStateRule extends SolidLintRule { final visitor = AvoidUnnecessarySetStateVisitor(); visitor.visitClassDeclaration(node); for (final element in visitor.setStateInvocations) { - reporter.reportErrorForNode(code, element); + reporter.atNode(element, code); } }); } diff --git a/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart b/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart index fa5fe38..20d088c 100644 --- a/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart +++ b/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart @@ -77,13 +77,13 @@ class AvoidUnnecessaryTypeAssertions extends SolidLintRule { ) { context.registry.addIsExpression((node) { if (_isUnnecessaryIsExpression(node)) { - reporter.reportErrorForNode(_unnecessaryIsCode, node); + reporter.atNode(node, _unnecessaryIsCode); } }); context.registry.addMethodInvocation((node) { if (_isUnnecessaryWhereType(node)) { - reporter.reportErrorForNode(_unnecessaryWhereTypeCode, node); + reporter.atNode(node, _unnecessaryWhereTypeCode); } }); } diff --git a/lib/src/lints/avoid_unnecessary_type_casts/avoid_unnecessary_type_casts_rule.dart b/lib/src/lints/avoid_unnecessary_type_casts/avoid_unnecessary_type_casts_rule.dart index a66cc79..bf0055f 100644 --- a/lib/src/lints/avoid_unnecessary_type_casts/avoid_unnecessary_type_casts_rule.dart +++ b/lib/src/lints/avoid_unnecessary_type_casts/avoid_unnecessary_type_casts_rule.dart @@ -41,7 +41,7 @@ class AvoidUnnecessaryTypeCastsRule extends SolidLintRule { visitor.visitAsExpression(node); for (final element in visitor.expressions.entries) { - reporter.reportErrorForNode(code, element.key); + reporter.atNode(element.key, code); } }); } diff --git a/lib/src/lints/avoid_unrelated_type_assertions/avoid_unrelated_type_assertions_rule.dart b/lib/src/lints/avoid_unrelated_type_assertions/avoid_unrelated_type_assertions_rule.dart index 4be9071..31deef8 100644 --- a/lib/src/lints/avoid_unrelated_type_assertions/avoid_unrelated_type_assertions_rule.dart +++ b/lib/src/lints/avoid_unrelated_type_assertions/avoid_unrelated_type_assertions_rule.dart @@ -39,10 +39,10 @@ class AvoidUnrelatedTypeAssertionsRule extends SolidLintRule { visitor.visitIsExpression(node); for (final element in visitor.expressions.entries) { - reporter.reportErrorForNode( - code, + reporter.atNode( element.key, - [element.value.toString()], + code, + arguments: [element.value.toString()], ); } }); diff --git a/lib/src/lints/avoid_unused_parameters/avoid_unused_parameters_rule.dart b/lib/src/lints/avoid_unused_parameters/avoid_unused_parameters_rule.dart index be52d0e..a704860 100644 --- a/lib/src/lints/avoid_unused_parameters/avoid_unused_parameters_rule.dart +++ b/lib/src/lints/avoid_unused_parameters/avoid_unused_parameters_rule.dart @@ -96,7 +96,7 @@ class AvoidUnusedParametersRule extends SolidLintRule { node.accept(visitor); for (final element in visitor.unusedParameters) { - reporter.reportErrorForNode(code, element); + reporter.atNode(element, code); } }); } diff --git a/lib/src/lints/avoid_using_api/avoid_using_api_linter.dart b/lib/src/lints/avoid_using_api/avoid_using_api_linter.dart index 6d41dd5..1b3f93c 100644 --- a/lib/src/lints/avoid_using_api/avoid_using_api_linter.dart +++ b/lib/src/lints/avoid_using_api/avoid_using_api_linter.dart @@ -63,7 +63,7 @@ class AvoidUsingApiLinter { return; } - reporter.reportErrorForNode(entryCode, node); + reporter.atNode(node, entryCode); }); context.registry.addNamedType((node) { @@ -72,7 +72,7 @@ class AvoidUsingApiLinter { return; } - reporter.reportErrorForNode(entryCode, node); + reporter.atNode(node, entryCode); }); } @@ -96,7 +96,7 @@ class AvoidUsingApiLinter { switch (node.staticElement) { case FunctionElement() || PropertyAccessorElement(): - reporter.reportErrorForNode(entryCode, node); + reporter.atNode(node, entryCode); } }); } @@ -118,7 +118,7 @@ class AvoidUsingApiLinter { if (sourcePath == null || !_matchesSource(sourcePath, source)) { return; } - reporter.reportErrorForNode(entryCode, node); + reporter.atNode(node, entryCode); }); context.registry.addSimpleIdentifier((node) { @@ -162,7 +162,7 @@ class AvoidUsingApiLinter { return; } - reporter.reportErrorForNode(entryCode, parent); + reporter.atNode(parent, entryCode); }); context.registry.addNamedType((node) { @@ -176,9 +176,9 @@ class AvoidUsingApiLinter { return; } - reporter.reportErrorForNode( - entryCode, + reporter.atNode( node.parent?.parent ?? node.parent ?? node, + entryCode, ); }); } @@ -219,23 +219,29 @@ class AvoidUsingApiLinter { return; } - reporter.reportErrorForNode(entryCode, node.parent ?? node); + reporter.atNode( + node.parent ?? node, + entryCode, + ); case SimpleIdentifier(:final staticElement?): final parentElementName = staticElement.name; if (parentElementName != className) { return; } - reporter.reportErrorForNode(entryCode, node.parent ?? node); + reporter.atNode( + node.parent ?? node, + entryCode, + ); case NamedType(:final element?): final parentTypeName = element.name; if (parentTypeName != className) { return; } - reporter.reportErrorForNode( - entryCode, + reporter.atNode( node.parent?.parent ?? node.parent ?? node, + entryCode, ); } }); diff --git a/lib/src/lints/cyclomatic_complexity/cyclomatic_complexity_rule.dart b/lib/src/lints/cyclomatic_complexity/cyclomatic_complexity_rule.dart index 86a2570..2e4aee5 100644 --- a/lib/src/lints/cyclomatic_complexity/cyclomatic_complexity_rule.dart +++ b/lib/src/lints/cyclomatic_complexity/cyclomatic_complexity_rule.dart @@ -57,7 +57,7 @@ class CyclomaticComplexityRule if (visitor.complexityEntities.length + 1 > config.parameters.maxComplexity) { - reporter.reportErrorForNode(code, node); + reporter.atNode(node, code); } }); } diff --git a/lib/src/lints/double_literal_format/double_literal_format_rule.dart b/lib/src/lints/double_literal_format/double_literal_format_rule.dart index d3e5bfb..d32664b 100644 --- a/lib/src/lints/double_literal_format/double_literal_format_rule.dart +++ b/lib/src/lints/double_literal_format/double_literal_format_rule.dart @@ -81,15 +81,15 @@ class DoubleLiteralFormatRule extends SolidLintRule { final lexeme = node.literal.lexeme; if (lexeme.hasLeadingZero) { - reporter.reportErrorForNode(_leadingZeroCode, node); + reporter.atNode(node, _leadingZeroCode); return; } if (lexeme.hasLeadingDecimalPoint) { - reporter.reportErrorForNode(_leadingDecimalCode, node); + reporter.atNode(node, _leadingDecimalCode); return; } if (lexeme.hasTrailingZero) { - reporter.reportErrorForNode(_trailingZeroCode, node); + reporter.atNode(node, _trailingZeroCode); return; } }); diff --git a/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart b/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart index ff90076..efda27c 100644 --- a/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart +++ b/lib/src/lints/function_lines_of_code/function_lines_of_code_rule.dart @@ -71,16 +71,16 @@ class FunctionLinesOfCodeRule if (visitor.linesWithCode.length > config.parameters.maxLines) { if (node is! AnnotatedNode) { - return reporter.reportErrorForNode(code, node); + return reporter.atNode(node, code); } final startOffset = node.firstTokenAfterCommentAndMetadata.offset; final lengthDifference = startOffset - node.offset; - reporter.reportErrorForOffset( - code, - startOffset, - node.length - lengthDifference, + reporter.atOffset( + offset: startOffset, + length: node.length - lengthDifference, + errorCode: code, ); } } diff --git a/lib/src/lints/member_ordering/member_ordering_rule.dart b/lib/src/lints/member_ordering/member_ordering_rule.dart index a5c5d04..4eba799 100644 --- a/lib/src/lints/member_ordering/member_ordering_rule.dart +++ b/lib/src/lints/member_ordering/member_ordering_rule.dart @@ -125,9 +125,9 @@ class MemberOrderingRule extends SolidLintRule { ); for (final memberInfo in wrongOrderMembers) { - reporter.reportErrorForNode( - _createWrongOrderLintCode(memberInfo), + reporter.atNode( memberInfo.classMember, + _createWrongOrderLintCode(memberInfo), ); } @@ -137,9 +137,9 @@ class MemberOrderingRule extends SolidLintRule { ); for (final memberInfo in alphabeticallyWrongOrderMembers) { - reporter.reportErrorForNode( - _createAlphabeticallyWrongOrderLintCode(memberInfo), + reporter.atNode( memberInfo.classMember, + _createAlphabeticallyWrongOrderLintCode(memberInfo), ); } } @@ -151,9 +151,9 @@ class MemberOrderingRule extends SolidLintRule { ); for (final memberInfo in alphabeticallyByTypeWrongOrderMembers) { - reporter.reportErrorForNode( - _createAlphabeticallyByTypeWrongOrderLintCode(memberInfo), + reporter.atNode( memberInfo.classMember, + _createAlphabeticallyByTypeWrongOrderLintCode(memberInfo), ); } } diff --git a/lib/src/lints/member_ordering/visitors/member_ordering_visitor.dart b/lib/src/lints/member_ordering/visitors/member_ordering_visitor.dart index 52c9ea9..6b2035d 100644 --- a/lib/src/lints/member_ordering/visitors/member_ordering_visitor.dart +++ b/lib/src/lints/member_ordering/visitors/member_ordering_visitor.dart @@ -85,9 +85,7 @@ class MemberOrderingVisitor extends RecursiveAstVisitor> { memberOrder: _getOrder( closestGroup, declaration.fields.variables.first.name.lexeme, - declaration.fields.type?.type - ?.getDisplayString(withNullability: false) ?? - '_', + declaration.fields.type?.type?.getDisplayString() ?? '_', isFlutterWidget, ), ), @@ -132,9 +130,7 @@ class MemberOrderingVisitor extends RecursiveAstVisitor> { memberOrder: _getOrder( closestGroup, declaration.name.lexeme, - declaration.returnType?.type - ?.getDisplayString(withNullability: false) ?? - '_', + declaration.returnType?.type?.getDisplayString() ?? '_', isFlutterWidget, ), ), @@ -151,9 +147,7 @@ class MemberOrderingVisitor extends RecursiveAstVisitor> { memberOrder: _getOrder( closestGroup, declaration.name.lexeme, - declaration.returnType?.type - ?.getDisplayString(withNullability: false) ?? - '_', + declaration.returnType?.type?.getDisplayString() ?? '_', isFlutterWidget, ), ), diff --git a/lib/src/lints/newline_before_return/newline_before_return_rule.dart b/lib/src/lints/newline_before_return/newline_before_return_rule.dart index dfd4c7a..49f479a 100644 --- a/lib/src/lints/newline_before_return/newline_before_return_rule.dart +++ b/lib/src/lints/newline_before_return/newline_before_return_rule.dart @@ -102,7 +102,7 @@ class NewlineBeforeReturnRule extends SolidLintRule { visitor.visitReturnStatement(node); for (final element in visitor.statements) { - reporter.reportErrorForNode(code, element); + reporter.atNode(element, code); } }); } diff --git a/lib/src/lints/no_empty_block/no_empty_block_rule.dart b/lib/src/lints/no_empty_block/no_empty_block_rule.dart index f083ea7..e9b33d3 100644 --- a/lib/src/lints/no_empty_block/no_empty_block_rule.dart +++ b/lib/src/lints/no_empty_block/no_empty_block_rule.dart @@ -80,7 +80,7 @@ class NoEmptyBlockRule extends SolidLintRule { node.accept(visitor); for (final emptyBlock in visitor.emptyBlocks) { - reporter.reportErrorForNode(code, emptyBlock); + reporter.atNode(emptyBlock, code); } }); } diff --git a/lib/src/lints/no_equal_then_else/no_equal_then_else_rule.dart b/lib/src/lints/no_equal_then_else/no_equal_then_else_rule.dart index 31989fe..085cca7 100644 --- a/lib/src/lints/no_equal_then_else/no_equal_then_else_rule.dart +++ b/lib/src/lints/no_equal_then_else/no_equal_then_else_rule.dart @@ -71,7 +71,7 @@ class NoEqualThenElseRule extends SolidLintRule { node.accept(visitor); for (final element in visitor.nodes) { - reporter.reportErrorForNode(code, element); + reporter.atNode(element, code); } }); } diff --git a/lib/src/lints/no_magic_number/no_magic_number_rule.dart b/lib/src/lints/no_magic_number/no_magic_number_rule.dart index b1ba609..2b4c4b2 100644 --- a/lib/src/lints/no_magic_number/no_magic_number_rule.dart +++ b/lib/src/lints/no_magic_number/no_magic_number_rule.dart @@ -178,7 +178,7 @@ class NoMagicNumberRule extends SolidLintRule { .where(_isNotWidgetParameter); for (final magicNumber in magicNumbers) { - reporter.reportErrorForNode(code, magicNumber); + reporter.atNode(magicNumber, code); } }); } @@ -212,8 +212,7 @@ class NoMagicNumberRule extends SolidLintRule { l.thisOrAncestorMatching( (a) => a is InstanceCreationExpression && - a.staticType?.getDisplayString(withNullability: false) == - 'DateTime', + a.staticType?.getDisplayString() == 'DateTime', ) == null; @@ -269,8 +268,7 @@ class NoMagicNumberRule extends SolidLintRule { if (staticType is! InterfaceType) return false; final widgetSupertype = staticType.allSupertypes.firstWhereOrNull( - (supertype) => - supertype.getDisplayString(withNullability: false) == 'Widget', + (supertype) => supertype.getDisplayString() == 'Widget', ); return widgetSupertype != null; diff --git a/lib/src/lints/number_of_parameters/number_of_parameters_rule.dart b/lib/src/lints/number_of_parameters/number_of_parameters_rule.dart index bacc407..2db18b5 100644 --- a/lib/src/lints/number_of_parameters/number_of_parameters_rule.dart +++ b/lib/src/lints/number_of_parameters/number_of_parameters_rule.dart @@ -74,10 +74,10 @@ class NumberOfParametersRule }; if (parameters > config.parameters.maxParameters) { - reporter.reportErrorForOffset( - code, - node.firstTokenAfterCommentAndMetadata.offset, - node.end, + reporter.atOffset( + offset: node.firstTokenAfterCommentAndMetadata.offset, + length: node.end, + errorCode: code, ); } }); diff --git a/lib/src/lints/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart b/lib/src/lints/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart index 71b607f..19ecbb1 100644 --- a/lib/src/lints/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart +++ b/lib/src/lints/prefer_conditional_expressions/prefer_conditional_expressions_rule.dart @@ -91,12 +91,10 @@ class PreferConditionalExpressionsRule node.accept(visitor); for (final element in visitor.statementsInfo) { - reporter.reportErrorForNode( - code, + reporter.atNode( element.statement, - null, - null, - element, + code, + data: element, ); } }); diff --git a/lib/src/lints/prefer_early_return/prefer_early_return_rule.dart b/lib/src/lints/prefer_early_return/prefer_early_return_rule.dart index d3d12d1..304947e 100644 --- a/lib/src/lints/prefer_early_return/prefer_early_return_rule.dart +++ b/lib/src/lints/prefer_early_return/prefer_early_return_rule.dart @@ -61,7 +61,7 @@ class PreferEarlyReturnRule extends SolidLintRule { node.accept(visitor); for (final element in visitor.nodes) { - reporter.reportErrorForNode(code, element); + reporter.atNode(element, code); } }); } diff --git a/lib/src/lints/prefer_first/prefer_first_rule.dart b/lib/src/lints/prefer_first/prefer_first_rule.dart index 5a584be..6dbe6c2 100644 --- a/lib/src/lints/prefer_first/prefer_first_rule.dart +++ b/lib/src/lints/prefer_first/prefer_first_rule.dart @@ -57,7 +57,7 @@ class PreferFirstRule extends SolidLintRule { node.accept(visitor); for (final element in visitor.expressions) { - reporter.reportErrorForNode(code, element); + reporter.atNode(element, code); } }); } diff --git a/lib/src/lints/prefer_last/prefer_last_rule.dart b/lib/src/lints/prefer_last/prefer_last_rule.dart index dae3193..d5fd804 100644 --- a/lib/src/lints/prefer_last/prefer_last_rule.dart +++ b/lib/src/lints/prefer_last/prefer_last_rule.dart @@ -57,7 +57,7 @@ class PreferLastRule extends SolidLintRule { node.accept(visitor); for (final element in visitor.expressions) { - reporter.reportErrorForNode(code, element); + reporter.atNode(element, code); } }); } diff --git a/lib/src/lints/prefer_match_file_name/prefer_match_file_name_rule.dart b/lib/src/lints/prefer_match_file_name/prefer_match_file_name_rule.dart index 4d2d9b7..e719434 100644 --- a/lib/src/lints/prefer_match_file_name/prefer_match_file_name_rule.dart +++ b/lib/src/lints/prefer_match_file_name/prefer_match_file_name_rule.dart @@ -92,12 +92,12 @@ class PreferMatchFileNameRule extends SolidLintRule { final nodeType = humanReadableNodeType(firstDeclaration.parent).toLowerCase(); - reporter.reportErrorForToken( + reporter.atToken( + firstDeclaration.token, LintCode( name: lintName, problemMessage: 'File name does not match with first $nodeType name.', ), - firstDeclaration.token, ); }); } diff --git a/lib/src/lints/proper_super_calls/proper_super_calls_rule.dart b/lib/src/lints/proper_super_calls/proper_super_calls_rule.dart index 166b736..bdeba39 100644 --- a/lib/src/lints/proper_super_calls/proper_super_calls_rule.dart +++ b/lib/src/lints/proper_super_calls/proper_super_calls_rule.dart @@ -119,15 +119,15 @@ class ProperSuperCallsRule extends SolidLintRule { if (!hasOverrideAnnotation) return; if (methodName == _initState && !_isSuperInitStateCalledFirst(statements)) { - reporter.reportErrorForNode( - _superInitStateCode, + reporter.atNode( node, + _superInitStateCode, ); } if (methodName == _dispose && !_isSuperDisposeCalledLast(statements)) { - reporter.reportErrorForNode( - _superDisposeCode, + reporter.atNode( node, + _superDisposeCode, ); } } diff --git a/lib/src/utils/types_utils.dart b/lib/src/utils/types_utils.dart index b34510f..f69b246 100644 --- a/lib/src/utils/types_utils.dart +++ b/lib/src/utils/types_utils.dart @@ -40,7 +40,7 @@ extension Subtypes on DartType { required bool withGenerics, required bool withNullability, }) { - final displayString = getDisplayString(withNullability: withNullability); + final displayString = getDisplayString(); return withGenerics ? displayString : displayString.replaceGenericString(); } @@ -118,26 +118,21 @@ bool isWidgetStateOrSubclass(DartType? type) => bool isSubclassOfListenable(DartType? type) => type is InterfaceType && type.allSupertypes.any(_isListenable); -bool isListViewWidget(DartType? type) => - type?.getDisplayString(withNullability: false) == 'ListView'; +bool isListViewWidget(DartType? type) => type?.getDisplayString() == 'ListView'; bool isSingleChildScrollViewWidget(DartType? type) => - type?.getDisplayString(withNullability: false) == 'SingleChildScrollView'; + type?.getDisplayString() == 'SingleChildScrollView'; -bool isColumnWidget(DartType? type) => - type?.getDisplayString(withNullability: false) == 'Column'; +bool isColumnWidget(DartType? type) => type?.getDisplayString() == 'Column'; -bool isRowWidget(DartType? type) => - type?.getDisplayString(withNullability: false) == 'Row'; +bool isRowWidget(DartType? type) => type?.getDisplayString() == 'Row'; -bool isPaddingWidget(DartType? type) => - type?.getDisplayString(withNullability: false) == 'Padding'; +bool isPaddingWidget(DartType? type) => type?.getDisplayString() == 'Padding'; bool isBuildContext(DartType? type) => - type?.getDisplayString(withNullability: false) == 'BuildContext'; + type?.getDisplayString() == 'BuildContext'; -bool isGameWidget(DartType? type) => - type?.getDisplayString(withNullability: false) == 'GameWidget'; +bool isGameWidget(DartType? type) => type?.getDisplayString() == 'GameWidget'; bool _checkSelfOrSupertypes( DartType? type, @@ -146,8 +141,7 @@ bool _checkSelfOrSupertypes( predicate(type) || (type is InterfaceType && type.allSupertypes.any(predicate)); -bool _isWidget(DartType? type) => - type?.getDisplayString(withNullability: false) == 'Widget'; +bool _isWidget(DartType? type) => type?.getDisplayString() == 'Widget'; bool _isSubclassOfWidget(DartType? type) => type is InterfaceType && type.allSupertypes.any(_isWidget); @@ -173,38 +167,34 @@ bool _isFuture(DartType type) => type is InterfaceType && isWidgetOrSubclass(type.typeArguments.firstOrNull); -bool _isListenable(DartType type) => - type.getDisplayString(withNullability: false) == 'Listenable'; +bool _isListenable(DartType type) => type.getDisplayString() == 'Listenable'; bool _isRenderObject(DartType? type) => - type?.getDisplayString(withNullability: false) == 'RenderObject'; + type?.getDisplayString() == 'RenderObject'; bool _isSubclassOfRenderObject(DartType? type) => type is InterfaceType && type.allSupertypes.any(_isRenderObject); bool _isRenderObjectWidget(DartType? type) => - type?.getDisplayString(withNullability: false) == 'RenderObjectWidget'; + type?.getDisplayString() == 'RenderObjectWidget'; bool _isSubclassOfRenderObjectWidget(DartType? type) => type is InterfaceType && type.allSupertypes.any(_isRenderObjectWidget); bool _isRenderObjectElement(DartType? type) => - type?.getDisplayString(withNullability: false) == 'RenderObjectElement'; + type?.getDisplayString() == 'RenderObjectElement'; bool _isSubclassOfRenderObjectElement(DartType? type) => type is InterfaceType && type.allSupertypes.any(_isRenderObjectElement); bool _isMultiProvider(DartType? type) => - type?.getDisplayString(withNullability: false) == 'MultiProvider'; + type?.getDisplayString() == 'MultiProvider'; bool _isSubclassOfInheritedProvider(DartType? type) => type is InterfaceType && type.allSupertypes.any(_isInheritedProvider); bool _isInheritedProvider(DartType? type) => - type != null && - type - .getDisplayString(withNullability: false) - .startsWith('InheritedProvider<'); + type != null && type.getDisplayString().startsWith('InheritedProvider<'); bool _isIterableInheritedProvider(DartType type) => type.isDartCoreIterable && diff --git a/pubspec.yaml b/pubspec.yaml index b6346b4..eea0b1a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,12 +8,12 @@ documentation: https://solid-software.github.io/solid_lints/docs/intro topics: [lints, linter, lint, analysis, analyzer] environment: - sdk: '>=3.0.0 <4.0.0' + sdk: ">=3.0.0 <4.0.0" dependencies: - analyzer: ^6.2.0 + analyzer: ^6.6.0 collection: ^1.17.2 - custom_lint_builder: ^0.6.0 + custom_lint_builder: ^0.6.7 glob: ^2.1.2 path: ^1.8.3 yaml: ^3.1.2 From 7391a6a9f25884b572e30dfee06ab2cc5f2dde7c Mon Sep 17 00:00:00 2001 From: solid-glebvorobey <132369081+solid-glebvorobey@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:42:52 +0200 Subject: [PATCH 2/8] Fixed LintCode issue --- example/pubspec.yaml | 4 ++-- lib/src/models/rule_config.dart | 2 +- pubspec.yaml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 030fcd5..64a0b9e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,14 +3,14 @@ description: A starting point for Dart libraries or applications. publish_to: none environment: - sdk: '>=3.0.0 <4.0.0' + sdk: ">=3.0.0 <4.0.0" dependencies: flutter: sdk: flutter dev_dependencies: - custom_lint: ^0.6.0 + custom_lint: ^0.6.7 solid_lints: path: ../ test: ^1.20.1 diff --git a/lib/src/models/rule_config.dart b/lib/src/models/rule_config.dart index d2429b9..ffc170a 100644 --- a/lib/src/models/rule_config.dart +++ b/lib/src/models/rule_config.dart @@ -1,4 +1,4 @@ -import 'package:analyzer/error/error.dart'; +import 'package:analyzer/error/error.dart' hide LintCode; import 'package:custom_lint_builder/custom_lint_builder.dart'; /// Type definition of a value factory which allows us to map data from diff --git a/pubspec.yaml b/pubspec.yaml index eea0b1a..948d5ee 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,10 +8,10 @@ documentation: https://solid-software.github.io/solid_lints/docs/intro topics: [lints, linter, lint, analysis, analyzer] environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.5.0 <4.0.0" dependencies: - analyzer: ^6.6.0 + analyzer: ^6.7.0 collection: ^1.17.2 custom_lint_builder: ^0.6.7 glob: ^2.1.2 From f52dbb6c88c7c701f06f4d3fb1e70b5122c3097b Mon Sep 17 00:00:00 2001 From: solid-glebvorobey <132369081+solid-glebvorobey@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:54:27 +0200 Subject: [PATCH 3/8] Fixed LintCode issue --- .../avoid_unnecessary_type_assertions_rule.dart | 2 +- .../lints/double_literal_format/double_literal_format_rule.dart | 2 +- lib/src/utils/parameter_utils.dart | 2 +- pubspec.yaml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart b/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart index 20d088c..dc117c3 100644 --- a/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart +++ b/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart @@ -1,6 +1,6 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:analyzer/error/error.dart'; +import 'package:analyzer/error/error.dart' hide LintCode; import 'package:analyzer/error/listener.dart'; import 'package:analyzer/source/source_range.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; diff --git a/lib/src/lints/double_literal_format/double_literal_format_rule.dart b/lib/src/lints/double_literal_format/double_literal_format_rule.dart index d32664b..6ad34d6 100644 --- a/lib/src/lints/double_literal_format/double_literal_format_rule.dart +++ b/lib/src/lints/double_literal_format/double_literal_format_rule.dart @@ -1,4 +1,4 @@ -import 'package:analyzer/error/error.dart'; +import 'package:analyzer/error/error.dart' hide LintCode; import 'package:analyzer/error/listener.dart'; import 'package:analyzer/source/source_range.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; diff --git a/lib/src/utils/parameter_utils.dart b/lib/src/utils/parameter_utils.dart index fdbd647..b7eff59 100644 --- a/lib/src/utils/parameter_utils.dart +++ b/lib/src/utils/parameter_utils.dart @@ -1,5 +1,5 @@ import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/error/error.dart'; +import 'package:analyzer/error/error.dart' hide LintCode; import 'package:custom_lint_builder/custom_lint_builder.dart'; /// Checks if parameter name consists only of underscores diff --git a/pubspec.yaml b/pubspec.yaml index eea0b1a..06fb954 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - analyzer: ^6.6.0 + analyzer: ^6.9.0 collection: ^1.17.2 custom_lint_builder: ^0.6.7 glob: ^2.1.2 From 9f2fb029db09a9d517ac495f3cba149e0a2d9b50 Mon Sep 17 00:00:00 2001 From: solid-glebvorobey <132369081+solid-glebvorobey@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:55:16 +0200 Subject: [PATCH 4/8] Fixed pubspec --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 06fb954..eea0b1a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - analyzer: ^6.9.0 + analyzer: ^6.6.0 collection: ^1.17.2 custom_lint_builder: ^0.6.7 glob: ^2.1.2 From eb854d0d20080c19c78786454f9c1152d40e1e98 Mon Sep 17 00:00:00 2001 From: solid-glebvorobey <132369081+solid-glebvorobey@users.noreply.github.com> Date: Wed, 18 Sep 2024 22:20:13 +0200 Subject: [PATCH 5/8] Try to update analyzer version --- .../avoid_unnecessary_type_assertions_rule.dart | 2 +- .../lints/double_literal_format/double_literal_format_rule.dart | 2 +- lib/src/models/rule_config.dart | 2 +- lib/src/utils/parameter_utils.dart | 2 +- pubspec.yaml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart b/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart index dc117c3..20d088c 100644 --- a/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart +++ b/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart @@ -1,6 +1,6 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:analyzer/error/error.dart' hide LintCode; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/error/listener.dart'; import 'package:analyzer/source/source_range.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; diff --git a/lib/src/lints/double_literal_format/double_literal_format_rule.dart b/lib/src/lints/double_literal_format/double_literal_format_rule.dart index 6ad34d6..d32664b 100644 --- a/lib/src/lints/double_literal_format/double_literal_format_rule.dart +++ b/lib/src/lints/double_literal_format/double_literal_format_rule.dart @@ -1,4 +1,4 @@ -import 'package:analyzer/error/error.dart' hide LintCode; +import 'package:analyzer/error/error.dart'; import 'package:analyzer/error/listener.dart'; import 'package:analyzer/source/source_range.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; diff --git a/lib/src/models/rule_config.dart b/lib/src/models/rule_config.dart index ffc170a..d2429b9 100644 --- a/lib/src/models/rule_config.dart +++ b/lib/src/models/rule_config.dart @@ -1,4 +1,4 @@ -import 'package:analyzer/error/error.dart' hide LintCode; +import 'package:analyzer/error/error.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; /// Type definition of a value factory which allows us to map data from diff --git a/lib/src/utils/parameter_utils.dart b/lib/src/utils/parameter_utils.dart index b7eff59..fdbd647 100644 --- a/lib/src/utils/parameter_utils.dart +++ b/lib/src/utils/parameter_utils.dart @@ -1,5 +1,5 @@ import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/error/error.dart' hide LintCode; +import 'package:analyzer/error/error.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; /// Checks if parameter name consists only of underscores diff --git a/pubspec.yaml b/pubspec.yaml index eea0b1a..4a3f329 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - analyzer: ^6.6.0 + analyzer: ^6.7.0 collection: ^1.17.2 custom_lint_builder: ^0.6.7 glob: ^2.1.2 From b328197252e46da9b91c69c094633541ed4e25a4 Mon Sep 17 00:00:00 2001 From: solid-glebvorobey <132369081+solid-glebvorobey@users.noreply.github.com> Date: Wed, 18 Sep 2024 22:24:24 +0200 Subject: [PATCH 6/8] Try to override analyzer dependency --- pubspec.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pubspec.yaml b/pubspec.yaml index 4a3f329..d2b769f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,3 +24,6 @@ dev_dependencies: flutter: sdk: flutter test: ^1.24.6 + +dependency_overrides: + analyzer: ^6.6.0 From 96e53f9670446215b89b5b7787556115fe8551c6 Mon Sep 17 00:00:00 2001 From: solid-glebvorobey <132369081+solid-glebvorobey@users.noreply.github.com> Date: Thu, 19 Sep 2024 02:45:45 +0200 Subject: [PATCH 7/8] Add import as instead of hide --- .../avoid_unnecessary_type_assertions_rule.dart | 2 +- .../avoid_unnecessary_type_assertions_fix.dart | 4 ++-- .../double_literal_format_rule.dart | 2 +- .../fixes/double_literal_format_fix.dart | 4 ++-- lib/src/models/rule_config.dart | 4 ++-- lib/src/utils/parameter_utils.dart | 14 +++++++------- pubspec.yaml | 3 --- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart b/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart index 20d088c..c973b60 100644 --- a/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart +++ b/lib/src/lints/avoid_unnecessary_type_assertions/avoid_unnecessary_type_assertions_rule.dart @@ -1,6 +1,6 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/element/type.dart'; -import 'package:analyzer/error/error.dart'; +import 'package:analyzer/error/error.dart' as error; import 'package:analyzer/error/listener.dart'; import 'package:analyzer/source/source_range.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; diff --git a/lib/src/lints/avoid_unnecessary_type_assertions/fixes/avoid_unnecessary_type_assertions_fix.dart b/lib/src/lints/avoid_unnecessary_type_assertions/fixes/avoid_unnecessary_type_assertions_fix.dart index 90c1c91..40afae0 100644 --- a/lib/src/lints/avoid_unnecessary_type_assertions/fixes/avoid_unnecessary_type_assertions_fix.dart +++ b/lib/src/lints/avoid_unnecessary_type_assertions/fixes/avoid_unnecessary_type_assertions_fix.dart @@ -8,8 +8,8 @@ class _UnnecessaryTypeAssertionsFix extends DartFix { CustomLintResolver resolver, ChangeReporter reporter, CustomLintContext context, - AnalysisError analysisError, - List others, + error.AnalysisError analysisError, + List others, ) { context.registry.addIsExpression((node) { if (analysisError.sourceRange.intersects(node.sourceRange)) { diff --git a/lib/src/lints/double_literal_format/double_literal_format_rule.dart b/lib/src/lints/double_literal_format/double_literal_format_rule.dart index d32664b..45429ef 100644 --- a/lib/src/lints/double_literal_format/double_literal_format_rule.dart +++ b/lib/src/lints/double_literal_format/double_literal_format_rule.dart @@ -1,4 +1,4 @@ -import 'package:analyzer/error/error.dart'; +import 'package:analyzer/error/error.dart' as error; import 'package:analyzer/error/listener.dart'; import 'package:analyzer/source/source_range.dart'; import 'package:custom_lint_builder/custom_lint_builder.dart'; diff --git a/lib/src/lints/double_literal_format/fixes/double_literal_format_fix.dart b/lib/src/lints/double_literal_format/fixes/double_literal_format_fix.dart index 2bc7e87..6452df8 100644 --- a/lib/src/lints/double_literal_format/fixes/double_literal_format_fix.dart +++ b/lib/src/lints/double_literal_format/fixes/double_literal_format_fix.dart @@ -8,8 +8,8 @@ class _DoubleLiteralFormatFix extends DartFix { CustomLintResolver resolver, ChangeReporter reporter, CustomLintContext context, - AnalysisError analysisError, - List others, + error.AnalysisError analysisError, + List others, ) { context.registry.addDoubleLiteral((node) { // checks that the literal declaration is where our warning is located diff --git a/lib/src/models/rule_config.dart b/lib/src/models/rule_config.dart index d2429b9..23f08f3 100644 --- a/lib/src/models/rule_config.dart +++ b/lib/src/models/rule_config.dart @@ -1,4 +1,4 @@ -import 'package:analyzer/error/error.dart'; +import 'package:analyzer/error/error.dart' as error; import 'package:custom_lint_builder/custom_lint_builder.dart'; /// Type definition of a value factory which allows us to map data from @@ -38,6 +38,6 @@ class RuleConfig { LintCode get lintCode => LintCode( name: name, problemMessage: _problemMessageFactory(parameters), - errorSeverity: ErrorSeverity.WARNING, + errorSeverity: error.ErrorSeverity.WARNING, ); } diff --git a/lib/src/utils/parameter_utils.dart b/lib/src/utils/parameter_utils.dart index fdbd647..df04597 100644 --- a/lib/src/utils/parameter_utils.dart +++ b/lib/src/utils/parameter_utils.dart @@ -1,5 +1,5 @@ import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/error/error.dart'; +import 'package:analyzer/error/error.dart' as error; import 'package:custom_lint_builder/custom_lint_builder.dart'; /// Checks if parameter name consists only of underscores @@ -12,12 +12,12 @@ bool nameConsistsOfUnderscoresOnly(FormalParameter parameter) { } /// Decodes the severity parameter from the string -ErrorSeverity? decodeErrorSeverity(String? severity) { +error.ErrorSeverity? decodeErrorSeverity(String? severity) { return switch (severity?.toLowerCase()) { - 'info' => ErrorSeverity.INFO, - 'warning' => ErrorSeverity.WARNING, - 'error' => ErrorSeverity.ERROR, - 'none' => ErrorSeverity.NONE, + 'info' => error.ErrorSeverity.INFO, + 'warning' => error.ErrorSeverity.WARNING, + 'error' => error.ErrorSeverity.ERROR, + 'none' => error.ErrorSeverity.NONE, _ => null, }; } @@ -31,7 +31,7 @@ extension LintCodeCopyWith on LintCode { String? correctionMessage, String? uniqueName, String? url, - ErrorSeverity? errorSeverity, + error.ErrorSeverity? errorSeverity, }) => LintCode( name: name ?? this.name, diff --git a/pubspec.yaml b/pubspec.yaml index d2b769f..4a3f329 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,6 +24,3 @@ dev_dependencies: flutter: sdk: flutter test: ^1.24.6 - -dependency_overrides: - analyzer: ^6.6.0 From 60463cc75d9a87c4fe00efde5e16a4d5eb554f6f Mon Sep 17 00:00:00 2001 From: solid-glebvorobey <132369081+solid-glebvorobey@users.noreply.github.com> Date: Thu, 19 Sep 2024 03:06:46 +0200 Subject: [PATCH 8/8] Fixed tests fpr custom linter to work correctly --- .../alphabetize_by_type_test.dart | 7 +- ...d_late_keyword_allow_initialized_test.dart | 12 +- .../avoid_late_keyword_no_generics_test.dart | 10 + ...avoid_late_keyword_with_generics_test.dart | 13 + .../avoid_returning_widget_test.dart | 2 + .../external_source/lib/banned_library.dart | 1 + .../external_source/lib/external_source.dart | 17 +- .../function_lines_of_code_test.dart | 448 +++++++++++++++++- ..._number_allowed_in_widget_params_test.dart | 5 + ...tional_expressions_ignore_nested_test.dart | 4 +- 10 files changed, 495 insertions(+), 24 deletions(-) diff --git a/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart b/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart index bd7522a..498188f 100644 --- a/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart +++ b/lint_test/alphabetize_by_type_test/alphabetize_by_type_test.dart @@ -1,19 +1,20 @@ // ignore_for_file: unused_field // ignore_for_file: unused_element +// ignore_for_file: prefer_match_file_name /// Check the `member_ordering` rule /// alphabetical-by-type option enabled class CorrectAlphabeticalByTypeClass { - final double e = 1; final int a = 1; + final double e = 1; } class WrongAlphabeticalByTypeClass { - final int a = 1; + final int e = 1; // expect_lint: member_ordering - final double e = 1; + final double a = 1; } class PartiallyWrongAlphabeticalByTypeClass { diff --git a/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart b/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart index 04dbfe1..8136b96 100644 --- a/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart +++ b/lint_test/avoid_late_keyword/allow_initialized/avoid_late_keyword_allow_initialized_test.dart @@ -14,6 +14,7 @@ class ColorTween {} /// `avoid_late_keyword` /// allow_initialized option disabled class AvoidLateKeyword { + /// expect_lint: avoid_late_keyword late final Animation animation1; late final animation2 = AnimationController(); @@ -23,27 +24,25 @@ class AvoidLateKeyword { /// 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; + /// expect_lint: avoid_late_keyword 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() { + /// expect_lint: avoid_late_keyword late final Animation animation1; late final animation2 = AnimationController(); @@ -53,21 +52,18 @@ class AvoidLateKeyword { /// 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; + /// expect_lint: avoid_late_keyword 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 diff --git a/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart b/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart index 486b193..12fea48 100644 --- a/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart +++ b/lint_test/avoid_late_keyword/no_generics/avoid_late_keyword_no_generics_test.dart @@ -15,28 +15,38 @@ class AvoidLateKeyword { /// expect_lint: avoid_late_keyword late final NotAllowed na1; + /// expect_lint: avoid_late_keyword late final Subscription subscription1; + /// expect_lint: avoid_late_keyword late final Subscription subscription2; + /// expect_lint: avoid_late_keyword late final Subscription> subscription3; + /// expect_lint: avoid_late_keyword late final Subscription>> subscription4; + /// expect_lint: avoid_late_keyword late final Subscription> subscription5; void test() { /// expect_lint: avoid_late_keyword late final NotAllowed na1; + /// expect_lint: avoid_late_keyword late final Subscription subscription1; + /// expect_lint: avoid_late_keyword late final Subscription subscription2; + /// expect_lint: avoid_late_keyword late final Subscription> subscription3; + /// expect_lint: avoid_late_keyword late final Subscription>> subscription4; + /// expect_lint: avoid_late_keyword late final Subscription> subscription5; } } diff --git a/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart b/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart index a046821..576ade7 100644 --- a/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart +++ b/lint_test/avoid_late_keyword/with_generics/avoid_late_keyword_with_generics_test.dart @@ -18,10 +18,13 @@ class ConcreteTypeWithNoGenerics {} /// `avoid_late_keyword` /// allow_initialized option enabled class AvoidLateKeyword { + /// expect_lint: avoid_late_keyword late final ColorTween colorTween; + /// expect_lint: avoid_late_keyword late final AnimationController controller1; + /// expect_lint: avoid_late_keyword late final SubAnimationController controller2; late final controller3 = AnimationController(); @@ -44,24 +47,32 @@ class AvoidLateKeyword { /// expect_lint: avoid_late_keyword late final Subscription subscription1; + /// expect_lint: avoid_late_keyword late final Subscription subscription2; + /// expect_lint: avoid_late_keyword late final Subscription> subscription3; + /// expect_lint: avoid_late_keyword late final Subscription>> subscription4; + /// expect_lint: avoid_late_keyword late final Subscription> subscription5; + /// expect_lint: avoid_late_keyword late final Subscription> subscription6; /// expect_lint: avoid_late_keyword late final Subscription> subscription7; void test() { + /// expect_lint: avoid_late_keyword late final ColorTween colorTween; + /// expect_lint: avoid_late_keyword late final AnimationController controller1; + /// expect_lint: avoid_late_keyword late final SubAnimationController controller2; late final controller3 = AnimationController(); @@ -84,8 +95,10 @@ class AvoidLateKeyword { /// expect_lint: avoid_late_keyword late final Subscription subscription1; + /// expect_lint: avoid_late_keyword late final Subscription subscription2; + /// expect_lint: avoid_late_keyword late final Subscription> subscription3; } } diff --git a/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart b/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart index ff20d27..a1f3677 100644 --- a/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart +++ b/lint_test/avoid_returning_widget_test/avoid_returning_widget_test.dart @@ -65,6 +65,7 @@ Widget build() { return Offstage(); } +// expect_lint: avoid_returning_widgets SizedBox excludeMethod() => const SizedBox(); class ExcludeWidget extends StatelessWidget { @@ -75,6 +76,7 @@ class ExcludeWidget extends StatelessWidget { return const Placeholder(); } + // expect_lint: avoid_returning_widgets Widget excludeWidgetMethod() => const SizedBox(); // expect_lint: avoid_returning_widgets diff --git a/lint_test/avoid_using_api/external_source/lib/banned_library.dart b/lint_test/avoid_using_api/external_source/lib/banned_library.dart index d36ffcd..abad480 100644 --- a/lint_test/avoid_using_api/external_source/lib/banned_library.dart +++ b/lint_test/avoid_using_api/external_source/lib/banned_library.dart @@ -1 +1,2 @@ +// expect_lint: avoid_global_state int banned = 5; diff --git a/lint_test/avoid_using_api/external_source/lib/external_source.dart b/lint_test/avoid_using_api/external_source/lib/external_source.dart index 2bab9af..4b2d78d 100644 --- a/lint_test/avoid_using_api/external_source/lib/external_source.dart +++ b/lint_test/avoid_using_api/external_source/lib/external_source.dart @@ -1,20 +1,25 @@ -class BannedCodeUsage { - BannedCodeUsage(); - static String test2() { - return 'Hello World'; - } +// ignore_for_file: prefer_match_file_name +// ignore_for_file: no_empty_block +class BannedCodeUsage { final String test4 = 'Hello World'; - void test() {} + BannedCodeUsage(); factory BannedCodeUsage.test3() { return BannedCodeUsage(); } + + void test() {} + + static String test2() { + return 'Hello World'; + } } const test2 = 'Hello World'; void test() {} +// expect_lint: avoid_global_state int banned = 5; diff --git a/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart b/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart index aa4211a..e35d5d6 100644 --- a/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart +++ b/lint_test/function_lines_of_code_test/function_lines_of_code_test.dart @@ -1,29 +1,278 @@ +// ignore_for_file: prefer_match_file_name + class ClassWithLongMethods { - int notLongMethod() { + // expect_lint: function_lines_of_code + int longMethod() { var i = 0; i++; i++; i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + return i; } - // expect_lint: function_lines_of_code - int longMethod() { + // Excluded by excludeNames + int longMethodExcluded() { var i = 0; i++; i++; i++; i++; + return i; } - // Excluded by excludeNames - int longMethodExcluded() { + int notLongMethod() { var i = 0; i++; i++; i++; - i++; + return i; } } @@ -33,6 +282,7 @@ int notLongFunction() { i++; i++; i++; + return i; } @@ -43,6 +293,191 @@ int longFunction() { i++; i++; i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + i++; + return i; } @@ -53,5 +488,6 @@ int longFunctionExcluded() { i++; i++; i++; + return i; } diff --git a/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart b/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart index a01e12f..7d603d2 100644 --- a/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart +++ b/lint_test/no_magic_number_allowed_in_widget_params_test/no_magic_number_allowed_in_widget_params_test.dart @@ -1,3 +1,6 @@ +// ignore_for_file: avoid_returning_widgets +// ignore_for_file: prefer_match_file_name + // Allowed for numbers in a Widget subtype parameters. abstract interface class Widget {} @@ -21,7 +24,9 @@ class MyWidgetDecoration { Widget build() { return MyWidget( + // expect_lint: no_magic_number decoration: MyWidgetDecoration(size: 12), + // expect_lint: no_magic_number value: 23, ); } diff --git a/lint_test/prefer_conditional_expressions_ignore_nested_test/prefer_conditional_expressions_ignore_nested_test.dart b/lint_test/prefer_conditional_expressions_ignore_nested_test/prefer_conditional_expressions_ignore_nested_test.dart index 954e77f..150b9e4 100644 --- a/lint_test/prefer_conditional_expressions_ignore_nested_test/prefer_conditional_expressions_ignore_nested_test.dart +++ b/lint_test/prefer_conditional_expressions_ignore_nested_test/prefer_conditional_expressions_ignore_nested_test.dart @@ -8,7 +8,9 @@ void fun() { // Allowed because ignore_nested flag is enabled if (1 > 0) { - _result = 1 > 2 ? 2 : 1; + if (true) { + _result = 1 > 0 ? 0 : 1; + } } else { _result = 0; }