Enforces braces for if/for/do/while statements.

JavaScript pattern

This matches the eslint rule.


Apply with the Grit CLI
grit apply curly

Code examples:

if

BEFORE
if (x > 0)
    doStuff();

will become

AFTER
if (x > 0) {
  doStuff();
}

else

BEFORE
if (x > 0)
  doStuff();
else
  console.log("e");

will become

AFTER
if (x > 0) {
  doStuff();
} else {
  console.log("e");
}

for

BEFORE
for (var i = 0; i < 10; i++)
    doStuff();

will become

AFTER
for (var i = 0; i < 10; i++) {
  doStuff();
}

while

BEFORE
while (x > 0)
    doStuff();

will become

AFTER
while (x > 0) {
  doStuff();
}

do

BEFORE
do
    doStuff();
while (x > 0);

will become

AFTER
do {
  doStuff();
} while (x > 0);