jdavisclark / JsFormat

Javascript formatting for Sublime Text 2 & 3
1.42k stars 222 forks source link

JsFormat removes space after function keyword #160

Closed friederbluemle closed 8 years ago

friederbluemle commented 8 years ago

If I am not mistaken, the function keyword (like most (all?) other keywords) should be followed by a space. Applying the JsFormat formatter results in this:

Actual

var f = function(parameter) {}

Expected

var f = function (parameter) {}

EDIT: I just found this: http://javascript.crockford.com/code.html

If a function literal is anonymous, there should be one space between the word function and the ( (left parenthesis). If the space is omitted, then it can appear that the function's name is function, which is an incorrect reading.

friederbluemle commented 8 years ago

Okay it seems like this is a problem with js-beautify. It can be fixed by adding an option:

-a, --space-after-anon-function   Add a space before an anonymous function's parens, ie. function ()

IMO this should be the default. Closing this issue on JsFormat.

jabaa commented 8 years ago

How to add this option?

siamkreative commented 7 years ago

@friederbluemle Yeah could you please advise on how to add this to Settings - User?

friederbluemle commented 7 years ago

@SiamKreative I do not have a way to verify at moment. I briefly checked js-beautify's README - did you try

"space_after_anon_function": true,
siamkreative commented 7 years ago

Yup, does not seem to work.

4sh3 commented 6 years ago

is working for me, steps:

1) Install JSformatter in sublime text 2) Preferences -> Package settings -> JSFormatter -> User 3) Introduce this:

{
    "space_after_anon_function": true
}   

4) Create a file to beautifull (file.js) and introduce:

var ModuleTwo = (function(random) { // This will be idented like the other function

    random.extension = function () { // <--- 
        // another method!
    };

    return random;

})(random);

4) Control + ALT + F 5) Enjoy 👯