This repository was archived by the owner on Nov 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ class _Visitor extends SimpleAstVisitor<void> {
9696 return ;
9797 }
9898 } else if (parent is MethodInvocation ) {
99+ if (expression is CascadeExpression ) return ;
99100 var name = parent.methodName.name;
100101 if (name == 'noSuchMethod' || name == 'toString' ) {
101102 // Code like `(String).noSuchMethod()` is allowed.
Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ import 'unnecessary_library_directive_test.dart'
8888 as unnecessary_library_directive;
8989import 'unnecessary_null_checks_test.dart' as unnecessary_null_checks;
9090import 'unnecessary_overrides_test.dart' as unnecessary_overrides;
91+ import 'unnecessary_parenthesis_test.dart' as unnecessary_parenthesis;
9192import 'use_build_context_synchronously_test.dart'
9293 as use_build_context_synchronously;
9394import 'use_enums_test.dart' as use_enums;
@@ -160,6 +161,7 @@ void main() {
160161 unnecessary_library_directive.main ();
161162 unnecessary_null_checks.main ();
162163 unnecessary_overrides.main ();
164+ unnecessary_parenthesis.main ();
163165 use_build_context_synchronously.main ();
164166 use_enums.main ();
165167 use_is_even_rather_than_modulo.main ();
Original file line number Diff line number Diff line change 1+ // Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+ // for details. All rights reserved. Use of this source code is governed by a
3+ // BSD-style license that can be found in the LICENSE file.
4+
5+ import 'package:test_reflective_loader/test_reflective_loader.dart' ;
6+
7+ import '../rule_test_support.dart' ;
8+
9+ main () {
10+ defineReflectiveSuite (() {
11+ defineReflectiveTests (UnnecessaryParenthesisTest );
12+ });
13+ }
14+
15+ @reflectiveTest
16+ class UnnecessaryParenthesisTest extends LintRuleTest {
17+ @override
18+ String get lintRule => 'unnecessary_parenthesis' ;
19+
20+ /// https://github.com/dart-lang/linter/issues/4041
21+ test_nullAware_cascadeAssignment () async {
22+ await assertNoDiagnostics (r'''
23+ class A {
24+ var b = false;
25+ void m() {}
26+ }
27+
28+ void f(A? a) {
29+ (a?..b = true)?.m();
30+ }
31+ ''' );
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments