S3358 — If operators should not be nested

Language
VB.NET
Type
Code smell
Severity
Major
Tags
confusing

Why is this an issue?

Nested ternaries are hard to read and can make the order of operations complex to understand.


Public Function GetReadableStatus(job As Job) As String
    Return If(job.IsRunning, "Running", If(job.HasErrors, "Failed", "Succeeded")) ' Noncompliant
End Function

Instead, use another line to express the nested operation in a separate statement.


Public Function GetReadableStatus(job As Job) As String
    If job.IsRunning Then Return "Running"
    Return If(job.HasErrors, "Failed", "Succeeded")
End Function

↑ Back to top