Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit a84d93d

Browse files
committed
fix: ignore override methods for avoid-redundant-async
1 parent 16d0cb5 commit a84d93d

File tree

3 files changed

+10
-1
lines changed
  • lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async
  • test/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/examples

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* feat: **Breaking change** cleanup public API.
1515
* chore: restrict `analyzer` version to `>=5.1.0 <5.3.0`.
1616
* feat: add `print-config` option to all commands.
17+
* fix: ignore `@override` methods for [`avoid-redundant-async`](https://dartcodemetrics.dev/docs/rules/common/avoid-redundant-async).
1718

1819
## 4.21.2
1920

lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/visitor.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ class _Visitor extends RecursiveAstVisitor<void> {
99
void visitMethodDeclaration(MethodDeclaration node) {
1010
super.visitMethodDeclaration(node);
1111

12-
if (_hasRedundantAsync(node.body)) {
12+
final isOverride = node.metadata.any(
13+
(node) =>
14+
node.name.name == 'override' && node.atSign.type == TokenType.AT,
15+
);
16+
17+
if (!isOverride && _hasRedundantAsync(node.body)) {
1318
_declarations.add(node);
1419
}
1520
}

test/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/examples/example.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class SomeClass {
2121
// LINT
2222
Future<String> anotherAsyncMethod() async => Future.value('value');
2323

24+
@override
25+
Future<String> overrideMethod() async => Future.value('value');
26+
2427
Future<String> someAsyncMethod(Future<String> later) => later;
2528

2629
Future<void> report(Iterable<String> records) async {

0 commit comments

Comments
 (0)