Skip to content

Commit ca47dde

Browse files
committed
formatting the formatter
1 parent 3544abf commit ca47dde

File tree

16 files changed

+76
-88
lines changed

16 files changed

+76
-88
lines changed

benchmark/directory.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ void main(List<String> arguments) async {
6363
void _runFormatter(String source) {
6464
try {
6565
var formatter = DartFormatter(
66-
languageVersion:
67-
_isShort
68-
? DartFormatter.latestShortStyleLanguageVersion
69-
: DartFormatter.latestLanguageVersion,
66+
languageVersion: _isShort
67+
? DartFormatter.latestShortStyleLanguageVersion
68+
: DartFormatter.latestLanguageVersion,
7069
);
7170

7271
var result = formatter.format(source);

benchmark/run.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,9 @@ List<double> _runTrials(String verb, Benchmark benchmark, int trials) {
137137
);
138138

139139
var formatter = DartFormatter(
140-
languageVersion:
141-
_isShort
142-
? DartFormatter.latestShortStyleLanguageVersion
143-
: DartFormatter.latestLanguageVersion,
140+
languageVersion: _isShort
141+
? DartFormatter.latestShortStyleLanguageVersion
142+
: DartFormatter.latestLanguageVersion,
144143
pageWidth: benchmark.pageWidth,
145144
lineEnding: '\n',
146145
);

lib/src/back_end/code_writer.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,10 @@ final class CodeWriter {
370370
// indication into account which may vary based on the surrounding pieces
371371
// when we get here.
372372
Profile.begin('CodeWriter try to bind by page width');
373-
isUnsolved =
374-
!_solution.tryBindByPageWidth(
375-
piece,
376-
_pageWidth - _indentStack.first.spaces,
377-
);
373+
isUnsolved = !_solution.tryBindByPageWidth(
374+
piece,
375+
_pageWidth - _indentStack.first.spaces,
376+
);
378377
Profile.end('CodeWriter try to bind by page width');
379378
}
380379

lib/src/cli/format_command.dart

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,18 @@ final class FormatCommand extends Command<int> {
183183
return 0;
184184
}
185185

186-
var show =
187-
const {
188-
'all': Show.all,
189-
'changed': Show.changed,
190-
'none': Show.none,
191-
}[argResults['show']]!;
192-
193-
var output =
194-
const {
195-
'write': Output.write,
196-
'show': Output.show,
197-
'none': Output.none,
198-
'json': Output.json,
199-
}[argResults['output']]!;
186+
var show = const {
187+
'all': Show.all,
188+
'changed': Show.changed,
189+
'none': Show.none,
190+
}[argResults['show']]!;
191+
192+
var output = const {
193+
'write': Output.write,
194+
'show': Output.show,
195+
'none': Output.none,
196+
'json': Output.json,
197+
}[argResults['output']]!;
200198

201199
var summary = Summary.none;
202200
switch (argResults['summary'] as String) {

lib/src/dart_formatter.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,9 @@ final class DartFormatter {
140140
text,
141141
uri: source.uri,
142142
isCompilationUnit: false,
143-
selectionStart:
144-
source.selectionStart != null
145-
? source.selectionStart! + inputOffset
146-
: null,
143+
selectionStart: source.selectionStart != null
144+
? source.selectionStart! + inputOffset
145+
: null,
147146
selectionLength: source.selectionLength,
148147
);
149148
}
@@ -176,10 +175,9 @@ final class DartFormatter {
176175
}
177176

178177
// Throw if there are syntactic errors.
179-
var syntacticErrors =
180-
parseResult.errors.where((error) {
181-
return error.diagnosticCode.type == DiagnosticType.SYNTACTIC_ERROR;
182-
}).toList();
178+
var syntacticErrors = parseResult.errors.where((error) {
179+
return error.diagnosticCode.type == DiagnosticType.SYNTACTIC_ERROR;
180+
}).toList();
183181
if (syntacticErrors.isNotEmpty) {
184182
throw FormatterException(syntacticErrors);
185183
}

lib/src/front_end/ast_node_visitor.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,10 +1794,9 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
17941794
var isSinglePositional =
17951795
positionalFields.length == 1 && namedFields == null;
17961796

1797-
var listStyle =
1798-
isSinglePositional
1799-
? const ListStyle(commas: Commas.alwaysTrailing)
1800-
: const ListStyle(commas: Commas.trailing);
1797+
var listStyle = isSinglePositional
1798+
? const ListStyle(commas: Commas.alwaysTrailing)
1799+
: const ListStyle(commas: Commas.trailing);
18011800
var builder = DelimitedListBuilder(this, listStyle);
18021801

18031802
// If all parameters are optional, put the `{` right after `(`.
@@ -1963,10 +1962,9 @@ final class AstNodeVisitor extends ThrowingAstVisitor<void> with PieceFactory {
19631962
for (var element in node.elements) {
19641963
pieces.visit(
19651964
element,
1966-
context:
1967-
node.isMultiline
1968-
? NodeContext.multilineStringInterpolation
1969-
: NodeContext.none,
1965+
context: node.isMultiline
1966+
? NodeContext.multilineStringInterpolation
1967+
: NodeContext.none,
19701968
);
19711969
}
19721970
}

lib/src/front_end/delimited_list_builder.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ final class DelimitedListBuilder {
269269
hanging: hangingComments,
270270
separate: separateComments,
271271
leading: leadingComments,
272-
) = _splitCommaComments(comments, hasElementAfter: hasElementAfter);
272+
) = _splitCommaComments(
273+
comments,
274+
hasElementAfter: hasElementAfter,
275+
);
273276

274277
// Add any hanging inline block comments to the previous element before the
275278
// subsequent ",".
@@ -401,10 +404,8 @@ final class DelimitedListBuilder {
401404
}
402405
}
403406

404-
var (
405-
hangingComments,
406-
separateCommentsBeforeComma,
407-
) = remainingCommentsBeforeComma.splitAt(hangingCommentCount);
407+
var (hangingComments, separateCommentsBeforeComma) =
408+
remainingCommentsBeforeComma.splitAt(hangingCommentCount);
408409

409410
// Inline block comments on the same line as the next element lead at the
410411
// beginning of that line, as in:

lib/src/front_end/piece_factory.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,10 +856,9 @@ mixin PieceFactory {
856856
pieces.token(question);
857857
}
858858

859-
var returnTypeModifiers =
860-
parameter != null
861-
? [parameter.requiredKeyword, parameter.covariantKeyword]
862-
: const <Token?>[];
859+
var returnTypeModifiers = parameter != null
860+
? [parameter.requiredKeyword, parameter.covariantKeyword]
861+
: const <Token?>[];
863862

864863
// If the type is a function-typed parameter with a default value, then
865864
// grab the default value from the parent node and attach it to the

lib/src/front_end/piece_writer.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,9 @@ final class PieceWriter {
208208
var builtPieces = _pieces.removeLast();
209209
assert(builtPieces.isNotEmpty);
210210

211-
var builtPiece =
212-
builtPieces.length == 1
213-
? builtPieces.first
214-
: AdjacentPiece(builtPieces);
211+
var builtPiece = builtPieces.length == 1
212+
? builtPieces.first
213+
: AdjacentPiece(builtPieces);
215214

216215
if (leadingPieces.isEmpty) {
217216
// No metadata, so return the content piece directly.

lib/src/short/line_splitting/solve_state.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,9 @@ final class SolveState {
407407
if (chunk is BlockChunk) {
408408
if (_splits.shouldSplitAt(i)) {
409409
// Include the cost of the nested block.
410-
cost +=
411-
_splitter.writer.formatBlock(chunk, _splits.getColumn(i)).cost;
410+
cost += _splitter.writer
411+
.formatBlock(chunk, _splits.getColumn(i))
412+
.cost;
412413
} else {
413414
// Include the nested block inline, if any.
414415
length += chunk.unsplitBlockLength;

0 commit comments

Comments
 (0)