# no-useless-path-segments

Rule `import/no-useless-path-segments`. Forbid unnecessary path segments in import and require statements.

- Source: import
- Technologies: Imports
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 10.3M weekly downloads of presets that enable it
- Trend: +1.9% last quarter
- Rank: #877 by reach, #1620 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `import/no-useless-path-segments` | no | safe | package `eslint-plugin-import` | [docs](https://github.com/import-js/eslint-plugin-import/blob/v2.32.0/docs/rules/no-useless-path-segments.md) |

## Code examples

### Incorrect: the rule reports this

```js
/**
 *  in my-project/app.js
 */

import "./../my-project/pages/about.js"; // should be "./pages/about.js"
import "./../my-project/pages/about"; // should be "./pages/about"
import "../my-project/pages/about.js"; // should be "./pages/about.js"
import "../my-project/pages/about"; // should be "./pages/about"
import "./pages//about"; // should be "./pages/about"
import "./pages/"; // should be "./pages"
import "./pages/index"; // should be "./pages" (except if there is a ./pages.js file)
import "./pages/index.js"; // should be "./pages" (except if there is a ./pages.js file)
```

### Correct: the rule accepts this

```js
/**
 *  in my-project/app.js
 */

import "./header.js";
import "./pages";
import "./pages/about";
import ".";
import "..";
import fs from "fs";
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import importPlugin from "eslint-plugin-import";

export default [
  {
    plugins: { import: importPlugin },
    rules: {
      "import/no-useless-path-segments": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Airbnb base](https://lintradar.dev/presets/airbnb-base.md) | ESLint | `eslint-config-airbnb-base` | 241 | 6.5M | +2.1% |
| [Airbnb](https://lintradar.dev/presets/airbnb.md) | ESLint | `eslint-config-airbnb` | 346 | 3.4M | +2.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [import/order](https://lintradar.dev/rules/import/order.md): Enforce a convention in module import order.
- [import/extensions](https://lintradar.dev/rules/import/extensions.md): Ensure consistent use of file extension within the import path.
- [import/no-self-import](https://lintradar.dev/rules/import/no-self-import.md): Forbid a module from importing itself.
- [import/no-cycle](https://lintradar.dev/rules/import/no-cycle.md): Forbid a module from importing a module with a dependency path back to itself.
- [import/newline-after-import](https://lintradar.dev/rules/import/newline-after-import.md): Enforce a newline after import statements.
- [import/no-extraneous-dependencies](https://lintradar.dev/rules/import/no-extraneous-dependencies.md): Forbid the use of extraneous packages.

---

Web page: https://lintradar.dev/rules/import/no-useless-path-segments. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
