millermedeiros / esformatter

ECMAScript code beautifier/formatter
MIT License
970 stars 91 forks source link

Added line brakes to 'case' blocks #432

Closed hoschi closed 8 years ago

hoschi commented 8 years ago

I try to fix no-case-declarations violations, but esformatter adds line breaks around the braces for the case block.

Input (es5 instead of es6):

var f = function (action, state) {
    switch (action.type) {
        case ADD_GROCERY: {
            var foo = 'bar'
        }
        default:
            return state
    }
}

Expected: output stays the same, because Catch* fields are configured with '-1'. Current output:

var f = function(action, state) {
    switch (action.type) {
        case ADD_GROCERY:
            {
            var foo = 'bar'
            }
        default:
            return state
    }
}

My .esformatter file (esformatter version 0.9.3):

{
    "preset":"default",
    "indent":{
        "value":"    "
    },
    "lineBreak":{
        "before":{
            "EndOfFile":1,
             "CatchOpeningBrace" : -1,
             "CatchClosingBrace" : -1
        },
        "after":{
             "CatchOpeningBrace" : -1,
             "CatchClosingBrace" : -1
        }
    }
}

How to configure esformatter to keep the braces where they are? (If this is no bug)

millermedeiros commented 8 years ago

@hoschi I added 2 new settings SwitchCaseBlockStart and SwitchCaseBlockEnd; the default behavior should match your expectation. thanks a lot for the bug report!

PS: CatchOpeningBrace is actually used to set the behavior of try { } catch(err) { }