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

Correctly format imports with both as and if clauses. #1550

Merged
merged 1 commit into from
Aug 29, 2024
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
Expand Up @@ -9,6 +9,7 @@
flag (#361).
* Preserve type parameters on old-style function-typed formals that also use
`this.` or `super.` (#1321).
* Correctly format imports with both `as` and `if` clauses (#1544).
* Remove temporary work around for analyzer 6.2.0 from dart_style 2.3.6.
* Require `package:analyzer` `>=6.5.0 <7.0.0`.

Expand Down
12 changes: 6 additions & 6 deletions lib/src/front_end/piece_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -812,13 +812,8 @@ mixin PieceFactory {
pieces.visit(directive.uri);
});

// Include any `if` clauses.
var clauses = <Piece>[];
for (var configuration in directive.configurations) {
clauses.add(nodePiece(configuration));
}

// Include the `as` clause.
var clauses = <Piece>[];
if (asKeyword != null) {
clauses.add(pieces.build(() {
pieces.token(deferredKeyword, spaceAfter: true);
Expand All @@ -828,6 +823,11 @@ mixin PieceFactory {
}));
}

// Include any `if` clauses.
for (var configuration in directive.configurations) {
clauses.add(nodePiece(configuration));
}

// Include the `show` and `hide` clauses.
for (var combinatorNode in directive.combinators) {
switch (combinatorNode) {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/short/source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1955,8 +1955,6 @@ class SourceVisitor extends ThrowingAstVisitor {
space();
visit(node.uri);

_visitConfigurations(node.configurations);

if (node.asKeyword != null) {
soloSplit();
token(node.deferredKeyword, after: space);
Expand All @@ -1965,6 +1963,7 @@ class SourceVisitor extends ThrowingAstVisitor {
visit(node.prefix);
}

_visitConfigurations(node.configurations);
_visitCombinators(node.combinators);
});
}
Expand Down
99 changes: 99 additions & 0 deletions test/short/regression/1500/1544.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
>>>
import 'package:archive/archive.dart' as archive
if (dart.library.io) 'package:archive/archive_io.dart';
import 'package:flutter/services.dart';
import 'package:fuzzy/web/e621/e621.dart';
import 'package:fuzzy/web/e621/models/tag_d_b.dart';
import 'package:http/http.dart' as http;
import 'package:j_util/e621.dart' as e621;
import 'package:fuzzy/log_management.dart' as lm;
import 'package:j_util/j_util_full.dart';
import 'package:flutter/foundation.dart';

// #region Logger
lm.Printer get _print => lRecord.print;
lm.FileLogger get _logger => lRecord.logger;
// ignore: unnecessary_late
late final lRecord = lm.generateLogger("TagDbImport");
// #endregion Logger
const bool DO_NOT_USE_TAG_DB = true;
final tagDb = LateFinal<TagDB>();
Future<TagDB> _core(String vf) {
_print("Tag Database Decompressed!");
return TagDB.makeFromCsvString(vf);
}
Future<TagDB> _androidCallback(http.StreamedResponse value) {
return decompressGzPlainTextStream(value).then(_core);
}
Future<TagDB> _webCallback(ByteData data) {
return http.ByteStream.fromBytes(
archive.GZipDecoder().decodeBuffer(archive.InputStream(data)))
.bytesToString()
.then(_core);
}
final LazyInitializer<TagDB> tagDbLazy = LazyInitializer(() async {
if (Platform.isWeb) {
var data = await rootBundle.load("assets/tags-2024-06-05.csv.gz");
_print("Tag Database Loaded!");
return compute(_webCallback, data);
} else {
return
E621.sendRequest(e621.Api.initDbExportRequest())
.then((value) => compute(_androidCallback, value));
// E621ApiEndpoints.dbExportTags
// .getMoreData()
// .sendRequest()
// .then((value) => compute(_androidCallback, value));
}
});
<<<
import 'package:archive/archive.dart' as archive
if (dart.library.io) 'package:archive/archive_io.dart';
import 'package:flutter/services.dart';
import 'package:fuzzy/web/e621/e621.dart';
import 'package:fuzzy/web/e621/models/tag_d_b.dart';
import 'package:http/http.dart' as http;
import 'package:j_util/e621.dart' as e621;
import 'package:fuzzy/log_management.dart' as lm;
import 'package:j_util/j_util_full.dart';
import 'package:flutter/foundation.dart';

// #region Logger
lm.Printer get _print => lRecord.print;
lm.FileLogger get _logger => lRecord.logger;
// ignore: unnecessary_late
late final lRecord = lm.generateLogger("TagDbImport");
// #endregion Logger
const bool DO_NOT_USE_TAG_DB = true;
final tagDb = LateFinal<TagDB>();
Future<TagDB> _core(String vf) {
_print("Tag Database Decompressed!");
return TagDB.makeFromCsvString(vf);
}

Future<TagDB> _androidCallback(http.StreamedResponse value) {
return decompressGzPlainTextStream(value).then(_core);
}

Future<TagDB> _webCallback(ByteData data) {
return http.ByteStream.fromBytes(
archive.GZipDecoder().decodeBuffer(archive.InputStream(data)))
.bytesToString()
.then(_core);
}

final LazyInitializer<TagDB> tagDbLazy = LazyInitializer(() async {
if (Platform.isWeb) {
var data = await rootBundle.load("assets/tags-2024-06-05.csv.gz");
_print("Tag Database Loaded!");
return compute(_webCallback, data);
} else {
return E621
.sendRequest(e621.Api.initDbExportRequest())
.then((value) => compute(_androidCallback, value));
// E621ApiEndpoints.dbExportTags
// .getMoreData()
// .sendRequest()
// .then((value) => compute(_androidCallback, value));
}
});
7 changes: 6 additions & 1 deletion test/short/whitespace/directives.unit
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ export 'a' if (b.c == 'd') 'e';
>>> part-of with uri
part of'uri.dart' ;
<<<
part of 'uri.dart';
part of 'uri.dart';
>>> Both configuration and prefix.
import 'foo.dart' as foo if (config == 'value') 'other.dart';
<<<
import 'foo.dart' as foo
if (config == 'value') 'other.dart';
99 changes: 99 additions & 0 deletions test/tall/regression/1500/1544.unit
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
>>>
import 'package:archive/archive.dart' as archive
if (dart.library.io) 'package:archive/archive_io.dart';
import 'package:flutter/services.dart';
import 'package:fuzzy/web/e621/e621.dart';
import 'package:fuzzy/web/e621/models/tag_d_b.dart';
import 'package:http/http.dart' as http;
import 'package:j_util/e621.dart' as e621;
import 'package:fuzzy/log_management.dart' as lm;
import 'package:j_util/j_util_full.dart';
import 'package:flutter/foundation.dart';

// #region Logger
lm.Printer get _print => lRecord.print;
lm.FileLogger get _logger => lRecord.logger;
// ignore: unnecessary_late
late final lRecord = lm.generateLogger("TagDbImport");
// #endregion Logger
const bool DO_NOT_USE_TAG_DB = true;
final tagDb = LateFinal<TagDB>();
Future<TagDB> _core(String vf) {
_print("Tag Database Decompressed!");
return TagDB.makeFromCsvString(vf);
}
Future<TagDB> _androidCallback(http.StreamedResponse value) {
return decompressGzPlainTextStream(value).then(_core);
}
Future<TagDB> _webCallback(ByteData data) {
return http.ByteStream.fromBytes(
archive.GZipDecoder().decodeBuffer(archive.InputStream(data)))
.bytesToString()
.then(_core);
}
final LazyInitializer<TagDB> tagDbLazy = LazyInitializer(() async {
if (Platform.isWeb) {
var data = await rootBundle.load("assets/tags-2024-06-05.csv.gz");
_print("Tag Database Loaded!");
return compute(_webCallback, data);
} else {
return
E621.sendRequest(e621.Api.initDbExportRequest())
.then((value) => compute(_androidCallback, value));
// E621ApiEndpoints.dbExportTags
// .getMoreData()
// .sendRequest()
// .then((value) => compute(_androidCallback, value));
}
});
<<<
import 'package:archive/archive.dart'
as archive
if (dart.library.io) 'package:archive/archive_io.dart';
import 'package:flutter/services.dart';
import 'package:fuzzy/web/e621/e621.dart';
import 'package:fuzzy/web/e621/models/tag_d_b.dart';
import 'package:http/http.dart' as http;
import 'package:j_util/e621.dart' as e621;
import 'package:fuzzy/log_management.dart' as lm;
import 'package:j_util/j_util_full.dart';
import 'package:flutter/foundation.dart';

// #region Logger
lm.Printer get _print => lRecord.print;
lm.FileLogger get _logger => lRecord.logger;
// ignore: unnecessary_late
late final lRecord = lm.generateLogger("TagDbImport");
// #endregion Logger
const bool DO_NOT_USE_TAG_DB = true;
final tagDb = LateFinal<TagDB>();
Future<TagDB> _core(String vf) {
_print("Tag Database Decompressed!");
return TagDB.makeFromCsvString(vf);
}

Future<TagDB> _androidCallback(http.StreamedResponse value) {
return decompressGzPlainTextStream(value).then(_core);
}

Future<TagDB> _webCallback(ByteData data) {
return http.ByteStream.fromBytes(
archive.GZipDecoder().decodeBuffer(archive.InputStream(data)),
).bytesToString().then(_core);
}

final LazyInitializer<TagDB> tagDbLazy = LazyInitializer(() async {
if (Platform.isWeb) {
var data = await rootBundle.load("assets/tags-2024-06-05.csv.gz");
_print("Tag Database Loaded!");
return compute(_webCallback, data);
} else {
return E621
.sendRequest(e621.Api.initDbExportRequest())
.then((value) => compute(_androidCallback, value));
// E621ApiEndpoints.dbExportTags
// .getMoreData()
// .sendRequest()
// .then((value) => compute(_androidCallback, value));
}
});
8 changes: 7 additions & 1 deletion test/tall/top_level/import.unit
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ import 'some/uri.dart' if (config.name.debug == 'string') 'c';
<<<
import 'some/uri.dart'
if (config.name.debug ==
'string') 'c';
'string') 'c';
>>> Both configuration and prefix.
import 'foo.dart' as foo if (config == 'value') 'other.dart';
<<<
import 'foo.dart'
as foo
if (config == 'value') 'other.dart';