Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create rule S7173: "GoSub" statements should not be used #4580

Merged
merged 5 commits into from
Dec 20, 2024
Merged
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
2 changes: 2 additions & 0 deletions rules/S7173/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
24 changes: 24 additions & 0 deletions rules/S7173/vb6/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"title": "\"GoSub\" statements should not be used",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "10min"
},
"tags": [
"brain-overload"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-7173",
"sqKey": "S7173",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "infeasible",
"code": {
"impacts": {
"MAINTAINABILITY": "MEDIUM"
},
"attribute": "CLEAR"
}
}
43 changes: 43 additions & 0 deletions rules/S7173/vb6/rule.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
== Why is this an issue?

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.

Modern programming practices recommend using proper subroutine or function calls instead, which provide better readability, maintainability, and error handling.

== How to fix it

Replace `GoSub` statements with proper subroutine or function calls.

=== Code examples

==== Noncompliant code example

[source,vb6,diff-id=1,diff-type=noncompliant]
----
Sub ExampleProcedure()
GoSub SubRoutine
Exit Sub

SubRoutine:
' ...
Return
End Sub
----

==== Compliant solution

[source,vb6,diff-id=1,diff-type=compliant]
----
Sub ExampleProcedure()
Call SubRoutine
End Sub

Sub SubRoutine()
' ...
End Sub
----

== Resources
=== Documentation

* Microsoft Learn - https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/gosubreturn-statement[GoSub...Return statement]
Loading