IanVS / prettier-plugin-sort-imports

An opinionated but flexible prettier plugin to sort import statements
Apache License 2.0
951 stars 21 forks source link

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

Open fbartho opened 1 year ago

fbartho commented 1 year ago
  // 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".