Skip to content

Commit 1345cdf

Browse files
munificentCommit Queue
authored andcommitted
Roll dart_style 3.1.0 into the SDK.
Change-Id: I6392327cadce5194dabaa719bff945868a690225 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419990 Auto-Submit: Bob Nystrom <[email protected]> Reviewed-by: Alexander Thomas <[email protected]> Commit-Queue: Alexander Thomas <[email protected]>
1 parent aaba96a commit 1345cdf

File tree

5 files changed

+189
-12
lines changed

5 files changed

+189
-12
lines changed

CHANGELOG.md

Lines changed: 169 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
- (Thanks [@FMorschel](https://github.com/FMorschel) for many of the above
7474
enhancements!)
7575

76-
7776
[`unnecessary_ignore`]: http://dart.dev/lints/unnecessary_ignore
7877

7978
#### Dart Development Compiler (dartdevc)
@@ -90,6 +89,175 @@ disallowed.
9089

9190
Removed the `--experiment-new-rti` and `--use-old-rti` flags.
9291

92+
#### Dart format
93+
94+
In 3.7.0, we released a largely rewritten formatter supporting a new
95+
["tall" style][tall style]. Since then, we've gotten a lot of feedback and bug
96+
reports and made a number of fixes in response to that.
97+
98+
[tall style]: https://github.com/dart-lang/dart_style/issues/1253
99+
100+
### Features
101+
102+
Some users strongly prefer the old behavior where a trailing comma will be
103+
preserved by the formatter and force the surrounding construct to split. That
104+
behavior is supported again (but off by default) and can enabled by adding this
105+
to a surrounding `analysis_options.yaml` file:
106+
107+
```yaml
108+
formatter:
109+
trailing_commas: preserve
110+
```
111+
112+
This is similar to how trailing commas work in the old short style formatter
113+
applied to code before language version 3.7.
114+
115+
### Bug fixes
116+
117+
* Don't add a trailing comma in lists that don't allow it, even when there is
118+
a trailing comment (#1639).
119+
120+
### Style changes
121+
122+
The following style changes are language versioned and only affect code whose
123+
language version is 3.8 or later. Dart code at 3.7 or earlier is formatted the
124+
same as it was before.
125+
126+
* Allow more code on the same line as a named argument or `=>`.
127+
128+
```dart
129+
// Before:
130+
function(
131+
name:
132+
(param) => another(
133+
argument1,
134+
argument2,
135+
),
136+
);
137+
138+
// After:
139+
function(
140+
name: (param) => another(
141+
argument1,
142+
argument3,
143+
),
144+
);
145+
```
146+
147+
* Allow the target or property chain part of a split method chain on the RHS of
148+
`=`, `:`, and `=>`.
149+
150+
```dart
151+
// Before:
152+
variable =
153+
target.property
154+
.method()
155+
.another();
156+
157+
// After:
158+
variable = target.property
159+
.method()
160+
.another();
161+
```
162+
163+
* Allow the condition part of a split conditional expression on the RHS of `=`,
164+
`:`, and `=>`.
165+
166+
```dart
167+
// Before:
168+
variable =
169+
condition
170+
? longThenBranch
171+
: longElseBranch;
172+
173+
// After:
174+
variable = condition
175+
? longThenBranch
176+
: longElseBranch;
177+
```
178+
179+
* Don't indent conditional branches redundantly after `=`, `:`, and `=>`.
180+
181+
```dart
182+
// Before:
183+
function(
184+
argument:
185+
condition
186+
? thenBranch
187+
: elseBranch,
188+
)
189+
190+
// After:
191+
function(
192+
argument:
193+
condition
194+
? thenBranch
195+
: elseBranch,
196+
)
197+
```
198+
199+
* Indent conditional branches past the operators.
200+
201+
```dart
202+
// Before:
203+
condition
204+
? thenBranch +
205+
anotherOperand
206+
: elseBranch(
207+
argument,
208+
);
209+
210+
// After:
211+
condition
212+
? thenBranch +
213+
anotherOperand
214+
: elseBranch(
215+
argument,
216+
);
217+
```
218+
219+
* Block format record types in typedefs:
220+
221+
```dart
222+
// Before:
223+
typedef ExampleRecordTypedef =
224+
(
225+
String firstParameter,
226+
int secondParameter,
227+
String thirdParameter,
228+
String fourthParameter,
229+
);
230+
231+
// After:
232+
typedef ExampleRecordTypedef = (
233+
String firstParameter,
234+
int secondParameter,
235+
String thirdParameter,
236+
String fourthParameter,
237+
);
238+
```
239+
240+
* Eagerly split argument lists whose contents are complex enough to be easier
241+
to read spread across multiple lines even if they would otherwise fit on a
242+
single line.
243+
244+
The heuristic is that the argument list must contain at least three named
245+
arguments, some of which are nested and some of which are not.
246+
247+
```dart
248+
// Before:
249+
TabBar(tabs: [Tab(text: 'A'), Tab(text: 'B')], labelColor: Colors.white70);
250+
251+
// After:
252+
TabBar(
253+
tabs: [
254+
Tab(text: 'A'),
255+
Tab(text: 'B'),
256+
],
257+
labelColor: Colors.white70,
258+
);
259+
```
260+
93261
## 3.7.0
94262

95263
**Released on:** 2025-02-12

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ vars = {
125125
# and land the review.
126126
#
127127
# For more details, see https://github.com/dart-lang/sdk/issues/30164.
128-
"dart_style_rev": "21de99ec0ff8ace4d946a746fb427fffd6afa535", # rolled manually
128+
"dart_style_rev": "100db45075abdd66fd8788b205243e90ff0595df", # rolled manually
129129

130130
### /third_party/pkg dependencies
131131
# 'tools/rev_sdk_deps.dart' will rev pkg dependencies to their latest; put an

PRESUBMIT.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ def load_source(modname, filename):
104104

105105

106106
def _CheckDartFormat(input_api, output_api):
107+
# TODO(rnystrom): Dart format presubmit checks are temporarily disabled
108+
# while rolling the new formatter into the SDK.
109+
return []
110+
107111
local_root = input_api.change.RepositoryRoot()
108112
utils = load_source('utils', os.path.join(local_root, 'tools', 'utils.py'))
109113

pkg/compiler/test/tool/graph_isomorphizer/golden/simple/libImport.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ mixin M_100 {}
1919
class T_100 {}
2020

2121
const C_100 iC_100 = const C_100();
22-
closureC_100(foo) => (C_100 unused) => iC_100.toString() == foo.toString();
22+
closureC_100(foo) =>
23+
(C_100 unused) => iC_100.toString() == foo.toString();
2324

2425
class C_101 {
2526
const C_101();
@@ -30,7 +31,8 @@ mixin M_101 {}
3031
class T_101 {}
3132

3233
const C_101 iC_101 = const C_101();
33-
closureC_101(foo) => (C_101 unused) => iC_101.toString() == foo.toString();
34+
closureC_101(foo) =>
35+
(C_101 unused) => iC_101.toString() == foo.toString();
3436

3537
class C_111 {
3638
const C_111();
@@ -41,7 +43,8 @@ mixin M_111 {}
4143
class T_111 {}
4244

4345
const C_111 iC_111 = const C_111();
44-
closureC_111(foo) => (C_111 unused) => iC_111.toString() == foo.toString();
46+
closureC_111(foo) =>
47+
(C_111 unused) => iC_111.toString() == foo.toString();
4548

4649
class C_010 {
4750
const C_010();
@@ -52,7 +55,8 @@ mixin M_010 {}
5255
class T_010 {}
5356

5457
const C_010 iC_010 = const C_010();
55-
closureC_010(foo) => (C_010 unused) => iC_010.toString() == foo.toString();
58+
closureC_010(foo) =>
59+
(C_010 unused) => iC_010.toString() == foo.toString();
5660

5761
class C_011 {
5862
const C_011();
@@ -63,7 +67,8 @@ mixin M_011 {}
6367
class T_011 {}
6468

6569
const C_011 iC_011 = const C_011();
66-
closureC_011(foo) => (C_011 unused) => iC_011.toString() == foo.toString();
70+
closureC_011(foo) =>
71+
(C_011 unused) => iC_011.toString() == foo.toString();
6772

6873
class C_001 {
6974
const C_001();
@@ -74,7 +79,8 @@ mixin M_001 {}
7479
class T_001 {}
7580

7681
const C_001 iC_001 = const C_001();
77-
closureC_001(foo) => (C_001 unused) => iC_001.toString() == foo.toString();
82+
closureC_001(foo) =>
83+
(C_001 unused) => iC_001.toString() == foo.toString();
7884

7985
class C_101_class_1 extends C_100
8086
with M_100, M_101, M_111, M_001

pkg/dartdev/lib/src/templates/server_shelf.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ import 'package:shelf/shelf_io.dart';
117117
import 'package:shelf_router/shelf_router.dart';
118118
119119
// Configure routes.
120-
final _router =
121-
Router()
122-
..get('/', _rootHandler)
123-
..get('/echo/<message>', _echoHandler);
120+
final _router = Router()
121+
..get('/', _rootHandler)
122+
..get('/echo/<message>', _echoHandler);
124123
125124
Response _rootHandler(Request req) {
126125
return Response.ok('Hello, World!\n');

0 commit comments

Comments
 (0)