rspec/rules/S1871/tsql/exceptions.adoc
2023-10-24 12:02:02 +00:00

35 lines
915 B
Plaintext

=== Exceptions
Branches in an `IF`/`ELSE IF` chain with an implementation that contains a single line of code are ignored.
[source,sql]
----
IF @SortOrder = 1
BEGIN
SELECT LastName FROM Employees ORDER BY LastName
END
ELSE IF @SortOrder = 2
BEGIN
SELECT LastName FROM Employees
END
ELSE
BEGIN
SELECT LastName FROM Employees ORDER BY LastName -- No issue, usually this is done on purpose to increase the readability
END
GO
----
But this exception does not apply to `IF` chains without `ELSE`-s when all branches have the same single line of code. In the case of `IF` chains with `ELSE`-s rule S3923 raises a bug.
[source,sql]
----
IF @SortOrder = 1 -- Noncompliant, this might have been done on purpose but probably not
BEGIN
SELECT LastName FROM Employees ORDER BY LastName
END
ELSE IF @SortOrder = 2
BEGIN
SELECT LastName FROM Employees ORDER BY LastName
END
GO
----