Skip to main content

js/useBlockStatements

MISSING DOCUMENTATION

ESLint Equivalent: curly

Examples

Invalid

if (x) x;

 file.ts:1 lint/js/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Block statements are preferred in this position.

    if (x) x;
    ^^^^^^^^^

  Safe fix

    1  - if·(x)·x;
      1+ if·(x)·{
      2+ x;
      3+ }


if (x) {
	x;
} else y;

 file.ts:1 lint/js/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Block statements are preferred in this position.

  > 1if (x) {
     ^^^^^^^^
  > 2  x;
  > 3} else y;
     ^^^^^^^^^

  Safe fix

    1 1  if·(x)·{
    2 2  x;
    3  - }·else·y;
      3+ }·else·{
      4+ y;
      5+ }


if (x) {
	x
} else if (y) y;

 file.ts:3:7 lint/js/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

  Block statements are preferred in this position.

    1if (x) {
    2  x
  > 3} else if (y) y;
            ^^^^^^^^^

  Safe fix

    1  - if·(y)·y;
      1+ if·(y)·{
      2+ y;
      3+ }


for (;;);

 file.ts:1 lint/js/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Block statements are preferred in this position.

    for (;;);
    ^^^^^^^^^

  Safe fix

    1  - for·(;;);
      1+ for·(;;)·{
      2+ }


for (p in obj);

 file.ts:1 lint/js/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Block statements are preferred in this position.

    for (p in obj);
    ^^^^^^^^^^^^^^^

  Safe fix

    1  - for·(p·in·obj);
      1+ for·(p·in·obj)·{
      2+ }


for (x of xs);

 file.ts:1 lint/js/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Block statements are preferred in this position.

    for (x of xs);
    ^^^^^^^^^^^^^^

  Safe fix

    1  - for·(x·of·xs);
      1+ for·(x·of·xs)·{
      2+ }


do; while (x);

 file.ts:1 lint/js/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Block statements are preferred in this position.

    do; while (x);
    ^^^^^^^^^^^^^^

  Safe fix

    1  - do;
    2  - while·(x);
      1+ do·{
      2+ }·while·(x);


while (x);

 file.ts:1 lint/js/useBlockStatements  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Block statements are preferred in this position.

    while (x);
    ^^^^^^^^^^

  Safe fix

    1  - while·(x);
      1+ while·(x)·{
      2+ }


with (x);

 file.ts:1 parse(js) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  'with' in strict mode

    with (x);
    ^^^^^^^^^