Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds no-useless-path-segments documentation. #1068

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## [Unreleased]
- Add documentation for [`no-useless-path-segments`] rule ([#1068], thanks [@manovotny])
- Fixer for [`first`] ([#1046], thanks [@fengkfengk])

## [2.10.0] - 2018-03-29
Expand Down Expand Up @@ -452,6 +453,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#1068]: https://github.com/benmosher/eslint-plugin-import/pull/1068
[#1046]: https://github.com/benmosher/eslint-plugin-import/pull/1046
[#944]: https://github.com/benmosher/eslint-plugin-import/pull/944
[#891]: https://github.com/benmosher/eslint-plugin-import/pull/891
Expand Down Expand Up @@ -694,3 +696,4 @@ for info on changes for earlier releases.
[@graingert]: https://github.com/graingert
[@danny-andrews]: https://github.com/dany-andrews
[@fengkfengk]: https://github.com/fengkfengk
[@manovotny]: https://github.com/manovotny
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
* Forbid webpack loader syntax in imports ([`no-webpack-loader-syntax`])
* Forbid a module from importing itself ([`no-self-import`])
* Forbid a module from importing a module with a dependency path back to itself ([`no-cycle`])
* Prevent unnecessary path segemnts in import and require statements ([`no-useless-path-segments`])

[`no-unresolved`]: ./docs/rules/no-unresolved.md
[`named`]: ./docs/rules/named.md
Expand All @@ -37,6 +38,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
[`no-webpack-loader-syntax`]: ./docs/rules/no-webpack-loader-syntax.md
[`no-self-import`]: ./docs/rules/no-self-import.md
[`no-cycle`]: ./docs/rules/no-cycle.md
[`no-useless-path-segments`]: ./docs/rules/no-useless-path-segments.md

### Helpful warnings

Expand Down
48 changes: 48 additions & 0 deletions docs/rules/no-useless-path-segments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# import/no-useless-path-segments

Use this rule to prevent unnecessary path segemnts in import and require statements.

## Rule Details

Given the following folder structure:

```
my-project
├── app.js
├── footer.js
├── header.js
└── pages
├── about.js
├── contact.js
└── index.js
```

The following patterns are considered problems:

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

import "./../pages/about.js"; // should be "./pages/about.js"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be "./../my-project/pages/about.js" // should be "./pages/about.js"

import "./../pages/about"; // should be "./pages/about"
import "../pages/about.js"; // should be "./pages/about.js"
import "../pages/about"; // should be "./pages/about"
import "./pages//about"; // should be "./pages/about"
import "./pages/"; // should be "./pages"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth adding a note about:

import "../" -> import "./"

```

The following patterns are NOT considered problems:

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

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