45 lines
1.2 KiB
Plaintext
45 lines
1.2 KiB
Plaintext
== 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.dart2'; // Noncompliant, this import is 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
|
|
|
|
* https://dart.dev/tools/diagnostic-messages?utm_source=dartdev&utm_medium=redir&utm_id=diagcode&utm_content=unnecessary_cast#unused_import[Dart compiler diagnostic]
|
|
|
|
=== Related rules
|
|
|
|
* S1481 - Unused local variables should be removed
|