Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit ef46492

Browse files
authored
Fix unnecessary_parenthesis with postfix bang operator. (#3904)
#3848
1 parent 994faac commit ef46492

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/src/rules/unnecessary_parenthesis.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/ast/ast.dart';
6+
import 'package:analyzer/dart/ast/token.dart';
67
import 'package:analyzer/dart/ast/visitor.dart';
78

89
import '../analyzer.dart';
@@ -104,6 +105,9 @@ class _Visitor extends SimpleAstVisitor<void> {
104105
// Code like `(String).noSuchMethod()` is allowed.
105106
return;
106107
}
108+
} else if (parent is PostfixExpression &&
109+
parent.operator.type == TokenType.BANG) {
110+
return;
107111
}
108112
rule.reportLint(node);
109113
return;

test_data/rules/unnecessary_parenthesis.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ main() async {
120120
(a?.abs()).hashCode;
121121
(a?..abs()).hashCode;
122122
(a?[0]).hashCode;
123+
124+
(a?.sign)!;
125+
(a?.abs())!;
126+
(a?..abs())!;
127+
(a?[0])!;
123128
}
124129

125130
Invocation? invocation() => null;

0 commit comments

Comments
 (0)