rspec/rules/S2539/plsql/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

48 lines
942 B
Plaintext

== Why is this an issue?
In a CREATE PACKAGE BODY, the purpose of the initialization section is to set the initial values of the package's global variables. It is therefore surprising to find a RETURN statement there, as all its following statements will be unreachable.
=== Noncompliant code example
[source,sql]
----
SET SERVEROUTPUT ON
CREATE OR REPLACE PACKAGE foo AS
FUNCTION getBar RETURN PLS_INTEGER;
bar PLS_INTEGER;
END;
/
CREATE OR REPLACE PACKAGE BODY foo AS
FUNCTION getBar RETURN PLS_INTEGER AS
BEGIN
RETURN bar; -- Compliant
END;
BEGIN
bar := 42;
DBMS_OUTPUT.PUT_LINE('package loaded');
RETURN; -- Noncompliant
DBMS_OUTPUT.PUT_LINE('this is unreachable code');
END;
/
DROP PACKAGE BODY foo;
DROP PACKAGE foo;
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this "RETURN" statement.
endif::env-github,rspecator-view[]