Skip to content

Commit ab4a1b9

Browse files
committed
Apply code review feedback.
1 parent 86ce650 commit ab4a1b9

9 files changed

+176
-154
lines changed

lib/src/config_cache.dart

+18-11
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,26 @@ final class ConfigCache {
130130
pageWidth = width;
131131
}
132132

133-
if (formatter case {'trailing_commas': String commas}) {
134-
trailingCommas = switch (commas) {
135-
'automate' => TrailingCommas.automate,
136-
'preserve' => TrailingCommas.preserve,
137-
// Silently ignore any unrecognized name.
138-
_ => null,
139-
};
133+
if (formatter case {'trailing_commas': var commas}) {
134+
switch (commas) {
135+
case 'automate':
136+
trailingCommas = TrailingCommas.automate;
137+
case 'preserve':
138+
trailingCommas = TrailingCommas.preserve;
139+
default:
140+
stderr.writeln(
141+
'Warning: "trailing_commas" option should be "automate" or '
142+
'"preserve", but was "$commas".',
143+
);
144+
}
140145
}
141146
}
142-
} on PackageResolutionException {
143-
// Silently ignore any errors coming from the processing the analyis
144-
// options. If there are any issues, we just use the default page width
145-
// and keep going.
147+
} on PackageResolutionException catch (exception) {
148+
// Report the error, but use the default settings and keep going.
149+
stderr.writeln(
150+
'Warning: Package resolution error when reading '
151+
'"analysis_options.yaml" file:\n$exception',
152+
);
146153
}
147154

148155
// Cache whichever options we found (or `null` if we didn't find them).

lib/src/front_end/piece_factory.dart

+3-5
Original file line numberDiff line numberDiff line change
@@ -1627,11 +1627,9 @@ mixin PieceFactory {
16271627

16281628
/// Whether there is a trailing comma at the end of the list delimited by
16291629
/// [rightBracket].
1630-
bool hasPreservedTrailingComma(Token rightBracket) {
1631-
if (formatter.trailingCommas != TrailingCommas.preserve) return false;
1632-
1633-
return rightBracket.hasCommaBefore;
1634-
}
1630+
bool hasPreservedTrailingComma(Token rightBracket) =>
1631+
formatter.trailingCommas == TrailingCommas.preserve &&
1632+
rightBracket.hasCommaBefore;
16351633

16361634
/// Writes a piece for a parameter-like constructor: Either a simple formal
16371635
/// parameter or a record type field, which is syntactically similar to a

test/cli/cli_test.dart

+38-32
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ void main() {
2222
]).create();
2323

2424
var process = await runFormatterOnDir();
25-
expect(
26-
await process.stdout.next,
27-
'Formatted ${p.join('code', 'a.dart')}',
28-
);
29-
expect(
30-
await process.stdout.next,
31-
'Formatted ${p.join('code', 'c.dart')}',
25+
await expectLater(
26+
process.stdout,
27+
emitsInOrder([
28+
'Formatted ${p.join('code', 'a.dart')}',
29+
'Formatted ${p.join('code', 'c.dart')}',
30+
]),
3231
);
33-
expect(
34-
await process.stdout.next,
35-
startsWith(r'Formatted 3 files (2 changed)'),
32+
await expectLater(
33+
process.stdout,
34+
emits(startsWith('Formatted 3 files (2 changed)')),
3635
);
3736
await process.shouldExit(0);
3837

@@ -52,17 +51,16 @@ void main() {
5251
p.join('code', 'subdir'),
5352
p.join('code', 'c.dart'),
5453
]);
55-
expect(
56-
await process.stdout.next,
57-
'Formatted ${p.join('code', 'subdir', 'a.dart')}',
54+
await expectLater(
55+
process.stdout,
56+
emitsInOrder([
57+
'Formatted ${p.join('code', 'subdir', 'a.dart')}',
58+
'Formatted ${p.join('code', 'c.dart')}',
59+
]),
5860
);
59-
expect(
60-
await process.stdout.next,
61-
'Formatted ${p.join('code', 'c.dart')}',
62-
);
63-
expect(
64-
await process.stdout.next,
65-
startsWith(r'Formatted 2 files (2 changed)'),
61+
await expectLater(
62+
process.stdout,
63+
emits(startsWith('Formatted 2 files (2 changed)')),
6664
);
6765
await process.shouldExit(0);
6866

@@ -91,16 +89,19 @@ void main() {
9189
var process = await runFormatter(['--version']);
9290

9391
// Match something roughly semver-like.
94-
expect(await process.stdout.next, matches(RegExp(r'\d+\.\d+\.\d+.*')));
92+
await expectLater(
93+
process.stdout,
94+
emits(matches(RegExp(r'\d+\.\d+\.\d+.*'))),
95+
);
9596
await process.shouldExit(0);
9697
});
9798

9899
group('--help', () {
99100
test('non-verbose shows description and common options', () async {
100101
var process = await runFormatter(['--help']);
101-
expect(
102-
await process.stdout.next,
103-
'Idiomatically format Dart source code.',
102+
await expectLater(
103+
process.stdout,
104+
emits('Idiomatically format Dart source code.'),
104105
);
105106
await expectLater(process.stdout, emitsThrough(contains('-o, --output')));
106107
await expectLater(process.stdout, neverEmits(contains('--summary')));
@@ -109,9 +110,9 @@ void main() {
109110

110111
test('verbose shows description and all options', () async {
111112
var process = await runFormatter(['--help', '--verbose']);
112-
expect(
113-
await process.stdout.next,
114-
'Idiomatically format Dart source code.',
113+
await expectLater(
114+
process.stdout,
115+
emits('Idiomatically format Dart source code.'),
115116
);
116117
await expectLater(process.stdout, emitsThrough(contains('-o, --output')));
117118
await expectLater(process.stdout, emitsThrough(contains('--show')));
@@ -133,10 +134,15 @@ void main() {
133134
process.stdin.writeln("a flush left multi-line string''';}");
134135
await process.stdin.close();
135136

136-
expect(await process.stdout.next, ' main() {');
137-
expect(await process.stdout.next, " '''");
138-
expect(await process.stdout.next, "a flush left multi-line string''';");
139-
expect(await process.stdout.next, ' }');
137+
await expectLater(
138+
process.stdout,
139+
emitsInOrder([
140+
' main() {',
141+
" '''",
142+
"a flush left multi-line string''';",
143+
' }',
144+
]),
145+
);
140146
await process.shouldExit(0);
141147
});
142148

@@ -205,7 +211,7 @@ void main() {
205211
'selection': {'offset': 5, 'length': 9},
206212
});
207213

208-
expect(await process.stdout.next, json);
214+
await expectLater(process.stdout, emits(json));
209215
await process.shouldExit();
210216
});
211217
});

test/cli/language_version_test.dart

+26-15
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,17 @@ main() {
176176
process.stdin.writeln('main() { switch (o) { case 1 + 2: break; } }');
177177
await process.stdin.close();
178178

179-
expect(await process.stdout.next, 'main() {');
180-
expect(await process.stdout.next, ' switch (o) {');
181-
expect(await process.stdout.next, ' case 1 + 2:');
182-
expect(await process.stdout.next, ' break;');
183-
expect(await process.stdout.next, ' }');
184-
expect(await process.stdout.next, '}');
179+
await expectLater(
180+
process.stdout,
181+
emitsInOrder([
182+
'main() {',
183+
' switch (o) {',
184+
' case 1 + 2:',
185+
' break;',
186+
' }',
187+
'}',
188+
]),
189+
);
185190
await process.shouldExit(0);
186191
});
187192

@@ -205,12 +210,17 @@ main() {
205210
process.stdin.writeln('main() { switch (o) { case 1 + 2: break; } }');
206211
await process.stdin.close();
207212

208-
expect(await process.stdout.next, 'main() {');
209-
expect(await process.stdout.next, ' switch (o) {');
210-
expect(await process.stdout.next, ' case 1 + 2:');
211-
expect(await process.stdout.next, ' break;');
212-
expect(await process.stdout.next, ' }');
213-
expect(await process.stdout.next, '}');
213+
await expectLater(
214+
process.stdout,
215+
emitsInOrder([
216+
'main() {',
217+
' switch (o) {',
218+
' case 1 + 2:',
219+
' break;',
220+
' }',
221+
'}',
222+
]),
223+
);
214224
await process.shouldExit(0);
215225
});
216226

@@ -222,9 +232,10 @@ main() {
222232
process.stdin.writeln('main() {var (a,b)=(1,2);}');
223233
await process.stdin.close();
224234

225-
expect(await process.stdout.next, 'main() {');
226-
expect(await process.stdout.next, ' var (a, b) = (1, 2);');
227-
expect(await process.stdout.next, '}');
235+
await expectLater(
236+
process.stdout,
237+
emitsInOrder(['main() {', ' var (a, b) = (1, 2);', '}']),
238+
);
228239
await process.shouldExit(0);
229240
});
230241
});

0 commit comments

Comments
 (0)