Function expression doubles the indentation level #50

Closed
presidento opened this Issue Jun 14, 2011 · 6 comments

Comments

Projects
None yet
4 participants
var myFunc = function () {
    return 42;
};
a = 13;

is beautified to

var myFunc = function () {
        return 42;
    };
a = 13;
Contributor

einars commented Jun 15, 2011

Yes, that's a known problem, but most likely will not get fixed: from what I see, the most frequent form of var x = function is in a multi-var statement, e.g

var a = 1,
    b = 2,
    c = function () {
        foo();
    },
    d = function () {
        ....
    }

and, as the parser is too simple and unable to determine whether var defines only a single function or something more, it always indents the function as if there would be many of them.

Maybe add an option for it? I think it happens pretty seldom that people use multiple function expressions in the same var block...

Morriz commented Jan 15, 2012

Your assumption that functions will be declared under one var declaration does not fit with the multitude of code I have seen over the last 15 years. Is it really hard to detect a single line or multi line function declaration? I would think not. When the closing bracket is not followed by a comma, it should not be indented.

Morriz commented Jan 15, 2012

Also, may I ask why your code is not formatted with your own tool? :p

Contributor

einars commented Jan 16, 2012

I see var-lined functions all the time all over the place, e.g http://code.jquery.com/jquery-latest.js, so I strongly prefer this approach.
Of course, the original formatting wish of fmate14 makes a lot of sense, and I'd have absolutely no objections to format single functions this way: crappy thing is that I don't see how to implement that given current parser constraints.

My code itself is not formatted with our tool because I find that irrelevant.

Contributor

einars commented Feb 6, 2013

Fixed somewhen along the way, closing

@einars einars closed this Feb 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment