import-sort
import-sort copied to clipboard
`import-sort-style-module` treats absolute first-party imports as third-party
Tilda is a common alias for project root. For example, Parcel uses it by default.
import { Main } from "~/components/Main"
According to validate-npm-package-name:
package name should not contain any of the following characters:
~)('!*
So it's safe to do such change
Hi @linvain
I am happy to accept a PR for this. Extending may also be more reasonable here, because I am not sure if people like to treat those exports as relative or absolute. Something like isRootModule
or even isTildeModule
.
@renke @linvain I think a PR enabling only tilde (~
) imports is too narrow. Some projects do root-relative imports by setting an alias for the root.
For example, you can configure both Webpack and TypeScript to allow absolute path imports:
import Foo from '/root/path/to/foo';
We can let user define function isAbsolute(path)
or regex absolutePathRegex
We can use jsconfig.json
syntax:
"paths": {
"~/*" : ["./src/*"]
}
Or even implement something like eslint-import-resolver-webpack
+1 on this, would be very useful to parse jsconfig.json
for import path aliasing. It's the one thing stopping me from using this on a few projects as they are quite large and use aliasing to avoid ../../../
etc.
One thing to note about a lot of aliasing setups is there is no prefix character, like /
or ~
for example, some people just use import x from "components/y/z"
so parsing jsconfig for a set of prefixes would be best.
Hi @linvain any plans to do this? I also use ~
syntax like ~components/
~consts/
for root and my local files goes to the top of the file - above third party libs. For me it could be easy - simple field inside package.json
with paths. But jsconfig
probably would be the most universal.
I agree with all of this. In general it would be really good if it dealt with aliases (js and ts).
For the moment I have found this issue: https://github.com/renke/import-sort/issues/26
And a style that allows you to do it manually: https://github.com/fsmaia/import-sort-style-module-alias
@kekel87 Thanks, it works :)