@@ -306,22 +306,31 @@ module.exports = {
306
306
}
307
307
308
308
/**
309
- * Checks a node to see if it's in a one-liner block statement.
309
+ * Checks a node to see if it's the last item in a one-liner block.
310
+ * Block is any `BlockStatement` or `StaticBlock` node. Block is a one-liner if its
311
+ * braces (and consequently everything between them) are on the same line.
310
312
* @param {ASTNode } node The node to check.
311
- * @returns {boolean } whether the node is in a one-liner block statement .
313
+ * @returns {boolean } whether the node is the last item in a one-liner block.
312
314
*/
313
- function isOneLinerBlock ( node ) {
315
+ function isLastInOneLinerBlock ( node ) {
314
316
const parent = node . parent ;
315
317
const nextToken = sourceCode . getTokenAfter ( node ) ;
316
318
317
319
if ( ! nextToken || nextToken . value !== "}" ) {
318
320
return false ;
319
321
}
320
- return (
321
- ! ! parent &&
322
- parent . type === "BlockStatement" &&
323
- parent . loc . start . line === parent . loc . end . line
324
- ) ;
322
+
323
+ if ( parent . type === "BlockStatement" ) {
324
+ return parent . loc . start . line === parent . loc . end . line ;
325
+ }
326
+
327
+ if ( parent . type === "StaticBlock" ) {
328
+ const openingBrace = sourceCode . getFirstToken ( parent , { skip : 1 } ) ; // skip the `static` token
329
+
330
+ return openingBrace . loc . start . line === parent . loc . end . line ;
331
+ }
332
+
333
+ return false ;
325
334
}
326
335
327
336
/**
@@ -343,7 +352,7 @@ module.exports = {
343
352
report ( node ) ;
344
353
}
345
354
} else {
346
- const oneLinerBlock = ( exceptOneLine && isOneLinerBlock ( node ) ) ;
355
+ const oneLinerBlock = ( exceptOneLine && isLastInOneLinerBlock ( node ) ) ;
347
356
348
357
if ( isSemi && oneLinerBlock ) {
349
358
report ( node , true ) ;
0 commit comments