ggascoigne / prettier-plugin-import-sort

Prettier plugin to pass javascript and typescript through import-sort
MIT License
110 stars 11 forks source link

Use `opts.filepath` as path to the config file #15

Closed richardaum closed 4 years ago

richardaum commented 4 years ago

It allows to use the plugin even on a monorepo, where node_modules folder couldn't be at the same level as the config file.

richardaum commented 4 years ago

Thank you for fast response. I've taken a double look here and by using process.cwd() it has a problem, when running with VSCode Prettier extension. It isn't able to properly point to the where the config file is localted.

So rather than that, I'm using the original file path, available on opts.filepath. It happens that import-sort-config knows how to solve by using it.

richardaum commented 4 years ago

It happens that import-sort-config knows how to solve by using it.

Using a recursive strategy from cosmiconfig, import-sort-config is able to recursively find the nearest config file. Since this plugin uses import-sort-config, it is also able to do it.

richardaum commented 4 years ago

https://github.com/ggascoigne/prettier-plugin-import-sort/pull/15/files#diff-1fdf421c05c1140f6d71444ea2b27638L55

This line where we add a dummy string could also be change to make use of the original file name. But since it isn't directly related to the issue probably a later PR would make more sense.

ggascoigne commented 4 years ago

OK now that the npmjs login is working again, v0.0.5 is published. Sorry it took so long.

richardaum commented 4 years ago

Thank you! =)