-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
Description
This is the proposal for no-relative-parent-imports rule improvement.
Context
When no-relative-parent-imports rule is enabled, it doesn't allow to import from relative parents at all, for example:
// Both will fail ESLint
import component from '../path/to/component' // immediate parent
import component from '../../path/to/component'However, it's sometimes acceptable and reasonable to import from the immediate parent as depicted above.
Proposal
Give no-relative-parent-imports the option of either strict or relaxed.
- If
strictis used, nothing will change, the current behavior stays intact.strictis by default if not specifying the option.
// Both will be in strict mode
// Explicitly specify the option
{
`no-relative-parent-imports`: ['warn', 'strict']
}
// `strict` by default
{
`no-relative-parent-imports`: 'warn'
}- If
relaxedis used, the rule will pass on immediate parent imports, and still catch the rest.
{
`no-relative-parent-imports`: ['warn', 'relaxed']
}import component from '../path/to/component' // passed
import component from '../../path/to/component' // failedEffect
By using strict by default, this proposal doesn't affect any existing users. However, it gives users more options to tweak the rule if needed.
Alternatives
Give the option to specify how depth of relative parent imports is allowed.
{
`no-relative-parent-imports`: ['warn', { depth: 2 }]
}import component from '../path/to/component' // passed
import component from '../../path/to/component' // passed
import component from '../../../path/to/component' // passedHowever, I think this isn't a preferred option since it goes against the purpose of no-relative-parent-imports rule.
Reactions are currently unavailable