nrwl / precise-commits

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

Code corrupted by format a white-spaces only changes #21

Open medved-nsk opened 6 years ago

medved-nsk commented 6 years ago

Hi. I faced a code corruption on white-space changes. Cannot say for sure it's caused by precise-commits (the setup include a prettier precise-commits and husky as suggested). Though applying prettier directly on the whole file does work properly.

I made a simple project with example. Basically it reproduced by with the following:

  1. Original snippet
    function func01(arg1: number) {
    if ( arg1  >  32)  {
    console.log("test3");
     }
    //return (arg1-32);
    }
  2. Then apply patch
    function func01(arg1: number) {
    -if ( arg1  >  32)  {
    -   console.log("test3");
    -     }
    +if ( arg1 >  32)  {
    +    console.log("test3");
    +      }
     //return (arg1-32);
    -  }
    +    }
  3. Which then make the snippet
    function func01(arg1: number) {
    if ( arg1 >  32)  {
    console.log("test3");
      }
    //return (arg1-32);
    }
  4. Commit
    git add test01.ts
    git commit -m "test01 format"
  5. The result
    cat test01.ts
    function func01(arg1: number) {
                                if (rg1 > 3) {
    c                              onsole.log("test3");
                           }
    //re                            turn (arg1-32);
                              }

Please advise if I missed something in my setup? What else could be checked on my side? Thanks.