source: frontend/node_modules/eslint-plugin-import/docs/rules/no-relative-packages.md

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
7Use this rule to prevent importing packages through relative paths.
8
9It'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
13Given the following folder structure:
14
15```pt
16my-project
17├── packages
18│ ├── foo
19│ │ ├── index.js
20│ │ └── package.json
21│ └── bar
22│ ├── index.js
23│ └── package.json
24└── entry.js
25```
26
27And the .eslintrc file:
28
29```json
30{
31 ...
32 "rules": {
33 "import/no-relative-packages": "error"
34 }
35}
36```
37
38The following patterns are considered problems:
39
40```js
41/**
42 * in my-project/packages/foo.js
43 */
44
45import bar from '../bar'; // Import sibling package using relative path
46import entry from '../../entry.js'; // Import from parent package using relative path
47
48/**
49 * in my-project/entry.js
50 */
51
52import bar from './packages/bar'; // Import child package using relative path
53```
54
55The following patterns are NOT considered problems:
56
57```js
58/**
59 * in my-project/packages/foo.js
60 */
61
62import bar from 'bar'; // Import sibling package using package name
63
64/**
65 * in my-project/entry.js
66 */
67
68import bar from 'bar'; // Import sibling package using package name
69```
Note: See TracBrowser for help on using the repository browser.