Skip to content

Commit 5c64747

Browse files
authored
feat: update brace-style for class static blocks (#15322)
* feat: update brace-style for class static blocks Updates the `brace-style` rule to apply to braces of class static blocks. Refs #15016 * Add note about indentation
1 parent df2f1cc commit 5c64747

File tree

3 files changed

+519
-2
lines changed

3 files changed

+519
-2
lines changed

docs/rules/brace-style.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ if (foo) {
8585
else {
8686
baz();
8787
}
88+
89+
class C
90+
{
91+
static
92+
{
93+
foo();
94+
}
95+
}
8896
```
8997

9098
Examples of **correct** code for this rule with the default `"1tbs"` option:
@@ -112,6 +120,12 @@ try {
112120
handleError();
113121
}
114122

123+
class C {
124+
static {
125+
foo();
126+
}
127+
}
128+
115129
// when there are no braces, there are no problems
116130
if (foo) bar();
117131
else if (baz) boom();
@@ -150,6 +164,12 @@ if (foo) { baz(); } else if (bar) {
150164
try { somethingRisky(); } catch(e) {
151165
handleError();
152166
}
167+
168+
class C {
169+
static { foo(); }
170+
}
171+
172+
class D { static { foo(); } }
153173
```
154174

155175
### stroustrup
@@ -177,6 +197,14 @@ try
177197
handleError();
178198
}
179199

200+
class C
201+
{
202+
static
203+
{
204+
foo();
205+
}
206+
}
207+
180208
if (foo) {
181209
bar();
182210
} else {
@@ -211,6 +239,12 @@ catch(e) {
211239
handleError();
212240
}
213241

242+
class C {
243+
static {
244+
foo();
245+
}
246+
}
247+
214248
// when there are no braces, there are no problems
215249
if (foo) bar();
216250
else if (baz) boom();
@@ -230,6 +264,12 @@ else { baz(); }
230264

231265
try { somethingRisky(); }
232266
catch(e) { handleError(); }
267+
268+
class C {
269+
static { foo(); }
270+
}
271+
272+
class D { static { foo(); } }
233273
```
234274

235275
### allman
@@ -255,6 +295,12 @@ try
255295
handleError();
256296
}
257297

298+
class C {
299+
static {
300+
foo();
301+
}
302+
}
303+
258304
if (foo) {
259305
bar();
260306
} else {
@@ -295,6 +341,14 @@ catch(e)
295341
handleError();
296342
}
297343

344+
class C
345+
{
346+
static
347+
{
348+
foo();
349+
}
350+
}
351+
298352
// when there are no braces, there are no problems
299353
if (foo) bar();
300354
else if (baz) boom();
@@ -314,6 +368,16 @@ else { baz(); }
314368

315369
try { somethingRisky(); }
316370
catch(e) { handleError(); }
371+
372+
class C
373+
{
374+
static { foo(); }
375+
376+
static
377+
{ foo(); }
378+
}
379+
380+
class D { static { foo(); } }
317381
```
318382

319383
## When Not To Use It

lib/rules/brace-style.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ module.exports = {
155155
validateCurlyPair(sourceCode.getFirstToken(node), sourceCode.getLastToken(node));
156156
}
157157
},
158+
StaticBlock(node) {
159+
validateCurlyPair(
160+
sourceCode.getFirstToken(node, { skip: 1 }), // skip the `static` token
161+
sourceCode.getLastToken(node)
162+
);
163+
},
158164
ClassBody(node) {
159165
validateCurlyPair(sourceCode.getFirstToken(node), sourceCode.getLastToken(node));
160166
},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy