From fc6b52b3239ee325f18524fdb01a7e732698f13e Mon Sep 17 00:00:00 2001 From: solid-glebvorobey <132369081+solid-glebvorobey@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:09:13 +0200 Subject: [PATCH] Fixed analyzer issue, fixed linter (#177) --- .../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