diff --git a/README.md b/README.md index c8c3789aa8..b3ef575656 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a * Forbid `require()` calls with expressions ([`no-dynamic-require`]) * Prevent importing the submodules of other modules ([`no-internal-modules`]) * Forbid Webpack loader syntax in imports ([`no-webpack-loader-syntax`]) +* Forbid a module from importing itself ([`no-self-import`]) [`no-unresolved`]: ./docs/rules/no-unresolved.md [`named`]: ./docs/rules/named.md @@ -33,6 +34,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a [`no-dynamic-require`]: ./docs/rules/no-dynamic-require.md [`no-internal-modules`]: ./docs/rules/no-internal-modules.md [`no-webpack-loader-syntax`]: ./docs/rules/no-webpack-loader-syntax.md +[`no-self-import`]: ./docs/rules/no-self-import.md **Helpful warnings:** diff --git a/docs/rules/no-self-import.md b/docs/rules/no-self-import.md new file mode 100644 index 0000000000..d8bdbfb797 --- /dev/null +++ b/docs/rules/no-self-import.md @@ -0,0 +1,30 @@ +# Forbid a module from importing itself + +Forbid a module from importing iteself. This can sometimes happen during refactoring. + +## Rule Details + +### Fail + +```js +// foo.js +import foo from './foo'; + +const foo = require('./foo'); +``` + +```js +// index.js +import index from '.'; + +const index = require('.'); +``` + +### Pass + +```js +// foo.js +import bar from './bar'; + +const bar = reqire('./bar'); +``` diff --git a/src/rules/no-self-import.js b/src/rules/no-self-import.js index b47f943796..986af0c53f 100644 --- a/src/rules/no-self-import.js +++ b/src/rules/no-self-import.js @@ -1,5 +1,5 @@ /** - * @fileOverview Forbids a file from importing itself + * @fileOverview Forbids a module from importing itself * @author Gio d'Amelio */ @@ -26,7 +26,7 @@ function isImportingSelf(context, node, requireName) { module.exports = { meta: { doc: { - description: 'Forbid a file from importing itself', + description: 'Forbid a module from importing itself', recommended: true, }, schema: [],