better-align icon indicating copy to clipboard operation
better-align copied to clipboard

it breaks "===" in javascript string block

Open kingSapa opened this issue 7 years ago • 6 comments

  • I'm sorry that I find it breaks "===" in javascript string block better align 2x

kingSapa avatar Dec 24 '17 11:12 kingSapa

php

y451309839 avatar Jan 18 '18 10:01 y451309839

hope fix soon

tananhcs avatar Jun 08 '18 02:06 tananhcs

I'm not sure if this is the proper solution, but I think it might work to solve the issues described above. I'm not entirely sure how to write atom extensions or even test this change below, but perhaps @WarWithinMe might be able to use this as a solution and we can get this fixed 😄

Basically we're adding a new else if statement after https://github.com/WarWithinMe/better-align/blob/master/src/formatter.ts#L201 to check for the cases above.

      let char = text.charAt(pos);
      let next = text.charAt(pos+1);
      let prev = pos > 0 ? text.charAt(pos-1) : "";

      ...
      } else if ( char == "=" && next == "=" ) {
        currTokenType = TokenType.Word;
        nextSeek = 2;
      } else if ( char == "=" && (prev == "=" || prev == "<" || prev == ">") ){
        currTokenType = TokenType.Word;
        nextSeek = 1;
      }
      ...

For the case where === is encountered, it will first trigger the first if above on when analyzing the first = in the string and then push to the nextSeek to look at the third = which then gets marked as an TokenType.Assignment a few else if statements later. But if we check check to see if the previous character is = we'll mark it as a TokenType.Word and not reach the later else if statement.

For the case of <= and >=, the last logic applies. It reaches our new if and marks it as a Word before it gets a chance to reach the assignment check.

FyerPower avatar Nov 14 '18 15:11 FyerPower

I created a pull-request to fix this #41 . Please @WarWithinMe check and accept it, thanks!

huanguolin avatar Dec 23 '18 04:12 huanguolin

Please, update your plagin for VS Сode with this fix. Thanks lot!

tony-show avatar Jan 31 '19 17:01 tony-show