github-actions[bot] 26945dcd6a
Create rule S7060 (#4224)
Co-authored-by: saberduck <saberduck@users.noreply.github.com>
2024-09-06 15:20:51 +02:00

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]