== Why is this an issue?

Unnecessary imports refer to importing types that are not used or referenced anywhere in the code.

include::../description.adoc[]

== How to fix it

While it's not difficult to remove these unneeded lines manually, modern code editors support the removal of every unnecessary import with a single click from every file of the project.

=== Code examples

==== Noncompliant code example

[source,dart,diff-id=1,diff-type=noncompliant]
----
import 'package:dart_hello_world/dart_hello_world.dart' as dart_hello_world;
import 'package:dart_hello_world/dart_hello_world.dart' as dart_hello_world; // Noncompliant: duplicate
import 'package:dart_hello_world/dart_hello_world.dart2'; // Noncompliant: unused

void main(List<String> arguments) {
  print('Hello world: ${dart_hello_world.calculate()}!');
  return;
}
----

==== Compliant solution

[source,dart,diff-id=1,diff-type=compliant]
----
import 'package:dart_hello_world/dart_hello_world.dart' as dart_hello_world;

void main(List<String> arguments) {
  print('Hello world: ${dart_hello_world.calculate()}!');
  return;
}
----

== Resources

* Dart Docs - https://dart.dev/tools/diagnostic-messages#duplicate_import[Dart Compiler diagnostic - duplicate_import]
* Dart Docs - https://dart.dev/tools/diagnostic-messages#unnecessary_import[Dart Compiler diagnostic - unnecessary_import]
* Dart Docs - https://dart.dev/tools/diagnostic-messages#unused_import[Dart Compiler diagnostic - unused_import]

=== Related rules

* S1481 - Unused local variables should be removed

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

* Unused import: '<unused import path>'.
* The import of '<unnecessary import path>' is unnecessary because all of the used elements are also provided by the import of '<including import path>'.
* Duplicate import.

=== Highlighting

The string literal of the path of the unused import statement.

'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
