Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Formatting Result #12

Open
ReDrUm opened this issue Mar 6, 2018 · 5 comments
Open

Unexpected Formatting Result #12

ReDrUm opened this issue Mar 6, 2018 · 5 comments

Comments

@ReDrUm
Copy link

ReDrUm commented Mar 6, 2018

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?

@ReDrUm ReDrUm changed the title Prettier Config Unexpected Formatting Result Mar 6, 2018
@Sheile
Copy link

Sheile commented Mar 8, 2018

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.

prettier/prettier#3789

@JamesHenry
Copy link
Contributor

@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
Copy link
Author

ReDrUm commented Mar 28, 2018

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
Copy link

Looks like this is #15 duplicate

@znarf
Copy link

znarf commented Sep 11, 2018

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.

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

No branches or pull requests

5 participants