Disallows newline before opening curly brace of all block statements.
Type: Boolean
or Array
or Object
Values:
true
always disallows newline before curly brace of block statementsArray
specifies block-type keywords after which newlines are disallowed before curly brace['if', 'else', 'try', 'catch', 'finally', 'do', 'while', 'for', 'function', 'class',
'switch']
Object
:value
: true
or an ArrayallExcept
: Array of exceptions"multiLine"
: if the conditions span on multiple lines, require a new line before the curly brace"disallowNewlineBeforeBlockStatements": true
function good(){
var obj = {
val: true
};
return {
data: obj
};
}
if (cond){
foo();
}
for (var e in elements){
bar(e);
}
while (cond){
foo();
}
function bad()
{
var obj =
{
val: true
};
return {
data: obj
};
}
if (cond)
{
foo();
}
for (var e in elements)
{
bar(e);
}
while (cond)
{
foo();
}
"disallowNewlineBeforeBlockStatements": ["if", "else", "for"]
if (i > 0) {
positive = true;
}
if (i < 0) {
negative = true;
} else {
negative = false;
}
for (var i = 0, len = myList.length; i < len; ++i) {
newList.push(myList[i]);
}
// this is fine, since "function" wasn't configured
function myFunc(x)
{
return x + 1;
}
if (i < 0)
{
negative = true;
}
if (i < 0)
{
negative = true;
}
else
{
negative = false;
}
for (var i = 0, len = myList.length; i < len; ++i)
{
newList.push(myList[i]);
}
"disallowNewlineBeforeBlockStatements": ["function", "while"]
function myFunc(x) {
return x + 1;
}
var z = function(x) {
return x - 1;
}
// this is fine, since "for" wasn't configured
for (var i = 0, len = myList.length; i < len; ++i)
{
newList.push(myList[i]);
}
function myFunc(x)
{
return x + 1;
}
var z = function(x)
{
return x - 1;
}
"disallowNewlineBeforeBlockStatements": {
"value": true,
"allExcept": ["multiLine"]
}
function myFunc(x,
y)
{
return x + y;
}
function foo() {
if (bar && baz &&
bat)
{
return true;
}
}
function myFunc(x,
y) {
return x + y;
}
function foo() {
if (bar && baz &&
bat) {
return true;
}
}