Unnecessary imports should be removed

Description

The imports part of a file should be handled by the Integrated Development Environment (IDE), not manually by the developer.
Unused and useless imports should not occur if that is the case.
Leaving them in reduces the code's readability, since their presence can be confusing.

Noncompliant Code Example

Message

* Remove this unused import. * Remove this duplicate import. * Remove this unnecessary import.

Highlighting

None

List of parameters

None
0% Done
Loading...

Activity

Li Huan jeowOctober 24, 2019 at 4:32 PM

In C#, this rule incorrectly removes imports used in XML comments.

Dinesh BolkensteynJuly 12, 2013 at 1:33 PM

IMO this is not much different from an unused variable, it does not harm, but it should be avoided.

I've updated the spec.

Dinesh BolkensteynJuly 12, 2013 at 11:21 AM

Why not enabled by default?

I guess this should be set to MINOR and enabled by default, it's simply a matter of proper IDE configuration, and should never happen.

Dinesh BolkensteynJuly 12, 2013 at 10:41 AM

Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Labels

Default Severity

Minor

Default Quality Profiles

Sonar way

Targeted languages

PHP
Python
VB.Net
XML

Covered Languages

C#
CSS
Java
JavaScript

Remediation Function

Constant/Issue

Constant Cost

Analysis Scope

Main Sources
Test Sources

Sentry

Created July 10, 2013 at 11:18 AM
Updated September 9, 2021 at 6:10 PM