Block formatting within function call parameters. #258

Closed
vkadam opened this Issue May 8, 2013 · 3 comments

Comments

Projects
None yet
2 participants

vkadam commented May 8, 2013

In case if block formatting is used for function call arguments, like shown in following example.

function test(arg1, arg2, arg3) {
    console.log(arguments);
}
test(
/*Argument 1*/
{
    "Value1": "1"
},
/*Argument 2*/
{
    "Value2": "2"
},
/*Argument 3*/
{
    "Value3"
});

After beautify this code is formatted like

function test(arg1, arg2, arg3) {
    console.log(arguments);
}
test(
/*Argument 1*/ {
    "Value1": "1"
},
/*Argument 2*/ {
    "Value2": "2"
},
/*Argument 3*/ {
    "Value3"
});

On next beautify this is again formatted like

function test(arg1, arg2, arg3) {
    console.log(arguments);
}
test(
/*Argument 1*/
{
    "Value1": "1"
},
/*Argument 2*/
{
    "Value2": "2"
},
/*Argument 3*/
{
    "Value3"
});

And keeps happening.

Expected: Keep first formatting one with block comment on new line.

Same thing happens one http://jsbeautifier.org/

Contributor

bitwiseman commented May 9, 2013

Neat. This might be addressed by #259, but might not. I'll modify the test framework so we can this class of issues in the future.

bitwiseman added a commit to bitwiseman/js-beautify that referenced this issue May 9, 2013

Ensure beautified output is the same when rebeautified
#258 surfaced and interersting issue that was not caught by the
current test framework.  Now the framework checks that beautified
output is unchanged after being run through the beautifier again.

Adding this check immediately found a bug in the beautification of
function declarations. Fixed that as well.
Contributor

bitwiseman commented May 25, 2013

Oh, fun with comments again. I have a fix for this case, but it fails this one:

function test(arg1, arg2, arg3) {
    console.log(arguments);
}
test(
/*Argument 1
*/
{
    "Value1": "1"
},
/*Argument 2
*/
{
    "Value2": "2"
},
/*Argument 3
*/
{
    "Value3"
});

bitwiseman added a commit that referenced this issue May 26, 2013

vkadam commented May 26, 2013

Thanks a lot. I will wait till its gets published at npm.

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