Uploaded image for project: 'SonarSlang'
  1. SonarSlang
  2. SONARSLANG-247

FP S1125(BooleanLiteralCheck) "else if" chain and block

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: Rules
    • Labels:
      None
    • Estimate:
      Minutes

      Description

      The rule S1125 does not apply when the branch contains a block with several statements, Kotlin example:

              return if (attachment is AttachmentWithContext) {
                  val whitelist = attachment.whitelistedContractImplementations ?: throw IllegalStateException("Unable to verify WhitelistedByZoneAttachmentConstraint - whitelist not specified")
                  attachment.id in (whitelist[attachment.stateContract] ?: emptyList())
              } else false
      

      And when there's a chain of "if" / "else if", applying the S1125 recommendation create a more complex expression. S1125 should limit it's scope to "if" with 2 branches.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                alban.auzeill Alban Auzeill
                Reporter:
                alban.auzeill Alban Auzeill
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: