Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format unnamed libraries #1144

Merged
merged 2 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 2.2.5-dev

* Require `package:analyzer` `^5.1.0`.
* Format unnamed libraries.

# 2.2.4

Expand Down
6 changes: 2 additions & 4 deletions lib/src/dart_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ class DartFormatter {
// TODO(paulberry): consider plumbing in experiment enable flags from the
// command line.
var featureSet = FeatureSet.fromEnableFlags2(
sdkLanguageVersion: Version(2, 17, 0),
sdkLanguageVersion: Version(2, 19, 0),
flags: [
'enhanced-enums',
'named-arguments-anywhere',
'super-parameters',
'unnamed-libraries',
],
);

Expand Down
6 changes: 4 additions & 2 deletions lib/src/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2021,8 +2021,10 @@ class SourceVisitor extends ThrowingAstVisitor {
_visitDirectiveMetadata(node);
_simpleStatement(node, () {
token(node.libraryKeyword);
space();
visit(node.name2);
if (node.name2 != null) {
space();
visit(node.name2);
}
srawlins marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down
4 changes: 4 additions & 0 deletions test/comments/top_level.unit
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ b.c;
<<<
library a. //
b.c;
>>> comment within unnamed library
library/* c */;
<<<
library /* c */;
>>> inline block comment between different kinds of directives
library a; /* comment */ import 'b.dart';
<<<
Expand Down
4 changes: 4 additions & 0 deletions test/whitespace/directives.unit
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ part of some_very_long_library_name_that_wraps;
library a . b . c;
<<<
library a.b.c;
>>> no spaces after unnamed library
library ;
<<<
library;
>>> configuration
import'a'if(b . c . d)'e';
<<<
Expand Down