import-js / import-js/eslint-plugin-import
import/no-relative-parent-imports - an option to allow for types-only imports
- Dominant language
- JavaScript
- Stars
- 5.9k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
I'm working on a project where I enforce the rule `import/no-relative-parent-imports`. However, while I can follow this rule for the actual code (**js**), I can't ensure conformance throughout the code because of the types.
Consider an example:
```
src/
types.ts // export interface ClientInterface {...}
clients/
client-a.ts // class ClientA implements ClientInterface {...}
client-b.ts // class ClientB implements ClientInterface {...}
```
Even in this simple case, the rule gets violated and there is no way to avoid it. Yet the rest of the code strictly follows it.
There are two workarounds:
- create a separate package with only one type and w/o any real code
- put the `ClientInterface` type definition into `declare global {}`
The first variant is obviously ridiculous.
The second one brings more harm than good: using global types in a typescript project is an anti-pattern.
My current workaround is to switch off the rule:
```ts
// eslint-disable-next-line import/no-relative-parent-imports
import { type ClientInterface } from '../types';
```
I'm sure it would be a good thing to have a rule option, which allowed relative parents when they're being imported with the `type` word, as I've just showed.
Contributor guide
Research direction
Start by locating the implementation and tests for the import/no-relative-parent-imports rule. Review how the rule identifies relative parent imports and how options are documented or tested. Done means an option permits parent imports used only for types while the existing behavior remains unchanged for runtime imports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100