rspec/rules/S2681/tsql/rule.adoc

30 lines
937 B
Plaintext
Raw Normal View History

2020-06-30 12:48:07 +02:00
<code>BEGIN...END</code> can be omitted from a one-line block, such as with an <code>IF</code> statement or <code>WHILE</code> loop, but doing so can be misleading and induce bugs.
This rule raises an issue when the indentation of the lines after a one-line block indicates an intent to include those lines in the block, but the omission of <code>BEGIN...END</code> means the lines will be unconditionally executed once.
== Noncompliant Code Example
----
IF (0=1)
EXEC firstActionInBlock;
EXEC secondAction; -- Noncompliant; executed unconditionally
EXEC thirdAction;
IF (0=1) EXEC firstActionInBlock; EXEC secondAction; -- Noncompliant; secondAction executed unconditionally
IF (0=1) EXEC firstActionInBlock; -- Noncompliant
EXEC secondAction; -- Executed unconditionally
----
== Compliant Solution
----
IF (0=1) BEGIN
EXEC firstActionInBlock;
EXEC secondAction;
END
EXEC thirdAction;
----
include::../see.adoc[]