From bb83d48cedff86355defe9b8fdcb6102d557fb89 Mon Sep 17 00:00:00 2001 From: denis-troller Date: Tue, 21 Oct 2025 16:22:57 +0000 Subject: [PATCH 1/5] Create rule S8196 --- rules/S8196/go/metadata.json | 25 ++++++++++++++++++++ rules/S8196/go/rule.adoc | 44 ++++++++++++++++++++++++++++++++++++ rules/S8196/metadata.json | 2 ++ 3 files changed, 71 insertions(+) create mode 100644 rules/S8196/go/metadata.json create mode 100644 rules/S8196/go/rule.adoc create mode 100644 rules/S8196/metadata.json diff --git a/rules/S8196/go/metadata.json b/rules/S8196/go/metadata.json new file mode 100644 index 00000000000..83382eae48f --- /dev/null +++ b/rules/S8196/go/metadata.json @@ -0,0 +1,25 @@ +{ + "title": "FIXME", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + ], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-8196", + "sqKey": "S8196", + "scope": "All", + "defaultQualityProfiles": ["Sonar way"], + "quickfix": "unknown", + "code": { + "impacts": { + "MAINTAINABILITY": "HIGH", + "RELIABILITY": "MEDIUM", + "SECURITY": "LOW" + }, + "attribute": "CONVENTIONAL" + } +} diff --git a/rules/S8196/go/rule.adoc b/rules/S8196/go/rule.adoc new file mode 100644 index 00000000000..7193b5561c7 --- /dev/null +++ b/rules/S8196/go/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,go,diff-id=1,diff-type=noncompliant] +---- +FIXME +---- + +==== Compliant solution + +[source,go,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/S8196/metadata.json b/rules/S8196/metadata.json new file mode 100644 index 00000000000..2c63c085104 --- /dev/null +++ b/rules/S8196/metadata.json @@ -0,0 +1,2 @@ +{ +} From 8746a271afe687bf72db4a51891f4f369e05ac81 Mon Sep 17 00:00:00 2001 From: denis-troller Date: Tue, 21 Oct 2025 18:58:50 +0200 Subject: [PATCH 2/5] Update rules/S8196/go/rule.adoc in PR #5757 --- rules/S8196/go/rule.adoc | 46 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/rules/S8196/go/rule.adoc b/rules/S8196/go/rule.adoc index 7193b5561c7..97fe82dbf80 100644 --- a/rules/S8196/go/rule.adoc +++ b/rules/S8196/go/rule.adoc @@ -1,16 +1,25 @@ -FIXME: add a description - -// If you want to factorize the description uncomment the following line and create the file. -//include::../description.adoc[] +This is an issue when a single-method interface doesn't use the method name plus an "-er" suffix or similar modification to construct an agent noun. == Why is this an issue? -FIXME: remove the unused optional headers (that are commented out) +Go has established naming conventions for interfaces, particularly single-method interfaces. According to the official Go documentation "Effective Go", single-method interfaces should be named by taking the method name and adding an "-er" suffix or similar modification to create an agent noun. + +This convention serves several important purposes: + +* **Predictability**: Developers can quickly understand what an interface does just by looking at its name +* **Consistency**: Following established patterns makes codebases more uniform and easier to navigate +* **Readability**: Agent nouns like `Reader`, `Writer`, `Formatter` immediately convey the interface's purpose +* **Community standards**: Adhering to Go conventions makes code more familiar to other Go developers + +When interfaces don't follow this pattern, they become less intuitive. For example, `FileRead` doesn't immediately suggest it's an interface, while `Reader` clearly indicates both the action and that it's likely an interface following Go conventions. -//=== What is the potential impact? +=== What is the potential impact? + +Not following Go naming conventions reduces code readability and makes it harder for developers to understand the codebase quickly. It can also make the code feel inconsistent with standard Go libraries and community practices, potentially confusing team members who expect conventional naming patterns. == How to fix it -//== How to fix it in FRAMEWORK NAME + +Rename the interface to follow Go conventions by using the method name plus an "-er" suffix or similar agent noun construction. === Code examples @@ -18,27 +27,24 @@ FIXME: remove the unused optional headers (that are commented out) [source,go,diff-id=1,diff-type=noncompliant] ---- -FIXME +type FileRead interface { + Read([]byte) (int, error) +} // Noncompliant ---- ==== Compliant solution [source,go,diff-id=1,diff-type=compliant] ---- -FIXME +type Reader interface { + Read([]byte) (int, error) +} ---- -//=== How does this work? - -//=== Pitfalls +== Resources -//=== Going the extra mile +=== Documentation + * Effective Go - Interface names - https://go.dev/doc/effective_go#interface-names[Official Go documentation explaining interface naming conventions] -//== Resources -//=== Documentation -//=== Articles & blog posts -//=== Conference presentations -//=== Standards -//=== External coding guidelines -//=== Benchmarks + * Go Code Review Comments - Interface Names - https://github.com/golang/go/wiki/CodeReviewComments#interface-names[Go team's code review guidelines for interface naming] From 0372c4cc993e1279b6d2cafa4cbf6f29d33db6f8 Mon Sep 17 00:00:00 2001 From: denis-troller Date: Tue, 21 Oct 2025 18:58:53 +0200 Subject: [PATCH 3/5] Update rules/S8196/go/metadata.json in PR #5757 --- rules/S8196/go/metadata.json | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/rules/S8196/go/metadata.json b/rules/S8196/go/metadata.json index 83382eae48f..2631014920b 100644 --- a/rules/S8196/go/metadata.json +++ b/rules/S8196/go/metadata.json @@ -1,25 +1,26 @@ { - "title": "FIXME", + "title": "Single-method interface names should follow Go naming conventions", "type": "CODE_SMELL", "status": "ready", "remediation": { - "func": "Constant\/Issue", - "constantCost": "5min" + "func": "Constant/Issue", + "constantCost": "5 min" }, "tags": [ + "convention" ], - "defaultSeverity": "Major", + "defaultSeverity": "Blocker", "ruleSpecification": "RSPEC-8196", "sqKey": "S8196", "scope": "All", - "defaultQualityProfiles": ["Sonar way"], + "defaultQualityProfiles": [ + "Sonar way" + ], "quickfix": "unknown", "code": { "impacts": { - "MAINTAINABILITY": "HIGH", - "RELIABILITY": "MEDIUM", - "SECURITY": "LOW" + "MAINTAINABILITY": "BLOCKER" }, "attribute": "CONVENTIONAL" } -} +} \ No newline at end of file From 3d6c756ebcb982f801571101e7a19e17209cbe65 Mon Sep 17 00:00:00 2001 From: yassin-kammoun-sonarsouce Date: Wed, 29 Oct 2025 16:02:55 +0100 Subject: [PATCH 4/5] Update metadata --- rules/S8196/go/metadata.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/S8196/go/metadata.json b/rules/S8196/go/metadata.json index 2631014920b..068cdabbed1 100644 --- a/rules/S8196/go/metadata.json +++ b/rules/S8196/go/metadata.json @@ -9,7 +9,7 @@ "tags": [ "convention" ], - "defaultSeverity": "Blocker", + "defaultSeverity": "Minor", "ruleSpecification": "RSPEC-8196", "sqKey": "S8196", "scope": "All", @@ -19,8 +19,8 @@ "quickfix": "unknown", "code": { "impacts": { - "MAINTAINABILITY": "BLOCKER" + "MAINTAINABILITY": "LOW" }, "attribute": "CONVENTIONAL" } -} \ No newline at end of file +} From c66c3fc4440b5c87401beedc2ac36e6c49f1c62e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marichal?= Date: Mon, 3 Nov 2025 10:27:44 +0100 Subject: [PATCH 5/5] Update rule.adoc --- rules/S8196/go/rule.adoc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rules/S8196/go/rule.adoc b/rules/S8196/go/rule.adoc index 97fe82dbf80..a977a0978d8 100644 --- a/rules/S8196/go/rule.adoc +++ b/rules/S8196/go/rule.adoc @@ -36,7 +36,7 @@ type FileRead interface { [source,go,diff-id=1,diff-type=compliant] ---- -type Reader interface { +type FileReader interface { Read([]byte) (int, error) } ---- @@ -46,5 +46,3 @@ type Reader interface { === Documentation * Effective Go - Interface names - https://go.dev/doc/effective_go#interface-names[Official Go documentation explaining interface naming conventions] - - * Go Code Review Comments - Interface Names - https://github.com/golang/go/wiki/CodeReviewComments#interface-names[Go team's code review guidelines for interface naming]