tests-always-included / pretty-js

Beautify and pretty print JavaScript and JSON
Other
21 stars 4 forks source link

Inconsistent spacing in function declarations #11

Closed jacekradko closed 9 years ago

jacekradko commented 9 years ago

There should be consistent spacing around function declarations.

function() {
    return;
}

function something() {
    return;
}

Right now named functions have different spacing from anonymous functions. Anonymous functions put a space between function and opening parenthesis. Named functions do not have a space between function name and opening parenthesis.

function () {
    return;
}

function something() {
    return;
}

Here is a failing scenario for this

{
  "input": "function(){return;} function a(){return;}",
  "output": "function() {\n    return;\n}\n\nfunction a() {\n    return;\n}"
}
fidian commented 9 years ago

I'm not sure that I'm behind the "inconsistent" word in the description, since this always follows "function" + space + name (optional) + parenthesis format, but I get what you mean. This formatting choice was picked to follow jslint's whitespace rules.

This looks like an excellent place for an additional option. Any suggestions for the property name?

jacekradko commented 9 years ago

That is fair. Inconsistent isn't the right word for it. Isn't there an option already to match jslint's formatting rules? This one could key of that option.

fidian commented 9 years ago

This should give you what you need. Please feel free to reopen or file a new issue if you're unhappy with the changes.