nrwl / precise-commits

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

Reformatting Bleeding Outside of Staged Lines #13

Closed ReDrUm closed 6 years ago

ReDrUm commented 6 years ago

Hi,

"precise-commits will work out exactly what lines and characters within those files have actually been changed or added." "It then uses this information to run Prettier in a very focused way, allowing it to only reformat what is relevant for your current work, and allowing you to keep your PRs small and explicit!"

Currently it's bleeding reformatting outside the staged lines. It appears to bleed out into the containing block. Is this expected? Perhaps out of necessity to determine nesting indentation?

Original:

render() {
    return (
        <div>
                    <span>Foo</span>
                <span>Bar (stage only this line)</span>
            <span>Baz</span>
        </div>
    );
}

Expectation:

render() {
    return (
        <div>
                <span>Foo (this line ignored because it wasn't staged)</span>
            <span>Bar (only this line reformatted)</span>
            <span>Baz</span>
        </div>
    );
}

Output from precise-commits (bleeds out into block level reformatting):

render() {
    return <div>
            <span>Foo</span>
            <span>Bar</span>
            <span>Baz</span>
        </div>;
}

Based on #7 Is the expectation that the developer needs to choose to stage only the reformatted lines they modified themselves in the prior commit and discards the rest of the formatting changes? Or should it not be bleeding outside of staged lines?

Cheers :)

alexeagle commented 6 years ago

This is WAI - it's based on the behavior of the underlying formatter: https://prettier.io/docs/en/options.html#range which says that the entire statement containing the modified lines is formatted.

The range will extend: Backwards to the start of the first line containing the selected statement. Forwards to the end of the selected statement

ReDrUm commented 6 years ago

Ok, thanks.