eslint-plugin-paths: A plugin for ESLint, to force use paths aliases from tsconfig - eviltoast
  • FooBarrington@lemmy.world
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    7 months 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?

      • FooBarrington@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        7 months 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)
          • FooBarrington@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            edit-2
            7 months 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"