diff --git a/CHANGELOG.md b/CHANGELOG.md index 0120205fc9..243dc66eeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * feat: **Breaking change** cleanup public API. * chore: restrict `analyzer` version to `>=5.1.0 <5.3.0`. * feat: add `print-config` option to all commands. +* fix: ignore `@override` methods for [`avoid-redundant-async`](https://dartcodemetrics.dev/docs/rules/common/avoid-redundant-async). ## 4.21.2 diff --git a/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/visitor.dart b/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/visitor.dart index ac20a6c094..791a0550aa 100644 --- a/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/visitor.dart +++ b/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/visitor.dart @@ -9,7 +9,12 @@ class _Visitor extends RecursiveAstVisitor { void visitMethodDeclaration(MethodDeclaration node) { super.visitMethodDeclaration(node); - if (_hasRedundantAsync(node.body)) { + final isOverride = node.metadata.any( + (node) => + node.name.name == 'override' && node.atSign.type == TokenType.AT, + ); + + if (!isOverride && _hasRedundantAsync(node.body)) { _declarations.add(node); } } diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/examples/example.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/examples/example.dart index 5cc9318cba..8db8fa3797 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/examples/example.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/examples/example.dart @@ -21,6 +21,9 @@ class SomeClass { // LINT Future anotherAsyncMethod() async => Future.value('value'); + @override + Future overrideMethod() async => Future.value('value'); + Future someAsyncMethod(Future later) => later; Future report(Iterable records) async {