57 lines
1.6 KiB
Plaintext

== Why is this an issue?
Unnecessary imports refer to importing modules, libraries, or dependencies that are not used or referenced anywhere in the code. These imports do not contribute to the functionality of the application and only add extra weight to the JavaScript bundle, leading to potential performance and maintainability issues.
[source,javascript,diff-id=1,diff-type=noncompliant]
----
import A from 'a'; // Noncompliant: The imported symbol 'A' isn't used
import { B1 } from 'b';
console.log(B1);
----
To mitigate the problems associated with unnecessary imports, you should regularly review and remove any imports that are not being used. Modern JavaScript build tools and bundlers often provide features like tree shaking, which eliminates unused code during the bundling process, resulting in a more optimized bundle size.
[source,javascript,diff-id=1,diff-type=compliant]
----
import { B1 } from 'b';
console.log(B1);
----
== Resources
=== Documentation
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import[``++import++``]
=== Related rules
* S1481 - Unused local variables and functions should be removed
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* Remove this unused import of {}.
=== Highlighting
Primary: Import to remove/merge
'''
== Comments And Links
(visible only on this page)
=== on 28 Jan 2019, 11:51:08 Nicolas Harraudeau wrote:
Message updated to match the implementation. This is part of the title cleaning for this rule.
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]