diff --git a/CHANGELOG.md b/CHANGELOG.md index 45891d9fe8..24ba4b5654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 @@ -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 diff --git a/README.md b/README.md index 529525363a..6fab768617 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/docs/rules/no-useless-path-segments.md b/docs/rules/no-useless-path-segments.md new file mode 100644 index 0000000000..d0891ee187 --- /dev/null +++ b/docs/rules/no-useless-path-segments.md @@ -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" +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" +``` + +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"; +```