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

This commit is contained in:
github-actions[bot] 2024-12-20 09:11:58 +00:00 committed by GitHub
parent 5adea709d2
commit 98e58e1e76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,2 @@
{
}

View File

@ -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
rules/S7173/vb6/rule.adoc Normal file
View File

@ -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]