commit | fe05845b453536a8c2b6c102be712fe8fa6d7c0a | [log] [tgz] |
---|---|---|
author | Sam Rawlins <srawlins@google.com> | Fri Mar 29 16:30:53 2024 +0000 |
committer | Commit Queue <dart-scoped@luci-project-accounts.iam.gserviceaccount.com> | Fri Mar 29 16:30:53 2024 +0000 |
tree | 80e21a1e53906f0474c3f4e4b8811a03156167ac | |
parent | 6e0978be76ae44d342b77d0486f05ae20842b733 [diff] |
linter: allow unnecessary parens in spreads Fixes https://github.com/dart-lang/linter/issues/3816 Change-Id: I3e5928e939de18b95cb27d2214a16b045c9aabc0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360400 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/linter/lib/src/rules/unnecessary_parenthesis.dart b/pkg/linter/lib/src/rules/unnecessary_parenthesis.dart index dc3f260..6332d29 100644 --- a/pkg/linter/lib/src/rules/unnecessary_parenthesis.dart +++ b/pkg/linter/lib/src/rules/unnecessary_parenthesis.dart
@@ -94,6 +94,9 @@ // `case const (a + b):` is OK. if (parent is ConstantPattern) return; + // `[...(p as List)]` is OK. + if (parent is SpreadElement) return; + // Don't over-report on records missing trailing commas. // `(int,) r = (3);` is OK. if (parent is VariableDeclaration &&
diff --git a/pkg/linter/test/rules/unnecessary_parenthesis_test.dart b/pkg/linter/test/rules/unnecessary_parenthesis_test.dart index 27ff412..ce79949 100644 --- a/pkg/linter/test/rules/unnecessary_parenthesis_test.dart +++ b/pkg/linter/test/rules/unnecessary_parenthesis_test.dart
@@ -205,6 +205,22 @@ ]); } + test_spread() async { + await assertNoDiagnostics(r''' +void f(Object p) { + [...(p as List)]; +} +'''); + } + + test_spread_nullAware() async { + await assertNoDiagnostics(r''' +void f(Object? p) { + [...?(p as List?)]; +} +'''); + } + test_switchExpression_expressionStatement() async { await assertNoDiagnostics(r''' void f(Object? x) {