Skip to content

Commit 4a801b5

Browse files
authored
Class modifiers (#1178)
* Format the new class modifiers. * Update CHANGELOG.
1 parent d80996e commit 4a801b5

File tree

5 files changed

+105
-2
lines changed

5 files changed

+105
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 2.2.5-dev
22

33
* Format record expressions and record type annotations.
4+
* Format class modifiers `base`, `final`, `interface`, `mixin`, and `sealed`
45
* Better indentation of multiline function types inside type argument lists.
56
* Require `package:analyzer` `^5.1.0`.
67
* Format unnamed libraries.

lib/src/dart_formatter.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ class DartFormatter {
9090
var featureSet = FeatureSet.fromEnableFlags2(
9191
sdkLanguageVersion: Version(2, 19, 0),
9292
flags: [
93+
'class-modifiers',
9394
'records',
95+
'sealed-class',
9496
'unnamed-libraries',
9597
],
9698
);

lib/src/source_visitor.dart

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

597597
builder.nestExpression();
598598
modifier(node.abstractKeyword);
599+
modifier(node.baseKeyword);
600+
modifier(node.interfaceKeyword);
601+
modifier(node.finalKeyword);
602+
modifier(node.sealedKeyword);
603+
modifier(node.mixinKeyword);
599604
token(node.classKeyword);
600605
space();
601606
token(node.name);
@@ -615,6 +620,11 @@ class SourceVisitor extends ThrowingAstVisitor {
615620

616621
_simpleStatement(node, () {
617622
modifier(node.abstractKeyword);
623+
modifier(node.baseKeyword);
624+
modifier(node.interfaceKeyword);
625+
modifier(node.finalKeyword);
626+
modifier(node.sealedKeyword);
627+
modifier(node.mixinKeyword);
618628
token(node.typedefKeyword);
619629
space();
620630
token(node.name);
@@ -2142,6 +2152,10 @@ class SourceVisitor extends ThrowingAstVisitor {
21422152
visitMetadata(node.metadata);
21432153

21442154
builder.nestExpression();
2155+
modifier(node.baseKeyword);
2156+
modifier(node.interfaceKeyword);
2157+
modifier(node.finalKeyword);
2158+
modifier(node.sealedKeyword);
21452159
token(node.mixinKeyword);
21462160
space();
21472161
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)