-
Notifications
You must be signed in to change notification settings - Fork 198
How should I use no-relative-imports #435
Comments
I have the same question. I cannot figure out how to get no-relative-imports to work with the no-submodule-includes and the no-implicit-dependencies issues. Just seems like too much hassle so I disabled the no-relative-imports rule. |
Hi there - welcome to TS/TSLint/VSCode/etc.! Glad you're enjoying the new area 😊 it's great to have you! I personally don't use this rule in my projects. The idea as I understand it is to encourage setting a |
I've tried using the baseUrl method to get rid of the no relative paths issues, however when I do that I start violating two other rules: no-submodule-includes and no-implicit-dependencies. no-submodule-includes is hit because I include components from subfolders in my solution. Can we drop the no-relative-imports rule from the microsoft tslint rule set? It might make sense for tiny projects or for npm packages but definitely does not work for website projects using tools such as webpack. |
Amusing. Yes, I'm in support of this. Let's leave this issue open for a few weeks, we can mark it as deprecated, then remove in a future major version. |
tslint:latest and tslint-microsoft-contrib rule sets applied. Exceptions are set to: "no-relative-imports": false, "no-import-side-effect": [true, {"ignore-module": "(\\.css)$"}] The first rule allow relative imports. It seems MS itself is going to deprecate them (microsoft/tslint-microsoft-contrib#435). The second rule allows CSS files to be imported without an "import with side effects" warning.
@JoshuaKGoldberg Please don't remove this, I really like this rule. We don't use the Maybe we can just publish this as a standalone rule? |
Interesting! @LukeSheard - could you please give a little more info on why you chose that way? |
@JoshuaKGoldberg While I probably can't give amazingly detailed specifics.. Essentially we run a very large monorepo + single package.json at the root and so we run with the idea that our "top level" is a set of packages itself, meaning that imports look like import { myThing } from "my/other/thing/over/here"; Since we other languages side by side with TypeScript we find that it gives nice consistency and also means if you move a file you can easily update imports by just searching for the module path. |
That's a really interesting approach, thanks for posting it! Have you tried good-fences? Also, would you mind also posting your Instead of deprecating this rule, since this is a very legitimate use case, let's say we remove it from the recommended ruleset and mention the monorepo use case in its documentation? |
@JoshuaKGoldberg I haven't come across Our I think that removing it from the default recommended configuration is the best solution, leaving it for users to bring it if it works for their use case. |
Just to follow up here this is a the rough selection of our rules around imports and exports. To make things slightly more opaque we actually wrap this up with a script to check the
|
While I can get behind the original reasons, I believe this rule should be removed for a few reasons:
I'm still pretty new to Typescript and getting my head around this rule is what took me the most time so far. |
In v6.0 Does this option solve other problems (if any) in this thread? |
Also same experience here with conflicting I had defined an alias What helped me, was to add this alias to the whitelist of the rules like this:
|
This is not possible for Angular 7. Already tried every answer on the web :( |
Sorry to hear that. I can only speak from a react-ts app perspective. Solution above worked for me. |
Tweaked @Ford04's solution and it seems to work well with a default React project structure:
|
Just ran across this project that may be relevant to some people in this discussion. https://github.com/vladimiry/tslint-rules-bunch |
☠️ It's time! ☠️ Per #876, this repository is no longer accepting feature pull requests. TSLint is being deprecated and we recommend you switch to https://typescript-eslint.io. Thanks for open sourcing with us, everyone! |
Hello!
I am amazed how productive became my work with vscode, typescript and this config.
Thank you for your great work with it.
I'm new with typescript and tslint, so I'm a bit confused how to use rule 'no-relative-imports'.
Suppose I have small frontend project with Webpack + Vue + ts-loader.
Main core written with typescript, other files with javascript.
In folder 'core' I have two files:
The thing is, 'no-relative-imports' throws error:
[tslint] Imported module is being loaded from a relative path. Please use an absolute path: import * as ElData from './ElData'; (no-relative-imports)
Hmm, disable rule is not my way to resolve a problem!
[tslint] Module 'ElData' is not listed as dependency in package.json (no-implicit-dependencies)
Well, lets try another way
And then
[tslint] Module 'core' is not listed as dependency in package.json (no-implicit-dependencies)
[tslint] Submodule import paths from this package are disallowed; import from the root instead (no-submodule-imports)
Arrgh
My webpack config a bit supercharged with aliases
[tslint] Module '@/core' is not listed as dependency in package.json (no-implicit-dependencies)
[tslint] Submodule import paths from this package are disallowed; import from the root instead (no-submodule-imports)
[ts] Cannot find module '@/core/ElData'.
Jesus, all I achieved is just increase of errors.
How should I cook my imports?
The text was updated successfully, but these errors were encountered: