rspec/rules/S3972/tsql/rule.adoc

53 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
Code is clearest when each statement has its own line. Nonetheless, it is a common pattern to combine on the same line an ``++IF++`` and its resulting _then_ statement. However, when an ``++IF++`` is placed on the same line as the closing ``++END++`` from a preceding ``++ELSE++`` or ``++ELSE IF++``, it is either an error - ``++ELSE++`` is missing - or the invitation to a future error as maintainers fail to understand that the two statements are unconnected.
2020-06-30 12:48:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,sql]
2020-06-30 12:48:39 +02:00
----
IF (condition1) BEGIN
EXEC something
END IF (condition2) BEGIN -- Noncompliant
EXEC something
END
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,sql]
2020-06-30 12:48:39 +02:00
----
IF (condition1) BEGIN
EXEC something
END ELSE IF (condition2) BEGIN
EXEC something
END
----
Or
2022-02-04 17:28:24 +01:00
[source,sql]
2020-06-30 12:48:39 +02:00
----
IF (condition1) BEGIN
EXEC something
END
IF (condition2) BEGIN
EXEC something
END
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]