eslint-plugin-paths: A plugin for ESLint, to force use paths aliases from tsconfig

3 years ago by vitonsky to c/cool_github_projects

A plugin for ESLint, to force use paths aliases from tsconfig - vitonsky/eslint-plugin-paths
FooBarrington 0 points 3 years ago

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?

path: 0 9255022, hotness: undefined, score: 0, children: 4
vitonsky 1 point 3 years ago

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 https://github.com/...

Is it that you need?

path: 0 9255022 9266679, hotness: undefined, score: 1, children: 3
FooBarrington 1 point 3 years ago

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)
path: 0 9255022 9266679 9267217, hotness: undefined, score: 1, children: 2
vitonsky 1 point 3 years ago

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 https://github.com/... It 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

path: 0 9255022 9266679 9267217 9268772, hotness: undefined, score: 1, children: 1
FooBarrington 1 point 3 years ago

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:

// we're in @/lib/foo

// correct
import A from "./foobar/a"
import B from "./b"
import C from "@/lib/c"
import D from "@/d"

// incorrect
import A from "@/lib/foo/foobar/a"
import B from "@/lib/foo/b"
path: 0 9255022 9266679 9267217 9268772 9268842, hotness: undefined, score: 1, children: 0
cool_github_projects
cool_github_projects

@programming.dev

login for more options
1759
124
20

Wormhole

!code_review@programming.dev

Icon base by Caro Asercion under CC BY 3.0 with modifications to add a gradient

go to feed...