Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions rules/S8304/groovy/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"title": "Duplicate import statements should be removed",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant/Issue",
"constantCost": "1 min"
},
"tags": [],
"defaultSeverity": "Critical",
"ruleSpecification": "RSPEC-8304",
"sqKey": "S8304",
"scope": "All",
"defaultQualityProfiles": [
"Sonar way"
],
"quickfix": "unknown",
"code": {
"impacts": {
"MAINTAINABILITY": "HIGH"
},
"attribute": "CLEAR"
}
}
36 changes: 36 additions & 0 deletions rules/S8304/groovy/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This rule raises an issue when the same import statement appears multiple times in a Groovy file.

== Why is this an issue?

Duplicate import statements create unnecessary code clutter without providing any functional benefit.

While duplicate imports don't cause compilation errors or runtime issues in Groovy, they make the code harder to read and maintain.

Keeping import statements clean and minimal helps developers quickly understand the dependencies of a file and reduces visual noise in the codebase.

=== What is the potential impact?

This issue has minimal impact on functionality but affects code readability and maintainability. Clean import sections help developers understand file dependencies more quickly.

== How to fix it

Remove the duplicate import statement. Keep only one instance of each import.

=== Code examples

==== Noncompliant code example

[source,groovy,diff-id=1,diff-type=noncompliant]
----
import java.util.List
import java.util.Map
import java.util.List // Noncompliant
----

==== Compliant solution

[source,groovy,diff-id=1,diff-type=compliant]
----
import java.util.List
import java.util.Map
----
2 changes: 2 additions & 0 deletions rules/S8304/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Loading