From 280f651e6e79000efd4aca4ceb1e2bf502346957 Mon Sep 17 00:00:00 2001 From: denis-troller Date: Sun, 9 Nov 2025 20:22:29 +0000 Subject: [PATCH 1/5] Create rule S8314 --- rules/S8314/groovy/metadata.json | 25 ++++++++++++++++++ rules/S8314/groovy/rule.adoc | 44 ++++++++++++++++++++++++++++++++ rules/S8314/metadata.json | 2 ++ 3 files changed, 71 insertions(+) create mode 100644 rules/S8314/groovy/metadata.json create mode 100644 rules/S8314/groovy/rule.adoc create mode 100644 rules/S8314/metadata.json diff --git a/rules/S8314/groovy/metadata.json b/rules/S8314/groovy/metadata.json new file mode 100644 index 00000000000..4a7fc3e30dd --- /dev/null +++ b/rules/S8314/groovy/metadata.json @@ -0,0 +1,25 @@ +{ + "title": "FIXME", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + ], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-8314", + "sqKey": "S8314", + "scope": "All", + "defaultQualityProfiles": ["Sonar way"], + "quickfix": "unknown", + "code": { + "impacts": { + "MAINTAINABILITY": "HIGH", + "RELIABILITY": "MEDIUM", + "SECURITY": "LOW" + }, + "attribute": "CONVENTIONAL" + } +} diff --git a/rules/S8314/groovy/rule.adoc b/rules/S8314/groovy/rule.adoc new file mode 100644 index 00000000000..16a0f60963c --- /dev/null +++ b/rules/S8314/groovy/rule.adoc @@ -0,0 +1,44 @@ +FIXME: add a description + +// If you want to factorize the description uncomment the following line and create the file. +//include::../description.adoc[] + +== Why is this an issue? + +FIXME: remove the unused optional headers (that are commented out) + +//=== What is the potential impact? + +== How to fix it +//== How to fix it in FRAMEWORK NAME + +=== Code examples + +==== Noncompliant code example + +[source,groovy,diff-id=1,diff-type=noncompliant] +---- +FIXME +---- + +==== Compliant solution + +[source,groovy,diff-id=1,diff-type=compliant] +---- +FIXME +---- + +//=== How does this work? + +//=== Pitfalls + +//=== Going the extra mile + + +//== Resources +//=== Documentation +//=== Articles & blog posts +//=== Conference presentations +//=== Standards +//=== External coding guidelines +//=== Benchmarks diff --git a/rules/S8314/metadata.json b/rules/S8314/metadata.json new file mode 100644 index 00000000000..2c63c085104 --- /dev/null +++ b/rules/S8314/metadata.json @@ -0,0 +1,2 @@ +{ +} From 5928d39de911e4e2cc496d3f9182a1177ed5087b Mon Sep 17 00:00:00 2001 From: denis-troller Date: Sun, 9 Nov 2025 21:50:53 +0100 Subject: [PATCH 2/5] Update rules/S8314/groovy/rule.adoc in PR #5900 --- rules/S8314/groovy/rule.adoc | 45 +++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/rules/S8314/groovy/rule.adoc b/rules/S8314/groovy/rule.adoc index 16a0f60963c..dcc6b339e0e 100644 --- a/rules/S8314/groovy/rule.adoc +++ b/rules/S8314/groovy/rule.adoc @@ -1,16 +1,20 @@ -FIXME: add a description - -// If you want to factorize the description uncomment the following line and create the file. -//include::../description.adoc[] +This rule raises an issue when static imports are declared after regular (non-static) imports in a source file. == Why is this an issue? -FIXME: remove the unused optional headers (that are commented out) +Import statements should follow a consistent ordering convention to improve code readability and maintainability. The widely accepted convention in Java and Groovy is to place all static imports before regular imports. + +When imports are not properly ordered, it creates visual inconsistency that can make code harder to scan and understand. While this doesn't affect the functionality of the code, following consistent import ordering helps developers quickly locate and understand dependencies. + +Most style guides and IDEs default to this ordering convention, so maintaining it ensures your code aligns with common practices and tools. + +=== What is the potential impact? -//=== What is the potential impact? +This issue has minimal impact on functionality but affects code readability and maintainability. Inconsistent import ordering can make it harder for developers to quickly scan and understand code dependencies, especially in files with many imports. == How to fix it -//== How to fix it in FRAMEWORK NAME + +Move all static imports to appear before regular imports. Group static imports together at the top of the import section. === Code examples @@ -18,27 +22,30 @@ FIXME: remove the unused optional headers (that are commented out) [source,groovy,diff-id=1,diff-type=noncompliant] ---- -FIXME +import org.codenarc.rule.InlineViolationsParser +import static org.codenarc.rule.InlineViolationsParser.inlineViolation // Noncompliant ---- ==== Compliant solution [source,groovy,diff-id=1,diff-type=compliant] ---- -FIXME +import static org.codenarc.rule.InlineViolationsParser.inlineViolation +import org.codenarc.rule.InlineViolationsParser ---- -//=== How does this work? +== Resources + +=== Documentation + + * Groovy Style Guide - Import Statements - https://groovy-lang.org/style-guide.html#_import_statements[Official Groovy style guide recommendations for import statement ordering] + + * Java Code Conventions - Import Statements - https://www.oracle.com/java/technologies/javase/codeconventions-imports.html[Oracle's Java code conventions for import statement organization] -//=== Pitfalls +=== Standards -//=== Going the extra mile + * Google Java Style Guide - Import Statements - https://google.github.io/styleguide/javaguide.html#s3.3-import-statements[Google's Java style guide specifying import ordering conventions] +=== Related rules -//== Resources -//=== Documentation -//=== Articles & blog posts -//=== Conference presentations -//=== Standards -//=== External coding guidelines -//=== Benchmarks + * RSPEC-2208 - https://rules.sonarsource.com/java/RSPEC-2208/[Wildcard imports should not be used (Java)] From 1cea43a49f557e577e8935f90cd7c63b263d908a Mon Sep 17 00:00:00 2001 From: denis-troller Date: Sun, 9 Nov 2025 21:50:57 +0100 Subject: [PATCH 3/5] Update rules/S8314/groovy/metadata.json in PR #5900 --- rules/S8314/groovy/metadata.json | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/rules/S8314/groovy/metadata.json b/rules/S8314/groovy/metadata.json index 4a7fc3e30dd..b79a3b43919 100644 --- a/rules/S8314/groovy/metadata.json +++ b/rules/S8314/groovy/metadata.json @@ -1,25 +1,27 @@ { - "title": "FIXME", + "title": "Static imports should appear before regular imports", "type": "CODE_SMELL", "status": "ready", "remediation": { - "func": "Constant\/Issue", - "constantCost": "5min" + "func": "Constant/Issue", + "constantCost": "5 min" }, "tags": [ + "convention", + "imports" ], - "defaultSeverity": "Major", + "defaultSeverity": "Critical", "ruleSpecification": "RSPEC-8314", "sqKey": "S8314", - "scope": "All", - "defaultQualityProfiles": ["Sonar way"], + "scope": "Main", + "defaultQualityProfiles": [ + "Sonar way" + ], "quickfix": "unknown", "code": { "impacts": { - "MAINTAINABILITY": "HIGH", - "RELIABILITY": "MEDIUM", - "SECURITY": "LOW" + "MAINTAINABILITY": "HIGH" }, "attribute": "CONVENTIONAL" } -} +} \ No newline at end of file From 353f1017b91b017a058d63e7087a22a4515ec6ac Mon Sep 17 00:00:00 2001 From: "erwan.serandour" Date: Thu, 11 Dec 2025 16:53:37 +0100 Subject: [PATCH 4/5] shorten the rule description --- rules/S8314/groovy/metadata.json | 5 +---- rules/S8314/groovy/rule.adoc | 26 ++------------------------ 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/rules/S8314/groovy/metadata.json b/rules/S8314/groovy/metadata.json index b79a3b43919..4c69e408aa8 100644 --- a/rules/S8314/groovy/metadata.json +++ b/rules/S8314/groovy/metadata.json @@ -6,10 +6,7 @@ "func": "Constant/Issue", "constantCost": "5 min" }, - "tags": [ - "convention", - "imports" - ], + "tags": [], "defaultSeverity": "Critical", "ruleSpecification": "RSPEC-8314", "sqKey": "S8314", diff --git a/rules/S8314/groovy/rule.adoc b/rules/S8314/groovy/rule.adoc index dcc6b339e0e..245e9e0791e 100644 --- a/rules/S8314/groovy/rule.adoc +++ b/rules/S8314/groovy/rule.adoc @@ -2,19 +2,11 @@ This rule raises an issue when static imports are declared after regular (non-st == Why is this an issue? -Import statements should follow a consistent ordering convention to improve code readability and maintainability. The widely accepted convention in Java and Groovy is to place all static imports before regular imports. - -When imports are not properly ordered, it creates visual inconsistency that can make code harder to scan and understand. While this doesn't affect the functionality of the code, following consistent import ordering helps developers quickly locate and understand dependencies. - -Most style guides and IDEs default to this ordering convention, so maintaining it ensures your code aligns with common practices and tools. - -=== What is the potential impact? - -This issue has minimal impact on functionality but affects code readability and maintainability. Inconsistent import ordering can make it harder for developers to quickly scan and understand code dependencies, especially in files with many imports. +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 -Move all static imports to appear before regular imports. Group static imports together at the top of the import section. +Place all static imports together before regular imports in the import section. === Code examples @@ -34,18 +26,4 @@ import static org.codenarc.rule.InlineViolationsParser.inlineViolation import org.codenarc.rule.InlineViolationsParser ---- -== Resources - -=== Documentation - - * Groovy Style Guide - Import Statements - https://groovy-lang.org/style-guide.html#_import_statements[Official Groovy style guide recommendations for import statement ordering] - - * Java Code Conventions - Import Statements - https://www.oracle.com/java/technologies/javase/codeconventions-imports.html[Oracle's Java code conventions for import statement organization] - -=== Standards - - * Google Java Style Guide - Import Statements - https://google.github.io/styleguide/javaguide.html#s3.3-import-statements[Google's Java style guide specifying import ordering conventions] - -=== Related rules - * RSPEC-2208 - https://rules.sonarsource.com/java/RSPEC-2208/[Wildcard imports should not be used (Java)] From 42329e507761572179d5a971f1a2ca44370fb164 Mon Sep 17 00:00:00 2001 From: "erwan.serandour" Date: Fri, 12 Dec 2025 15:19:37 +0100 Subject: [PATCH 5/5] fix code example --- rules/S8314/groovy/rule.adoc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rules/S8314/groovy/rule.adoc b/rules/S8314/groovy/rule.adoc index 245e9e0791e..2c591eff2b8 100644 --- a/rules/S8314/groovy/rule.adoc +++ b/rules/S8314/groovy/rule.adoc @@ -14,16 +14,16 @@ Place all static imports together before regular imports in the import section. [source,groovy,diff-id=1,diff-type=noncompliant] ---- -import org.codenarc.rule.InlineViolationsParser -import static org.codenarc.rule.InlineViolationsParser.inlineViolation // Noncompliant +import java.util.ArrayList +import static java.lang.Math.PI // Noncompliant ---- ==== Compliant solution [source,groovy,diff-id=1,diff-type=compliant] ---- -import static org.codenarc.rule.InlineViolationsParser.inlineViolation -import org.codenarc.rule.InlineViolationsParser +import static java.lang.Math.PI +import java.util.ArrayList ----