Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-126

"if ... else if" constructs should end with "else" clauses

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Add the missing "[else|ELSE]" clause.
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Legacy Key:
      missing-else-clause, ElseIfWithoutElse
    • Targeted languages:
      APEX, Cobol, Flex, PL/I, Python, TypeScript, VB6
    • Covered Languages:
      ABAP, C#, C, C++, Go, Java, JavaScript, Kotlin, Objective-C, PHP, PL/SQL, RPG, Ruby, Scala, Swift, T-SQL, VB.Net
    • Irrelevant for Languages:
      HTML, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Common Rule:
      Yes
    • CERT:
      MSC01-C., MSC57-J.
    • PC-Lint:
      9013

      Description

      This rule applies whenever an if statement is followed by one or more else if statements; the final else if should be followed by an else statement.

      The requirement for a final else statement is defensive programming.
      The else statement should either take appropriate action or contain a suitable comment as to why no action is taken. This is consistent with the requirement to have a final default clause in a switch statement.

      See

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                freddy.mallet Freddy Mallet (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: