royriojas / esformatter-jsx

esformatter plugin: format jsx files (or js files with Facebook React JSX Syntax)
MIT License
142 stars 25 forks source link

Template or backtick strings keep being indented #72

Closed ckknight closed 8 years ago

ckknight commented 8 years ago

This is likely related to #53, but occurs regardless if formatJSXExpressions is true or false

Using esformatter 0.9.3 and esformatter-jsx 5.0.4

.esformatter:

{
    "preset": "default",
    "plugins": [
        "esformatter-jsx"
    ]
}

Initial input:

function render(count) {
    return (
        <FormattedMessage
            id="some.id"
            defaultMessage={`You have {count, plural,
                =0 {no Items}
                one {one Item}
                other {{count} Items}
            }`}
            description="Description goes here"
            values={{ count }}
        />
    );
}

First output:

function render(count) {
  return (
    <FormattedMessage id="some.id" defaultMessage={ `You have {count, plural,
                                                                =0 {no Items}
                                                                one {one Item}
                                                                other {{count} Items}
                                                            }` } description="Description goes here" values={ { count } } />
    );
}

Second output:

function render(count) {
  return (
    <FormattedMessage id="some.id" defaultMessage={ `You have {count, plural,
                                                                                                                =0 {no Items}
                                                                                                                one {one Item}
                                                                                                                other {{count} Items}
                                                                                                            }` } description="Description goes here" values={ { count } } />
    );
}

Third output:

function render(count) {
  return (
    <FormattedMessage id="some.id" defaultMessage={ `You have {count, plural,
                                                                                                                                                                =0 {no Items}
                                                                                                                                                                one {one Item}
                                                                                                                                                                other {{count} Items}
                                                                                                                                                            }` } description="Description goes here" values={ { count } } />
    );
}

Also see #70 for a PR to verify reformatting

royriojas commented 8 years ago

definitively an ugly bug. :(

Will try to take a look at it now

royriojas commented 8 years ago

I just published a new version with this fixed. Let me know if there is any instance where it fails...

demo

ckknight commented 8 years ago

@royriojas Your demo duplicates the backtick string in the inner backtick string.

Also, the indentation bug is present if you do something akin to

<Comp prop={fn`
  hello
`}/>
royriojas commented 8 years ago

@ckknight I have to update the demo to use the latest. That shouldn't be happening with the latest.

For the other one I will investigate. Would you matter to create a new issue for the tags in backtips? please.