Skip to content

Commit be551c0

Browse files
committed
Merge branch 'master' into patterns
# Conflicts: # lib/src/dart_formatter.dart # lib/src/source_visitor.dart # test/comments/patterns.stmt # test/splitting/if_case.stmt # test/splitting/patterns.stmt # test/whitespace/patterns.stmt
2 parents 5f05e58 + 4a801b5 commit be551c0

File tree

7 files changed

+120
-12
lines changed

7 files changed

+120
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Fix bug where parameter metadata wouldn't always split when it should.
88
* Don't split after `<` in collection literals.
99
* Format record expressions and record type annotations.
10+
* Format class modifiers `base`, `final`, `interface`, `mixin`, and `sealed`
1011
* Better indentation of multiline function types inside type argument lists.
1112
* Require `package:analyzer` `^5.1.0`.
1213
* Format unnamed libraries.

lib/src/cli/show.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ enum Show {
7171
/// Describes the directory whose contents are about to be processed.
7272
void directory(String path) {
7373
if (this == Show.legacy || this == Show.overwrite) {
74-
print('Formatting directory $directory:');
74+
print('Formatting directory $path:');
7575
}
7676
}
7777

lib/src/dart_formatter.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ class DartFormatter {
206206
var featureSet = FeatureSet.fromEnableFlags2(
207207
sdkLanguageVersion: Version(2, 19, 0),
208208
flags: [
209+
'class-modifiers',
209210
if (patterns) 'patterns',
210211
'records',
212+
'sealed-class',
211213
'unnamed-libraries',
212214
],
213215
);

lib/src/debug.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,31 @@ void dumpChunks(int start, List<Chunk> chunks) {
126126
var spanBars = '';
127127
for (var span in spans) {
128128
if (chunk.spans.contains(span)) {
129-
if (index == 0 || !chunks[index - 1].spans.contains(span)) {
129+
if (index == chunks.length - 1 ||
130+
!chunks[index + 1].spans.contains(span)) {
131+
// This is the last chunk with the span.
132+
spanBars += '╙';
133+
} else {
134+
spanBars += '║';
135+
}
136+
} else {
137+
// If the next chunk has this span, then show it bridging this chunk
138+
// and the next because a split between them breaks the span.
139+
if (index < chunks.length - 1 &&
140+
chunks[index + 1].spans.contains(span)) {
130141
if (span.cost == 1) {
131142
spanBars += '╓';
132143
} else {
133144
spanBars += span.cost.toString();
134145
}
135-
} else {
136-
spanBars += '║';
137-
}
138-
} else {
139-
if (index > 0 && chunks[index - 1].spans.contains(span)) {
140-
spanBars += '╙';
141-
} else {
142-
spanBars += ' ';
143146
}
144147
}
145148
}
146149
row.add(spanBars);
147150
}
148151

152+
row.add(chunk.spans.map((span) => span.id).join(' '));
153+
149154
if (chunk.text.length > 70) {
150155
row.add(chunk.text.substring(0, 70));
151156
} else {

lib/src/source_visitor.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,11 @@ class SourceVisitor extends ThrowingAstVisitor {
583583

584584
builder.nestExpression();
585585
modifier(node.abstractKeyword);
586+
modifier(node.baseKeyword);
587+
modifier(node.interfaceKeyword);
588+
modifier(node.finalKeyword);
589+
modifier(node.sealedKeyword);
590+
modifier(node.mixinKeyword);
586591
token(node.classKeyword);
587592
space();
588593
token(node.name);
@@ -602,6 +607,11 @@ class SourceVisitor extends ThrowingAstVisitor {
602607

603608
_simpleStatement(node, () {
604609
modifier(node.abstractKeyword);
610+
modifier(node.baseKeyword);
611+
modifier(node.interfaceKeyword);
612+
modifier(node.finalKeyword);
613+
modifier(node.sealedKeyword);
614+
modifier(node.mixinKeyword);
605615
token(node.typedefKeyword);
606616
space();
607617
token(node.name);
@@ -2203,6 +2213,10 @@ class SourceVisitor extends ThrowingAstVisitor {
22032213
visitMetadata(node.metadata);
22042214

22052215
builder.nestExpression();
2216+
modifier(node.baseKeyword);
2217+
modifier(node.interfaceKeyword);
2218+
modifier(node.finalKeyword);
2219+
modifier(node.sealedKeyword);
22062220
token(node.mixinKeyword);
22072221
space();
22082222
token(node.name);

test/whitespace/classes.unit

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,78 @@ class Foo {
169169
<<<
170170
class Foo {
171171
bar() {}
172-
}
172+
}
173+
>>> class modifiers
174+
class C1 {}
175+
base class C2 {}
176+
interface class C3 {}
177+
final class C4 {}
178+
sealed class C5 {}
179+
abstract class C6 {}
180+
abstract base class C7 {}
181+
abstract interface class C8 {}
182+
abstract final class C9 {}
183+
mixin class C10 {}
184+
base mixin class C11 {}
185+
abstract mixin class C12 {}
186+
abstract base mixin class C13 {}
187+
<<<
188+
class C1 {}
189+
190+
base class C2 {}
191+
192+
interface class C3 {}
193+
194+
final class C4 {}
195+
196+
sealed class C5 {}
197+
198+
abstract class C6 {}
199+
200+
abstract base class C7 {}
201+
202+
abstract interface class C8 {}
203+
204+
abstract final class C9 {}
205+
206+
mixin class C10 {}
207+
208+
base mixin class C11 {}
209+
210+
abstract mixin class C12 {}
211+
212+
abstract base mixin class C13 {}
213+
>>> mixin application modifiers
214+
class C1 = Object with Mixin;
215+
base class C2 = Object with Mixin;
216+
interface class C3 = Object with Mixin;
217+
final class C4 = Object with Mixin;
218+
sealed class C5 = Object with Mixin;
219+
abstract class C6 = Object with Mixin;
220+
abstract base class C7 = Object with Mixin;
221+
abstract interface class C8 = Object with Mixin;
222+
abstract final class C9 = Object with Mixin;
223+
mixin class C10 = Object with Mixin;
224+
base mixin class C11 = Object with Mixin;
225+
abstract mixin class C12 = Object with Mixin;
226+
abstract base mixin class C13 = Object with Mixin;
227+
<<<
228+
class C1 = Object with Mixin;
229+
base class C2 = Object with Mixin;
230+
interface class C3 = Object with Mixin;
231+
final class C4 = Object with Mixin;
232+
sealed class C5 = Object with Mixin;
233+
abstract class C6 = Object with Mixin;
234+
abstract base class C7 = Object
235+
with Mixin;
236+
abstract interface class C8 = Object
237+
with Mixin;
238+
abstract final class C9 = Object
239+
with Mixin;
240+
mixin class C10 = Object with Mixin;
241+
base mixin class C11 = Object
242+
with Mixin;
243+
abstract mixin class C12 = Object
244+
with Mixin;
245+
abstract base mixin class C13 = Object
246+
with Mixin;

test/whitespace/mixins.unit

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,16 @@ mixin M1 on UnaryNum {
2424
>>> generic
2525
mixin M< A ,B >on C implements D{ }
2626
<<<
27-
mixin M<A, B> on C implements D {}
27+
mixin M<A, B> on C implements D {}
28+
>>> mixin modifiers
29+
mixin M1 {}
30+
base mixin M2 {}
31+
interface mixin M3 {}
32+
final mixin M4 {}
33+
sealed mixin M5 {}
34+
<<<
35+
mixin M1 {}
36+
base mixin M2 {}
37+
interface mixin M3 {}
38+
final mixin M4 {}
39+
sealed mixin M5 {}

0 commit comments

Comments
 (0)