Skip to content

Instantly share code, notes, and snippets.

@TheSavior
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheSavior/5bff50474be2dd622b81 to your computer and use it in GitHub Desktop.
Save TheSavior/5bff50474be2dd622b81 to your computer and use it in GitHub Desktop.
Block spacing

Require a blank line after blocks.

Valid
function () {
    for (var i = 0; i < 2; i++) {
        if (true) {
            return false;
        }

        continue;
    }

    var obj = {
        a: true,
        foo: function() {
            return 1;
        },

        bar: function() {
            return 2;
        }
    };
}

// if / else blocks and try / catch blocks are still as you'd expect
if(check) {
    return 1;
} else {
    return 2;
}

try {
    // stuff
} catch(e) {
    // stuff
}

// same with anonymous functions, even with binds
var a = (function(i) {
    return i * this.mult;
}).bind(this);

return a;
Invalid
function () {
    for (var i = 0; i < 2; i++) {
        if (true) {
            return false;
        }
        continue;
    }
    var obj = {
        a: true,
        foo: function() {
            return 1;
        },
        bar: function() {
            return 2;
        }
    };
}
if(check) {
    return 1;
} 

else {
    return 2;
}
var a = (function(i) {
    return i * this.mult;
}).bind(this);
return a;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment