1 | # block-opening-brace-newline-before
|
2 |
|
3 | Require a newline or disallow whitespace before the opening brace of blocks.
|
4 |
|
5 |
|
6 | ```css
|
7 | a
|
8 | { color: pink; }
|
9 | /** ↑
|
10 | * The newline before this brace */
|
11 | ```
|
12 |
|
13 | Refer to [combining rules](../../../docs/user-guide/rules/combine.md) for more information on using this rule with [`block-opening-brace-newline-after`](../block-opening-brace-newline-after/README.md) to disallow single-line rules.
|
14 |
|
15 | The [`fix` option](../../../docs/user-guide/usage/options.md#fix) can automatically fix all of the problems reported by this rule.
|
16 |
|
17 | ## Options
|
18 |
|
19 | `string`: `"always"|"always-single-line"|"never-single-line"|"always-multi-line"|"never-multi-line"`
|
20 |
|
21 | ### `"always"`
|
22 |
|
23 | There _must always_ be a newline before the opening brace.
|
24 |
|
25 | The following patterns are considered violations:
|
26 |
|
27 |
|
28 | ```css
|
29 | a{ color: pink; }
|
30 | ```
|
31 |
|
32 |
|
33 | ```css
|
34 | a{ color: pink;
|
35 | }
|
36 | ```
|
37 |
|
38 | The following patterns are _not_ considered violations:
|
39 |
|
40 |
|
41 | ```css
|
42 | a
|
43 | { color: pink; }
|
44 | ```
|
45 |
|
46 |
|
47 | ```css
|
48 | a
|
49 | {
|
50 | color: pink; }
|
51 | ```
|
52 |
|
53 |
|
54 | ```css
|
55 | a /* foo */
|
56 | {
|
57 | color: pink;
|
58 | }
|
59 | ```
|
60 |
|
61 | ### `"always-single-line"`
|
62 |
|
63 | There _must always_ be a newline before the opening brace in single-line blocks.
|
64 |
|
65 | The following patterns are considered violations:
|
66 |
|
67 |
|
68 | ```css
|
69 | a{ color: pink; }
|
70 | ```
|
71 |
|
72 | The following patterns are _not_ considered violations:
|
73 |
|
74 |
|
75 | ```css
|
76 | a
|
77 | { color: pink; }
|
78 | ```
|
79 |
|
80 |
|
81 | ```css
|
82 | a{
|
83 | color: pink; }
|
84 | ```
|
85 |
|
86 | ### `"never-single-line"`
|
87 |
|
88 | There _must never_ be whitespace before the opening brace in single-line blocks.
|
89 |
|
90 | The following patterns are considered violations:
|
91 |
|
92 |
|
93 | ```css
|
94 | a { color: pink; }
|
95 | ```
|
96 |
|
97 | The following patterns are _not_ considered violations:
|
98 |
|
99 |
|
100 | ```css
|
101 | a{ color: pink; }
|
102 | ```
|
103 |
|
104 |
|
105 | ```css
|
106 | a {
|
107 | color: pink; }
|
108 | ```
|
109 |
|
110 | ### `"always-multi-line"`
|
111 |
|
112 | There _must always_ be a newline before the opening brace in multi-line blocks.
|
113 |
|
114 | The following patterns are considered violations:
|
115 |
|
116 |
|
117 | ```css
|
118 | a{
|
119 | color: pink; }
|
120 | ```
|
121 |
|
122 |
|
123 | ```css
|
124 | a {
|
125 | color: pink; }
|
126 | ```
|
127 |
|
128 | The following patterns are _not_ considered violations:
|
129 |
|
130 |
|
131 | ```css
|
132 | a{ color: pink; }
|
133 | ```
|
134 |
|
135 |
|
136 | ```css
|
137 | a { color: pink; }
|
138 | ```
|
139 |
|
140 |
|
141 | ```css
|
142 | a
|
143 | { color: pink; }
|
144 | ```
|
145 |
|
146 |
|
147 | ```css
|
148 | a
|
149 | {
|
150 | color: pink; }
|
151 | ```
|
152 |
|
153 | ### `"never-multi-line"`
|
154 |
|
155 | There _must never_ be whitespace before the opening brace in multi-line blocks.
|
156 |
|
157 | The following patterns are considered violations:
|
158 |
|
159 |
|
160 | ```css
|
161 | a {
|
162 | color: pink; }
|
163 | ```
|
164 |
|
165 | The following patterns are _not_ considered violations:
|
166 |
|
167 |
|
168 | ```css
|
169 | a { color: pink; }
|
170 | ```
|
171 |
|
172 |
|
173 | ```css
|
174 | a{
|
175 | color: pink;}
|
176 | ```
|