Skip to content

Commit 93c7913

Browse files
authored
Change code blocks to use indentation instead of backticks. (#1351)
Not exactly the most impactful change. :) But in a previous PR, Nate suggested that old-style Markdown indentation for code blocks would be better than backticks since it's shorter and we aren't actually running the comments through a Markdown formatter anyway. This converts all of them over in on Go so the codebase is consistent.
1 parent 7ab3444 commit 93c7913

16 files changed

+219
-343
lines changed

lib/src/ast_extensions.dart

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,21 @@ extension ExpressionExtensions on Expression {
131131
/// example, in an assignment, a split in the assigned value is usually
132132
/// indented:
133133
///
134-
/// ```
135-
/// var variableName =
136-
/// longValue;
137-
/// ```
134+
/// var variableName =
135+
/// longValue;
138136
///
139137
/// But if the initializer is block-like, we don't split at the `=`:
140138
///
141-
/// ```
142-
/// var variableName = [
143-
/// element,
144-
/// ];
145-
/// ```
139+
/// var variableName = [
140+
/// element,
141+
/// ];
146142
///
147143
/// Likewise, in an argument list, block-like expressions can avoid splitting
148144
/// the surrounding argument list:
149145
///
150-
/// ```
151-
/// function([
152-
/// element,
153-
/// ]);
154-
/// ```
146+
/// function([
147+
/// element,
148+
/// ]);
155149
///
156150
/// Completely empty delimited constructs like `[]` and `foo()` don't allow
157151
/// splitting inside them, so are not considered block-like.
@@ -165,21 +159,17 @@ extension ExpressionExtensions on Expression {
165159
// TODO(tall): We should also allow multi-line strings to be formatted
166160
// like block arguments, at least in some cases like:
167161
//
168-
// ```
169-
// function('''
170-
// Lots of
171-
// text
172-
// ''');
173-
// ```
162+
// function('''
163+
// Lots of
164+
// text
165+
// ''');
174166

175167
// TODO(tall): Consider whether immediately-invoked function expressions
176168
// should be block argument candidates, like:
177169
//
178-
// ```
179-
// function(() {
180-
// body;
181-
// }());
182-
// ```
170+
// function(() {
171+
// body;
172+
// }());
183173
return switch (expression) {
184174
// A function expression can use either a non-empty parameter list or a
185175
// non-empty block body for block formatting.

lib/src/comment_type.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ enum CommentType {
2020
/// preceding the `/*`, after the `*/`, or both. An inline block comment
2121
/// may be multiple lines, as in:
2222
///
23-
/// ```
24-
/// code /* comment
25-
/// more */
26-
/// ```
23+
/// code /* comment
24+
/// more */
2725
inlineBlock,
2826
}

lib/src/front_end/ast_node_visitor.dart

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,7 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
631631
if (node.parameters case var parameters?) {
632632
// A function-typed field formal like:
633633
//
634-
// ```
635-
// C(this.fn(parameter));
636-
// ```
634+
// C(this.fn(parameter));
637635
return createFunctionType(
638636
node.type,
639637
fieldKeyword: node.thisKeyword,
@@ -721,15 +719,13 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
721719
// where each clause is a separate argument. This means that when they
722720
// split, they split like:
723721
//
724-
// ```
725-
// for (
726-
// initializerClause;
727-
// conditionClause;
728-
// incrementClause
729-
// ) {
730-
// body;
731-
// }
732-
// ```
722+
// for (
723+
// initializerClause;
724+
// conditionClause;
725+
// incrementClause
726+
// ) {
727+
// body;
728+
// }
733729
var partsList =
734730
DelimitedListBuilder(this, const ListStyle(commas: Commas.none));
735731
partsList.leftBracket(node.leftParenthesis);
@@ -779,13 +775,11 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
779775
// If a for-in loop, treat the for parts like an assignment, so they
780776
// split like:
781777
//
782-
// ```
783-
// for (var variable in [
784-
// initializer,
785-
// ]) {
786-
// body;
787-
// }
788-
// ```
778+
// for (var variable in [
779+
// initializer,
780+
// ]) {
781+
// body;
782+
// }
789783
forPartsPiece = buildPiece((b) {
790784
b.token(node.leftParenthesis);
791785
b.add(createAssignment(
@@ -1039,12 +1033,10 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
10391033
// Edge case: When the then branch is a block and there is an else clause
10401034
// after it, we want to force the block to split even if empty, like:
10411035
//
1042-
// ```
1043-
// if (condition) {
1044-
// } else {
1045-
// body;
1046-
// }
1047-
// ```
1036+
// if (condition) {
1037+
// } else {
1038+
// body;
1039+
// }
10481040
var thenStatement = switch (ifStatement.thenStatement) {
10491041
Block thenBlock when ifStatement.elseStatement != null =>
10501042
createBlock(thenBlock, forceSplit: true),
@@ -1589,9 +1581,7 @@ class AstNodeVisitor extends ThrowingAstVisitor<Piece> with PieceFactory {
15891581
if (node.parameters case var parameters?) {
15901582
// A function-typed super parameter like:
15911583
//
1592-
// ```
1593-
// C(super.fn(parameter));
1594-
// ```
1584+
// C(super.fn(parameter));
15951585
return createFunctionType(
15961586
node.type,
15971587
fieldKeyword: node.superKeyword,

lib/src/front_end/comment_writer.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,13 @@ class SourceComment {
193193
///
194194
/// For example, this code:
195195
///
196-
/// ```dart
197-
/// a /* c1 */
198-
/// /* c2 */
196+
/// a /* c1 */
197+
/// /* c2 */
199198
///
200-
/// /* c3 */
199+
/// /* c3 */
201200
///
202201
///
203-
/// b
204-
/// ```
202+
/// b
205203
///
206204
/// Produces a sequence like:
207205
///

lib/src/front_end/delimited_list_builder.dart

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ class DelimitedListBuilder {
6767
/// after [bracket]. This is used for parameter lists where all parameters
6868
/// are optional or named, as in:
6969
///
70-
/// ```
71-
/// function([parameter]);
72-
/// ```
70+
/// function([parameter]);
7371
///
7472
/// Here, [bracket] will be `(` and [delimiter] will be `[`.
7573
void leftBracket(Token bracket, {Piece? preceding, Token? delimiter}) {
@@ -90,9 +88,7 @@ class DelimitedListBuilder {
9088
/// after [bracket]. This is used for parameter lists with optional or named
9189
/// parameters, like:
9290
///
93-
/// ```
94-
/// function(mandatory, {named});
95-
/// ```
91+
/// function(mandatory, {named});
9692
///
9793
/// Here, [bracket] will be `)` and [delimiter] will be `}`.
9894
///
@@ -107,13 +103,11 @@ class DelimitedListBuilder {
107103
// bracket. If there is a delimiter, this will move comments between it and
108104
// the bracket to before the delimiter, as in:
109105
//
110-
// ```
111-
// // Before:
112-
// f([parameter] /* comment */) {}
106+
// // Before:
107+
// f([parameter] /* comment */) {}
113108
//
114-
// // After:
115-
// f([parameter /* comment */]) {}
116-
// ```
109+
// // After:
110+
// f([parameter /* comment */]) {}
117111
if (delimiter != null) {
118112
commentsBefore = _visitor.comments
119113
.takeCommentsBefore(delimiter)
@@ -188,15 +182,11 @@ class DelimitedListBuilder {
188182
// Preserve any comments before the delimiter. Treat them as occurring
189183
// before the previous element's comma. This means that:
190184
//
191-
// ```
192-
// function(p1, /* comment */ [p1]);
193-
// ```
185+
// function(p1, /* comment */ [p1]);
194186
//
195187
// Will be formatted as:
196188
//
197-
// ```
198-
// function(p1 /* comment */, [p1]);
199-
// ```
189+
// function(p1 /* comment */, [p1]);
200190
//
201191
// (In practice, it's such an unusual place for a comment that it doesn't
202192
// matter that much where it goes and this seems to be simple and
@@ -280,13 +270,11 @@ class DelimitedListBuilder {
280270
///
281271
/// For example:
282272
///
283-
/// ```
284-
/// function(
285-
/// argument /* inline */, // hanging
286-
/// // separate
287-
/// /* leading */ nextArgument
288-
/// );
289-
/// ```
273+
/// function(
274+
/// argument /* inline */, // hanging
275+
/// // separate
276+
/// /* leading */ nextArgument
277+
/// );
290278
///
291279
/// Calculating these takes into account whether there are newlines before or
292280
/// after the comments, and which side of the commas the comments appear on.
@@ -322,12 +310,10 @@ class DelimitedListBuilder {
322310
// Inline block comments before the `,` stay with the preceding element, as
323311
// in:
324312
//
325-
// ```
326-
// function(
327-
// argument /* hanging */ /* comment */,
328-
// argument,
329-
// );
330-
// ```
313+
// function(
314+
// argument /* hanging */ /* comment */,
315+
// argument,
316+
// );
331317
var inlineCommentCount = 0;
332318
if (_elements.isNotEmpty) {
333319
while (inlineCommentCount < _commentsBeforeComma.length) {
@@ -361,12 +347,10 @@ class DelimitedListBuilder {
361347
// Inline block comments on the same line as the next element lead at the
362348
// beginning of that line, as in:
363349
///
364-
// ```
365-
// function(
366-
// argument,
367-
// /* leading */ /* comment */ argument,
368-
// );
369-
// ```
350+
// function(
351+
// argument,
352+
// /* leading */ /* comment */ argument,
353+
// );
370354
var leadingCommentCount = 0;
371355
if (hasElementAfter && commentsBeforeElement.isNotEmpty) {
372356
while (leadingCommentCount < commentsBeforeElement.length) {
@@ -386,14 +370,12 @@ class DelimitedListBuilder {
386370
// Comments that are neither hanging nor leading are formatted like
387371
// separate elements, as in:
388372
//
389-
// ```
390-
// function(
391-
// argument,
392-
// /* comment */
393-
// argument,
394-
// // another
395-
// );
396-
// ```
373+
// function(
374+
// argument,
375+
// /* comment */
376+
// argument,
377+
// // another
378+
// );
397379
var separateComments =
398380
separateCommentsBeforeComma.concatenate(separateCommentsAfterComma);
399381

@@ -433,13 +415,11 @@ class DelimitedListBuilder {
433415
// be it.
434416
// TODO(tall): The old formatter allows multiple block arguments, like:
435417
//
436-
// ```
437-
// function(() {
438-
// body;
439-
// }, () {
440-
// more;
441-
// });
442-
// ```
418+
// function(() {
419+
// body;
420+
// }, () {
421+
// more;
422+
// });
443423
//
444424
// This doesn't seem very common in the Flutter repo, but does occur
445425
// sometimes. We'll probably want to experiment to see if it's worth

lib/src/front_end/piece_factory.dart

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ mixin PieceFactory {
7171
/// is used, for example, with empty blocks in `if` statements followed by
7272
/// `else` clauses:
7373
///
74-
/// ```
75-
/// if (condition) {
76-
/// } else {}
77-
/// ```
74+
/// if (condition) {
75+
/// } else {}
7876
Piece createBody(
7977
Token leftBracket, List<AstNode> contents, Token rightBracket,
8078
{bool forceSplit = false}) {
@@ -104,10 +102,8 @@ mixin PieceFactory {
104102
/// is used, for example, with empty blocks in `if` statements followed by
105103
/// `else` clauses:
106104
///
107-
/// ```
108-
/// if (condition) {
109-
/// } else {}
110-
/// ```
105+
/// if (condition) {
106+
/// } else {}
111107
Piece createBlock(Block block, {bool forceSplit = false}) {
112108
return createBody(block.leftBracket, block.statements, block.rightBracket,
113109
forceSplit: forceSplit);
@@ -133,12 +129,10 @@ mixin PieceFactory {
133129
// TODO(tall): Support a line comment inside a collection literal as a
134130
// signal to preserve internal newlines. So if you have:
135131
//
136-
// ```
137-
// var list = [
138-
// 1, 2, 3, // comment
139-
// 4, 5, 6,
140-
// ];
141-
// ```
132+
// var list = [
133+
// 1, 2, 3, // comment
134+
// 4, 5, 6,
135+
// ];
142136
//
143137
// The formatter will preserve the newline after element 3 and the lack of
144138
// them after the other elements.
@@ -380,14 +374,12 @@ mixin PieceFactory {
380374
// Edge case: When there's another catch/on/finally after this one, we
381375
// want to force the block to split even if it's empty.
382376
//
383-
// ```
384-
// try {
385-
// ..
386-
// } on Foo {
387-
// } finally Bar {
388-
// body;
389-
// }
390-
// ```
377+
// try {
378+
// ..
379+
// } on Foo {
380+
// } finally Bar {
381+
// body;
382+
// }
391383
var forceSplit = i < tryStatement.catchClauses.length - 1 ||
392384
tryStatement.finallyBlock != null;
393385
var catchClauseBody =

0 commit comments

Comments
 (0)