# block-spacing
Enforce or disallow spaces inside of blocks after the opening and closing brackets.
This rule enforces consistent spacing inside blocks by enforcing the opening token and the next token being on the same line. It also enforces consistent spacing with a closing token and the previous token being on the same line.
# Always
# Incorrect code examples
function foo() {return true;}
if (foo) { bar = 0;}
function baz() {let i = 0;
return i;
}
# Correct code examples
function foo() { return true; }
if (foo) { bar = 0; }
# Never
# Incorrect code examples
function foo() { return true; }
if (foo) { bar = 0;}
# Correct code examples
function foo() {return true;}
if (foo) {bar = 0;}
# Config
Name | Type | Description |
---|---|---|
style | String | The style of spacing, either "always" (default) to require one or more spaces, or "never" to disallow spaces |
More incorrect examples
{foo();}
{foo();}
{ foo();}
{foo(); }
{foo();
}
if (a) {foo();}
if (a) {} else {foo();}
switch (a) {case 0: foo();}
while (a) {foo();}
do {foo();} while (a);
for (;;) {foo();}
for (var a in b) {foo();}
for (var a of b) {foo();}
try {foo();} catch (e) {foo();} finally {foo();}
function foo() {bar();}
(function() {bar();});
(() => {bar();});
if (a) {//comment
foo(); }
More correct examples
{ foo(); }
{ foo();
}
{
foo(); }
{
foo();
}
if (a) { foo(); }
if (a) {} else { foo(); }
switch (a) {}
switch (a) { case 0: foo(); }
while (a) { foo(); }
do { foo(); } while (a);
for (;;) { foo(); }
for (var a in b) { foo(); }
for (var a of b) { foo(); }
try { foo(); } catch (e) { foo(); }
function foo() { bar(); }
(function() { bar(); });
(() => { bar(); });
if (a) { /* comment */ foo(); /* comment */ }
if (a) { //comment
foo(); }
← Overview