source: frontend/node_modules/eslint-plugin-import/docs/rules/no-useless-path-segments.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: 2.5 KB
Line 
1# import/no-useless-path-segments
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 unnecessary path segments in import and require statements.
8
9## Rule Details
10
11Given the following folder structure:
12
13```pt
14my-project
15├── app.js
16├── footer.js
17├── header.js
18└── helpers.js
19└── helpers
20 └── index.js
21├── index.js
22└── pages
23 ├── about.js
24 ├── contact.js
25 └── index.js
26```
27
28The following patterns are considered problems:
29
30```js
31/**
32 * in my-project/app.js
33 */
34
35import "./../my-project/pages/about.js"; // should be "./pages/about.js"
36import "./../my-project/pages/about"; // should be "./pages/about"
37import "../my-project/pages/about.js"; // should be "./pages/about.js"
38import "../my-project/pages/about"; // should be "./pages/about"
39import "./pages//about"; // should be "./pages/about"
40import "./pages/"; // should be "./pages"
41import "./pages/index"; // should be "./pages" (except if there is a ./pages.js file)
42import "./pages/index.js"; // should be "./pages" (except if there is a ./pages.js file)
43```
44
45The following patterns are NOT considered problems:
46
47```js
48/**
49 * in my-project/app.js
50 */
51
52import "./header.js";
53import "./pages";
54import "./pages/about";
55import ".";
56import "..";
57import fs from "fs";
58```
59
60## Options
61
62### noUselessIndex
63
64If you want to detect unnecessary `/index` or `/index.js` (depending on the specified file extensions, see below) imports in your paths, you can enable the option `noUselessIndex`. By default it is set to `false`:
65
66```js
67"import/no-useless-path-segments": ["error", {
68 noUselessIndex: true,
69}]
70```
71
72Additionally to the patterns described above, the following imports are considered problems if `noUselessIndex` is enabled:
73
74```js
75// in my-project/app.js
76import "./helpers/index"; // should be "./helpers/" (not auto-fixable to `./helpers` because this would lead to an ambiguous import of `./helpers.js` and `./helpers/index.js`)
77import "./pages/index"; // should be "./pages" (auto-fixable)
78import "./pages/index.js"; // should be "./pages" (auto-fixable)
79```
80
81Note: `noUselessIndex` only avoids ambiguous imports for `.js` files if you haven't specified other resolved file extensions. See [Settings: import/extensions](https://github.com/import-js/eslint-plugin-import#importextensions) for details.
82
83### commonjs
84
85When set to `true`, this rule checks CommonJS imports. Default to `false`.
Note: See TracBrowser for help on using the repository browser.