|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 1 | # import/no-relative-packages
|
|---|
| 2 |
|
|---|
| 3 | 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|---|
| 4 |
|
|---|
| 5 | <!-- end auto-generated rule header -->
|
|---|
| 6 |
|
|---|
| 7 | Use this rule to prevent importing packages through relative paths.
|
|---|
| 8 |
|
|---|
| 9 | It's useful in Yarn/Lerna workspaces, where it's possible to import a sibling package using `../package` relative path, while direct `package` is the correct one.
|
|---|
| 10 |
|
|---|
| 11 | ## Examples
|
|---|
| 12 |
|
|---|
| 13 | Given the following folder structure:
|
|---|
| 14 |
|
|---|
| 15 | ```pt
|
|---|
| 16 | my-project
|
|---|
| 17 | ├── packages
|
|---|
| 18 | │ ├── foo
|
|---|
| 19 | │ │ ├── index.js
|
|---|
| 20 | │ │ └── package.json
|
|---|
| 21 | │ └── bar
|
|---|
| 22 | │ ├── index.js
|
|---|
| 23 | │ └── package.json
|
|---|
| 24 | └── entry.js
|
|---|
| 25 | ```
|
|---|
| 26 |
|
|---|
| 27 | And the .eslintrc file:
|
|---|
| 28 |
|
|---|
| 29 | ```json
|
|---|
| 30 | {
|
|---|
| 31 | ...
|
|---|
| 32 | "rules": {
|
|---|
| 33 | "import/no-relative-packages": "error"
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | ```
|
|---|
| 37 |
|
|---|
| 38 | The following patterns are considered problems:
|
|---|
| 39 |
|
|---|
| 40 | ```js
|
|---|
| 41 | /**
|
|---|
| 42 | * in my-project/packages/foo.js
|
|---|
| 43 | */
|
|---|
| 44 |
|
|---|
| 45 | import bar from '../bar'; // Import sibling package using relative path
|
|---|
| 46 | import entry from '../../entry.js'; // Import from parent package using relative path
|
|---|
| 47 |
|
|---|
| 48 | /**
|
|---|
| 49 | * in my-project/entry.js
|
|---|
| 50 | */
|
|---|
| 51 |
|
|---|
| 52 | import bar from './packages/bar'; // Import child package using relative path
|
|---|
| 53 | ```
|
|---|
| 54 |
|
|---|
| 55 | The following patterns are NOT considered problems:
|
|---|
| 56 |
|
|---|
| 57 | ```js
|
|---|
| 58 | /**
|
|---|
| 59 | * in my-project/packages/foo.js
|
|---|
| 60 | */
|
|---|
| 61 |
|
|---|
| 62 | import bar from 'bar'; // Import sibling package using package name
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | * in my-project/entry.js
|
|---|
| 66 | */
|
|---|
| 67 |
|
|---|
| 68 | import bar from 'bar'; // Import sibling package using package name
|
|---|
| 69 | ```
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.