Open nunocasteleira opened 2 years ago
I too would expect relative-paths to have a consistent ordering.
I think there's a secondary ask above where @nunocasteleira may also want control over how the relative-path specifiers compare to each other (./Foo
should it be above or below ../Bar
?).
@fbartho is absolutely right. I would like ./Foo
to come before ../Bar
, and then come ../../Bar
and ../../Foo
.
I guess we could do "^[.]\\/", "^\.\.\\/",
instead of (or before) "^[./]"
?
Thanks for your comment, @tanmayairbase, but it doesn't do what I'm looking for.
"^\.\.\\/"
this escaped string throws an error and that approach relies on specifying every relative path ad infinity.
You can separate imports that starts with ./
and ../
into two separate groups:
"importOrder": ["^react$", "^react", "<THIRD_PARTY_MODULES>", "^@.*", "^./(.*)", "^../(.*)"]
@nunocasteleira did you find a solution that works?
@nunocasteleira did you find a solution that works?
no, I didn't :/
So we ended up using somewhat of a workaround with:
"importOrder": ["^react$", "^react", "<THIRD_PARTY_MODULES>", "^@.*$", "^./(.*)", "^[./]"],
It will have ./
imports before ../
but still have nested ../../
imports backward. So something like the following:
./Bar
./Foo
../../../Bar
../../../Foo
../../Bar
../../Foo
../Bar
../Foo
Not ideal but we decided to roll with it for now.
Still no mitigations yet?
Discussed in https://github.com/trivago/prettier-plugin-sort-imports/discussions/126