| OLD | NEW |
| (Empty) |
| 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 /// The indentation for subsequent variables when a for loop defines multiple | |
| 22 /// variables that wrap, like: | |
| 23 /// | |
| 24 /// for (var a = initializer, | |
| 25 /// b = another, | |
| 26 /// c = third; | |
| 27 /// a + b + c < 100; | |
| 28 /// a++) { | |
| 29 /// ... | |
| 30 /// } | |
| 31 static const loopVariable = 8; | |
| 32 } | |
| 33 | |
| 34 /// The kind of pending whitespace that has been "written", but not actually | |
| 35 /// physically output yet. | |
| 36 /// | |
| 37 /// We defer actually writing whitespace until a non-whitespace token is | |
| 38 /// encountered to avoid trailing whitespace. | |
| 39 class Whitespace { | |
| 40 /// No whitespace. | |
| 41 static const none = const Whitespace._("none"); | |
| 42 | |
| 43 /// A single non-breaking space. | |
| 44 static const space = const Whitespace._("space"); | |
| 45 | |
| 46 /// A single newline. | |
| 47 static const newline = const Whitespace._("newline"); | |
| 48 | |
| 49 /// A single newline that takes into account the current expression nesting | |
| 50 /// for the next line. | |
| 51 static const nestedNewline = const Whitespace._("nestedNewline"); | |
| 52 | |
| 53 /// A single newline with all indentation eliminated at the beginning of the | |
| 54 /// next line. | |
| 55 /// | |
| 56 /// Used for subsequent lines in a multiline string. | |
| 57 static const newlineFlushLeft = const Whitespace._("newlineFlushLeft"); | |
| 58 | |
| 59 /// Two newlines, a single blank line of separation. | |
| 60 static const twoNewlines = const Whitespace._("twoNewlines"); | |
| 61 | |
| 62 /// A space or newline should be output based on whether the current token is | |
| 63 /// on the same line as the previous one or not. | |
| 64 /// | |
| 65 /// In general, we like to avoid using this because it makes the formatter | |
| 66 /// less prescriptive over the user's whitespace. | |
| 67 static const spaceOrNewline = const Whitespace._("spaceOrNewline"); | |
| 68 | |
| 69 /// A split or newline should be output based on whether the current token is | |
| 70 /// on the same line as the previous one or not. | |
| 71 /// | |
| 72 /// In general, we like to avoid using this because it makes the formatter | |
| 73 /// less prescriptive over the user's whitespace. | |
| 74 static const splitOrNewline = const Whitespace._("splitOrNewline"); | |
| 75 | |
| 76 /// One or two newlines should be output based on how many newlines are | |
| 77 /// present between the next token and the previous one. | |
| 78 /// | |
| 79 /// In general, we like to avoid using this because it makes the formatter | |
| 80 /// less prescriptive over the user's whitespace. | |
| 81 static const oneOrTwoNewlines = const Whitespace._("oneOrTwoNewlines"); | |
| 82 | |
| 83 final String name; | |
| 84 | |
| 85 /// Gets the minimum number of newlines contained in this whitespace. | |
| 86 int get minimumLines { | |
| 87 switch (this) { | |
| 88 case Whitespace.newline: | |
| 89 case Whitespace.nestedNewline: | |
| 90 case Whitespace.newlineFlushLeft: | |
| 91 case Whitespace.oneOrTwoNewlines: | |
| 92 return 1; | |
| 93 | |
| 94 case Whitespace.twoNewlines: | |
| 95 return 2; | |
| 96 | |
| 97 default: | |
| 98 return 0; | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 const Whitespace._(this.name); | |
| 103 | |
| 104 String toString() => name; | |
| 105 } | |
| OLD | NEW |