prettier-plugin-sort-imports icon indicating copy to clipboard operation
prettier-plugin-sort-imports copied to clipboard

Plugin causes // prettier-ignore lines to be disregarded (formatting the code)

Open fbartho opened this issue 2 years ago • 0 comments

  // prettier-ignore
  import {b, a} from 'a'
  // prettier-ignore
  import {c, d} from 'b'
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  // prettier-ignore
x  import { b, a } from 'a';
  // prettier-ignore
x  import { c, d } from 'b';

Notice how the { } have spaces inside them?

I think the bug is related to getCodeFromAst and how it should avoid touching these imports, but simultaneously this node is important to restore comments at the top of file. So we have to omit it from nodesToDelete, but somehow also make sure that other imports don't get sorted above it.

If we just avoid "deleting" the original node, it will fall to the bottom of imports with the rest of the "unparsed runtime code".

fbartho avatar May 18 '23 01:05 fbartho