From 975c89fc3980bf947c9451124b48f587795f1624 Mon Sep 17 00:00:00 2001 From: sebastien-marichal Date: Wed, 18 Dec 2024 10:24:12 +0000 Subject: [PATCH 1/3] Create rule S7173 --- rules/S7173/metadata.json | 2 ++ rules/S7173/vb6/metadata.json | 25 ++++++++++++++++++++ rules/S7173/vb6/rule.adoc | 44 +++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 rules/S7173/metadata.json create mode 100644 rules/S7173/vb6/metadata.json create mode 100644 rules/S7173/vb6/rule.adoc diff --git a/rules/S7173/metadata.json b/rules/S7173/metadata.json new file mode 100644 index 00000000000..2c63c085104 --- /dev/null +++ b/rules/S7173/metadata.json @@ -0,0 +1,2 @@ +{ +} diff --git a/rules/S7173/vb6/metadata.json b/rules/S7173/vb6/metadata.json new file mode 100644 index 00000000000..0a4321d5a28 --- /dev/null +++ b/rules/S7173/vb6/metadata.json @@ -0,0 +1,25 @@ +{ + "title": "FIXME", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "5min" + }, + "tags": [ + ], + "defaultSeverity": "Major", + "ruleSpecification": "RSPEC-7173", + "sqKey": "S7173", + "scope": "All", + "defaultQualityProfiles": ["Sonar way"], + "quickfix": "unknown", + "code": { + "impacts": { + "MAINTAINABILITY": "HIGH", + "RELIABILITY": "MEDIUM", + "SECURITY": "LOW" + }, + "attribute": "CONVENTIONAL" + } +} diff --git a/rules/S7173/vb6/rule.adoc b/rules/S7173/vb6/rule.adoc new file mode 100644 index 00000000000..70626f3be4c --- /dev/null +++ b/rules/S7173/vb6/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,vb6,diff-id=1,diff-type=noncompliant] +---- +FIXME +---- + +==== Compliant solution + +[source,vb6,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 From 05cc2bedc1acef8c8d8131c68be7d7646b694cd9 Mon Sep 17 00:00:00 2001 From: Sebastien Marichal Date: Wed, 18 Dec 2024 11:43:24 +0100 Subject: [PATCH 2/3] Add description --- rules/S7173/vb6/metadata.json | 13 +++++----- rules/S7173/vb6/rule.adoc | 47 +++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/rules/S7173/vb6/metadata.json b/rules/S7173/vb6/metadata.json index 0a4321d5a28..b5ce6dbd588 100644 --- a/rules/S7173/vb6/metadata.json +++ b/rules/S7173/vb6/metadata.json @@ -1,25 +1,24 @@ { - "title": "FIXME", + "title": "\"GoSub\" statements should not be used", "type": "CODE_SMELL", "status": "ready", "remediation": { "func": "Constant\/Issue", - "constantCost": "5min" + "constantCost": "10min" }, "tags": [ + "brain-overload" ], "defaultSeverity": "Major", "ruleSpecification": "RSPEC-7173", "sqKey": "S7173", "scope": "All", "defaultQualityProfiles": ["Sonar way"], - "quickfix": "unknown", + "quickfix": "infeasible", "code": { "impacts": { - "MAINTAINABILITY": "HIGH", - "RELIABILITY": "MEDIUM", - "SECURITY": "LOW" + "MAINTAINABILITY": "MEDIUM" }, - "attribute": "CONVENTIONAL" + "attribute": "CLEAR" } } diff --git a/rules/S7173/vb6/rule.adoc b/rules/S7173/vb6/rule.adoc index 70626f3be4c..d2b6d47ea81 100644 --- a/rules/S7173/vb6/rule.adoc +++ b/rules/S7173/vb6/rule.adoc @@ -1,16 +1,16 @@ -FIXME: add a description +== Why is this an issue? -// If you want to factorize the description uncomment the following line and create the file. -//include::../description.adoc[] +The `GoSub` statement in VB6 is an unstructured control flow statement. It can lead to complex and difficult-to-maintain code, as well as potential stack overflow errors due to improper return handling. -== Why is this an issue? +Modern programming practices recommend using proper subroutine or function calls instead, which provide better readability, maintainability, and error handling. -FIXME: remove the unused optional headers (that are commented out) +=== Exceptions -//=== What is the potential impact? +`On Error GoSub` statements are ignored as correct error handling. == How to fix it -//== How to fix it in FRAMEWORK NAME + +Replace `GoSub` statements with proper subroutine or function calls. === Code examples @@ -18,27 +18,30 @@ FIXME: remove the unused optional headers (that are commented out) [source,vb6,diff-id=1,diff-type=noncompliant] ---- -FIXME +Sub ExampleProcedure() + GoSub SubRoutine + Exit Sub + +SubRoutine: + ' ... + Return +End Sub ---- ==== Compliant solution [source,vb6,diff-id=1,diff-type=compliant] ---- -FIXME ----- +Sub ExampleProcedure() + Call SubRoutine +End Sub -//=== How does this work? - -//=== Pitfalls - -//=== Going the extra mile +Sub SubRoutine() + ' ... +End Sub +---- +== Resources +=== Documentation -//== Resources -//=== Documentation -//=== Articles & blog posts -//=== Conference presentations -//=== Standards -//=== External coding guidelines -//=== Benchmarks +* Microsoft Learn - https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/gosubreturn-statement[GoSub...Return statement] From 03a644bbe0874c60a2005940102a614d55311643 Mon Sep 17 00:00:00 2001 From: Sebastien Marichal Date: Wed, 18 Dec 2024 16:14:55 +0100 Subject: [PATCH 3/3] Remove exceptions section --- rules/S7173/vb6/rule.adoc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rules/S7173/vb6/rule.adoc b/rules/S7173/vb6/rule.adoc index d2b6d47ea81..bbfd41bc885 100644 --- a/rules/S7173/vb6/rule.adoc +++ b/rules/S7173/vb6/rule.adoc @@ -4,10 +4,6 @@ The `GoSub` statement in VB6 is an unstructured control flow statement. It can l Modern programming practices recommend using proper subroutine or function calls instead, which provide better readability, maintainability, and error handling. -=== Exceptions - -`On Error GoSub` statements are ignored as correct error handling. - == How to fix it Replace `GoSub` statements with proper subroutine or function calls.