43 lines
1.1 KiB
Plaintext
43 lines
1.1 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
|
||
|
|
||
|
=== Related rules
|
||
|
|
||
|
* S1481 - Unused local variables should be removed
|