diff --git a/CHANGELOG.md b/CHANGELOG.md index 876bfb4e63..0436331821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * chore: changed min `SDK` version to `2.18.0`. * chore: restrict `analyzer` version to `>=5.1.0 <5.2.0`. * chore: restrict `analyzer_plugin` version to `>=0.11.0 <0.12.0`. +* fix: make [`avoid-redundant-async`](https://dartcodemetrics.dev/docs/rules/common/avoid-redundant-async) correctly handle yield. ## 4.19.1 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 c22e6077f7..ac20a6c094 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 @@ -73,4 +73,11 @@ class _AsyncVisitor extends RecursiveAstVisitor { hasValidAsync = true; } + + @override + void visitYieldStatement(YieldStatement node) { + super.visitYieldStatement(node); + + hasValidAsync = true; + } } 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 638818bb16..5cc9318cba 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 @@ -34,4 +34,10 @@ class SomeClass { Future returnNullable(SomeClass? instance) async { return instance?.report([]); } + + Stream buildStream() async* { + for (int i = 0; i < 10; i++) { + yield i; + } + } }