FooBarrington,

Cool stuff, I was looking for something like this!

Only thing I’m missing is an option to prefer local imports over alias imports - I like to use alias imports for different modules, but local imports for stuff in the same module (but only downward, never parents). Would such a feature be interesting to you?

vitonsky,

Could you elaborate your idea.

If i correct understood you, you want to use relative imports inside alias directory. This is possible, you may check test about it github.com/vitonsky/…/alias.test.ts#L36-L40

Is it that you need?

FooBarrington,

It is, but I’d specifically like a rule that enforces this style of import over aliased imports. I.e. when importing a package, the order of importance is:

  1. Relative import (if on same or lower level)
  2. Aliased import (if in ancestor directory or different module)
vitonsky,

Current plugin is just about force use aliases instead of relative paths (and back for deprecated aliases).

If you need to sort imports, you may try rule simple-import-sort/imports from github.com/…/eslint-plugin-simple-import-sortIt is very flexible, so you may customize your own groups. For instance, you may group aliases in one group and relative imports to another group. Check their docs

FooBarrington, (edited )

Sorry, maybe I’m not being clear - I’m not talking about sorting. I’m talking about an ESLint rule that flags alias imports that can be expressed as relative subdirectory imports, but flags other imports that could have been alias imports. Does that make sense?

Examples:


<span style="color:#323232;">// we're in @/lib/foo
</span><span style="color:#323232;">
</span><span style="color:#323232;">// correct
</span><span style="color:#323232;">import A from "./foobar/a"
</span><span style="color:#323232;">import B from "./b"
</span><span style="color:#323232;">import C from "@/lib/c"
</span><span style="color:#323232;">import D from "@/d"
</span><span style="color:#323232;">
</span><span style="color:#323232;">// incorrect
</span><span style="color:#323232;">import A from "@/lib/foo/foobar/a"
</span><span style="color:#323232;">import B from "@/lib/foo/b"
</span>
  • All
  • Subscribed
  • Moderated
  • Favorites
  • cool_github_projects@programming.dev
  • DreamBathrooms
  • ngwrru68w68
  • cubers
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • mdbf
  • tacticalgear
  • JUstTest
  • osvaldo12
  • normalnudes
  • tester
  • cisconetworking
  • everett
  • GTA5RPClips
  • ethstaker
  • anitta
  • Leos
  • provamag3
  • modclub
  • megavids
  • lostlight
  • All magazines