UNPKG

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