electroma / tslint-forbidden-imports

TSLint rule to control dependencies between project modules
The Unlicense
2 stars 0 forks source link

Does not support path aliases #4

Open mikekreeki opened 6 years ago

mikekreeki commented 6 years ago

Awesome plugin, exactly what we were looking for, but the plugin does not seem to resolve import paths which use aliases defined in tsconfig.

In our project we import like:

 import SomeStore from 'stores/SomeStore'

With tsconfig containing the following:

{
  "compilerOptions": {
    "paths": {
      "stores/*": ["src/js/stores/*"]
    }
  }
}
electroma commented 6 years ago

Thank you for your feedback, @mikekreeki! Responsible and consistent usage of path aliases makes code cleaner.

From what I can see at https://github.com/palantir/tslint/issues/3654 and https://github.com/palantir/tslint/issues/3364#issuecomment-338920133 it's not enough to have TypeScript AST. It looks like TSLint doesn't run actual module resolution, which is required to distinguish path-aliased local imports from library imports.

I'll dig into TSLint core and try to figure out if architecturally possible to do some kind of lightweight module resolution (w/o full compilation).

mikekreeki commented 6 years ago

Thank you so much. I see big value in this plugin for projects with multiple teams working in the same codebase, we feel the pains in managing that manually and being able to do bundle splitting efficiently.

galkin commented 5 years ago

@electroma, thank you for cool package.

Do you have any updates about this issue?

uluzox commented 5 years ago

I wrote a rule myself. It is not as sophisticated but for my use cases it works. You may want to check it out here

rickihastings commented 5 years ago

Paths appear to work for me without any issues. I'm using the following versions:

Typescript 3.1.6 Tslint 5.11.0 Tslint-forbidden-imports 1.0.9