Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Function expression doubles the indentation level #50

Closed
presidento opened this Issue · 6 comments

4 participants

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

is beautified to

var myFunc = function () {
        return 42;
    };
a = 13;
@einars
Owner

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.

@ThiefMaster

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

@Morriz

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

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

@einars
Owner

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.

@einars
Owner

Fixed somewhen along the way, closing

@einars einars closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.