29 lines
886 B
Plaintext
29 lines
886 B
Plaintext
== Why is this an issue?
|
|
|
|
When a module imports itself it has no effect. This means that the import statement does nothing useful and serves no purpose. This can happen during refactoring or when a developer mistakenly imports the module itself.
|
|
|
|
To fix the problem remove the self-import statement.
|
|
|
|
[source,javascript]
|
|
----
|
|
// file: foo.js
|
|
import foo from './foo'; // Noncompliant
|
|
|
|
const foo = require('./foo'); // Noncompliant
|
|
----
|
|
|
|
[source,javascript]
|
|
----
|
|
// file: index.js
|
|
import index from '.'; // Noncompliant
|
|
|
|
const index = require('.'); // Noncompliant
|
|
----
|
|
|
|
|
|
== Resources
|
|
=== Documentation
|
|
|
|
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules[Modules]
|
|
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import[import]
|
|
* Node.js docs - https://nodejs.org/api/modules.html#requireid[Node.js require] |