nrwl / precise-commits

:sparkles: Painlessly apply Prettier by only formatting lines you have modified anyway!
MIT License
471 stars 20 forks source link

Unexpected Formatting Result #12

Open ReDrUm opened 6 years ago

ReDrUm commented 6 years ago

Hi,

When using precise-commits i'm unexpectedly getting different output compared to running prettier directly myself. Specifically it's stripping brackets from return statements within my react render functions and doing weird things with alignment/indentation.

"husky": "^0.14.3",
"precise-commits": "^1.0.2",
"prettier": "^1.11.0",

Is precise-commits using it's own Prettier config instead of finding the .prettierrc file in my project root? Based on the below quote from your docs I had assumed it would be consistent.

"it will automatically pick up on any of the standard Prettier configuration files you may have in your project"

Something like this:

render() {
    return (
          <div><p>foo</p></div>
    );
}

Becomes this via precise-commits:

render() {
    return <div>
            <p>foo</p>
        </div>;
}

Compared to this expectation which I get when running prettier directly:

render() {
    return (
        <div>
            <p>foo</p>
        </div>
    );
}

Any ideas how to re-align the formatting so that precise-commits outputs the same result as prettier is?

Sheile commented 6 years ago

I have same problem and it is caused by prettier with range options, IMO. If you use raw prettier with --range-start and --range-end options, you will get same result in your question.

https://github.com/prettier/prettier/issues/3789

JamesHenry commented 6 years ago

@ReDrUm In order to reproduce and diagnose, it is important to know what characters were actually changed before precise-commits ran on it.

In your example above, which bits changed?

ReDrUm commented 6 years ago

Hi @JamesHenry, Sure, thanks.

I think @Sheile is correct and it's related or caused by bleeding outside of the range options which is mentioned via #13

For the purpose of this example let's assume i changed and staged a single line: <div><p>foo</p></div>

Regardless of bleeding the formatting inconsistency is my concern in this issue.

aberezkin commented 6 years ago

Looks like this is #15 duplicate

znarf commented 5 years ago

I ran into the issue and did a bit of investigation. Seems like the problem is in Prettier itself.

When running Prettier (CLI) directly with the same --range-start and --range-end parameters, I get the same (wrong) result that precise-commits is producing.