Skip to content

useBlockStatements (since v1.0.0)

Diagnostic Category: lint/style/useBlockStatements

Sources:

Requires following curly brace conventions.

JavaScript allows the omission of curly braces when a block contains only one statement. However, it is considered by many to be best practice to never omit curly braces around blocks, even when they are optional, because it can lead to bugs and reduces code clarity.

if (x) x;
style/useBlockStatements.js:1:2 lint/style/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Block statements are preferred in this position.
  
  > 1 │  if (x) x;
    ^^^^^^^^^
    2 │ 
  
   Unsafe fix: Wrap the statement with a `JsBlockStatement`
  
    1 │ ·if·(x)·{·x;·}
          ++  ++
if (x) {
x;
} else y;
style/useBlockStatements.js:3:4 lint/style/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Block statements are preferred in this position.
  
    1 │  if (x) {
    2 │    x;
  > 3 │  } else y;
      ^^^^^^^
    4 │ 
  
   Unsafe fix: Wrap the statement with a `JsBlockStatement`
  
    3 │ ·}·else·{·y;·}
          ++  ++
if (x) {
x;
} else if (y) y;
style/useBlockStatements.js:3:8 lint/style/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Block statements are preferred in this position.
  
    1 │ if (x) {
    2 │   x;
  > 3 │ } else if (y) y;
          ^^^^^^^^^
    4 │ 
  
   Unsafe fix: Wrap the statement with a `JsBlockStatement`
  
    3 │ }·else·if·(y)·{·y;·}
                ++  ++
for (;;);
style/useBlockStatements.js:1:4 lint/style/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Block statements are preferred in this position.
  
  > 1 │    for (;;);
      ^^^^^^^^^
    2 │ 
  
   Unsafe fix: Wrap the statement with a `JsBlockStatement`
  
    1  - ···for·(;;);
      1+ ···for·(;;)·{}
    2 2  
  
for (p in obj);
style/useBlockStatements.js:1:4 lint/style/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Block statements are preferred in this position.
  
  > 1 │    for (p in obj);
      ^^^^^^^^^^^^^^^
    2 │ 
  
   Unsafe fix: Wrap the statement with a `JsBlockStatement`
  
    1  - ···for·(p·in·obj);
      1+ ···for·(p·in·obj)·{}
    2 2  
  
for (x of xs);
style/useBlockStatements.js:1:3 lint/style/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Block statements are preferred in this position.
  
  > 1 │   for (x of xs);
     ^^^^^^^^^^^^^^
    2 │ 
  
   Unsafe fix: Wrap the statement with a `JsBlockStatement`
  
    1  - ··for·(x·of·xs);
      1+ ··for·(x·of·xs)·{}
    2 2  
  
do;
while (x);
style/useBlockStatements.js:1:3 lint/style/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Block statements are preferred in this position.
  
  > 1 │   do;
     ^^^
  > 2 │   while (x);
     ^^^^^^^^^^
    3 │ 
  
   Unsafe fix: Wrap the statement with a `JsBlockStatement`
  
    1  - ··do;
      1+ ··do·{}
    2 2    while (x);
    3 3  
  
while (x);
style/useBlockStatements.js:1:4 lint/style/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   Block statements are preferred in this position.
  
  > 1 │    while (x);
      ^^^^^^^^^^
    2 │ 
  
   Unsafe fix: Wrap the statement with a `JsBlockStatement`
  
    1  - ···while·(x);
      1+ ···while·(x)·{}
    2 2  
  
with (x);
style/useBlockStatements.js:1:3 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   `with` statements are not allowed in strict mode
  
  > 1 │   with (x);
     ^^^^^^^^^
    2 │