Skip to content

Commit 9fa5c65

Browse files
authored
Merge pull request #1144 from dart-lang/unnamed-libraries
Format unnamed libraries
2 parents 1510c99 + eb1a98b commit 9fa5c65

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
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
* Require `package:analyzer` `^5.1.0`.
4+
* Format unnamed libraries.
45

56
# 2.2.4
67

lib/src/dart_formatter.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@ class DartFormatter {
8888
// TODO(paulberry): consider plumbing in experiment enable flags from the
8989
// command line.
9090
var featureSet = FeatureSet.fromEnableFlags2(
91-
sdkLanguageVersion: Version(2, 17, 0),
91+
sdkLanguageVersion: Version(2, 19, 0),
9292
flags: [
93-
'enhanced-enums',
94-
'named-arguments-anywhere',
95-
'super-parameters',
93+
'unnamed-libraries',
9694
],
9795
);
9896

lib/src/source_visitor.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,8 +2021,10 @@ class SourceVisitor extends ThrowingAstVisitor {
20212021
_visitDirectiveMetadata(node);
20222022
_simpleStatement(node, () {
20232023
token(node.libraryKeyword);
2024-
space();
2025-
visit(node.name2);
2024+
if (node.name2 != null) {
2025+
space();
2026+
visit(node.name2);
2027+
}
20262028
});
20272029
}
20282030

test/comments/top_level.unit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ b.c;
185185
<<<
186186
library a. //
187187
b.c;
188+
>>> comment within unnamed library
189+
library/* c */;
190+
<<<
191+
library /* c */;
188192
>>> inline block comment between different kinds of directives
189193
library a; /* comment */ import 'b.dart';
190194
<<<

test/whitespace/directives.unit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ part of some_very_long_library_name_that_wraps;
5050
library a . b . c;
5151
<<<
5252
library a.b.c;
53+
>>> no spaces after unnamed library
54+
library ;
55+
<<<
56+
library;
5357
>>> configuration
5458
import'a'if(b . c . d)'e';
5559
<<<

0 commit comments

Comments
 (0)