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/S8314/groovy/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"title": "Static imports should appear before regular imports",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant/Issue",
"constantCost": "5 min"
},
"tags": [],
"defaultSeverity": "Critical",
"ruleSpecification": "RSPEC-8314",
"sqKey": "S8314",
"scope": "Main",
"defaultQualityProfiles": [
"Sonar way"
],
"quickfix": "unknown",
"code": {
"impacts": {
"MAINTAINABILITY": "HIGH"
},
"attribute": "CONVENTIONAL"
}
}
29 changes: 29 additions & 0 deletions rules/S8314/groovy/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
This rule raises an issue when static imports are declared after regular (non-static) imports in a source file.

== Why is this an issue?

Import statements should follow a consistent order to keep code readable and easy to scan. In Java and Groovy, the usual convention is to place all static imports before regular imports.

== How to fix it

Place all static imports together before regular imports in the import section.

=== Code examples

==== Noncompliant code example

[source,groovy,diff-id=1,diff-type=noncompliant]
----
import java.util.ArrayList
import static java.lang.Math.PI // Noncompliant
----

==== Compliant solution

[source,groovy,diff-id=1,diff-type=compliant]
----
import static java.lang.Math.PI
import java.util.ArrayList
----


2 changes: 2 additions & 0 deletions rules/S8314/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Loading