import-js/eslint-plugin-import

Add 'allow' option to the no-relative-parent-imports rule or 'ignoreChildren' option to no-internal-modules rule.

Ouverte

#1 118 ouverte le 7 juin 2018

 (4 commentaires) (7 réactions) (0 personne assignée)JavaScript (1 548 forks)batch import
acceptedenhancementhelp wantedquestion

Métriques du dépôt

Stars
 (5 940 étoiles)
Métriques de merge PR
 (Merge moyen 138j 22h) (3 PRs mergées en 30 j)

Description

Our use case is to have some util classes/functions in a folder on top and then always import using relative path. Eg.

src/
 utils/
   util1.js
 comp1/
   index.js
 comp2/
   index.js

From src/comp1/index.js i'd like to be able to import from ../utils/util1 but prohibit import from ../comp2

To achieve this, I see two options:

  1. add 'allow' option to no-relative-parent-imports rule (in the same form as no-internal-modules 'allow'), eg.
"import/no-relative-parent-imports": [ "error", { "allow": ["**/src/utils/**"] } ]
  1. add 'ignoreChildren' option to no-internal-modules to only inspect parent's internal modules, eg.
"import/no-internal-modules": [ "error", { "allow": ["**/src/utils/**"], "ignoreChildren": true  } ]

I'm willing to provide a PR to any of the rules.

Guide contributeur