44 lines
1.3 KiB
Plaintext
44 lines
1.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Having the same module imported multiple times can affect code readability and maintainability. It makes hard to identify which modules are being used.
|
|
|
|
[source,javascript,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
import { B1 } from 'b';
|
|
import { B2 } from 'b'; // Noncompliant: there is already an import from module 'b'.
|
|
----
|
|
|
|
Instead, one should consolidate the imports from the same module into a single statement. By consolidating all imports from the same module in a single `import` statement, the code becomes more concise and easier to read, as there is only one import statement to keep track of. Additionally, it can make it easier to identify which modules are used in the code.
|
|
|
|
[source,javascript,diff-id=1,diff-type=compliant]
|
|
----
|
|
import { B1, B2 } from 'b';
|
|
----
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import[`import`]
|
|
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules[JavaScript modules]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Merge this import with another one from the same module on line N.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
Primary: Import #1
|
|
|
|
Secondary: previous Import to be merged with
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|