1 | | // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
2 | | // for details. All rights reserved. Use of this source code is governed by a
|
3 | | // BSD-style license that can be found in the LICENSE file.
|
4 | |
|
5 | | library dart_style.src.whitespace;
|
6 | |
|
7 | | /// Constants for the number of spaces for various kinds of indentation.
|
8 | | class Indent {
|
9 | | /// The number of spaces in a block or collection body.
|
10 | | static const block = 2;
|
11 | |
|
12 | | /// How much wrapped cascade sections indent.
|
13 | | static const cascade = 2;
|
14 | |
|
15 | | /// The number of spaces in a single level of expression nesting.
|
16 | | static const expression = 4;
|
17 | |
|
18 | | /// The ":" on a wrapped constructor initialization list.
|
19 | | static const constructorInitializer = 4;
|
20 | | }
|
21 | |
|
22 | | /// The kind of pending whitespace that has been "written", but not actually
|
23 | | /// physically output yet.
|
24 | | ///
|
25 | | /// We defer actually writing whitespace until a non-whitespace token is
|
26 | | /// encountered to avoid trailing whitespace.
|
27 | | class Whitespace {
|
28 | | /// No whitespace.
|
29 | | static const none = const Whitespace._("none");
|
30 | |
|
31 | | /// A single non-breaking space.
|
32 | | static const space = const Whitespace._("space");
|
33 | |
|
34 | | /// A single newline.
|
35 | | static const newline = const Whitespace._("newline");
|
36 | |
|
37 | | /// A single newline that takes into account the current expression nesting
|
38 | | /// for the next line.
|
39 | | static const nestedNewline = const Whitespace._("nestedNewline");
|
40 | |
|
41 | | /// A single newline with all indentation eliminated at the beginning of the
|
42 | | /// next line.
|
43 | | ///
|
44 | | /// Used for subsequent lines in a multiline string.
|
45 | | static const newlineFlushLeft = const Whitespace._("newlineFlushLeft");
|
46 | |
|
47 | | /// Two newlines, a single blank line of separation.
|
48 | | static const twoNewlines = const Whitespace._("twoNewlines");
|
49 | |
|
50 | | /// A split or newline should be output based on whether the current token is
|
51 | | /// on the same line as the previous one or not.
|
52 | | ///
|
53 | | /// In general, we like to avoid using this because it makes the formatter
|
54 | | /// less prescriptive over the user's whitespace.
|
55 | | static const splitOrNewline = const Whitespace._("splitOrNewline");
|
56 | |
|
57 | | /// A split or blank line (two newlines) should be output based on whether
|
58 | | /// the current token is on the same line as the previous one or not.
|
59 | | ///
|
60 | | /// This is used between enum cases, which will collapse if possible but
|
61 | | /// also allow a blank line to be preserved between cases.
|
62 | | ///
|
63 | | /// In general, we like to avoid using this because it makes the formatter
|
64 | | /// less prescriptive over the user's whitespace.
|
65 | | static const splitOrTwoNewlines = const Whitespace._("splitOrTwoNewlines");
|
66 | |
|
67 | | /// One or two newlines should be output based on how many newlines are
|
68 | | /// present between the next token and the previous one.
|
69 | | ///
|
70 | | /// In general, we like to avoid using this because it makes the formatter
|
71 | | /// less prescriptive over the user's whitespace.
|
72 | | static const oneOrTwoNewlines = const Whitespace._("oneOrTwoNewlines");
|
73 | |
|
74 | | final String name;
|
75 | |
|
76 | | /// Gets the minimum number of newlines contained in this whitespace.
|
77 | 2 | int get minimumLines {
|
78 | | switch (this) {
|
79 | 2 | case Whitespace.newline:
|
80 | 2 | case Whitespace.nestedNewline:
|
81 | 2 | case Whitespace.newlineFlushLeft:
|
82 | 2 | case Whitespace.oneOrTwoNewlines:
|
83 | | return 1;
|
84 | |
|
85 | 2 | case Whitespace.twoNewlines:
|
86 | | return 2;
|
87 | |
|
88 | | default:
|
89 | | return 0;
|
90 | | }
|
91 | | }
|
92 | |
|
93 | 5 | const Whitespace._(this.name);
|
94 | |
|
95 | 0 | String toString() => name;
|
96 | | }
|