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

"switch" statements should have "default" clauses

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Add a "[case default|WHEN OTHERS|Case Else]" clause to this "[switch|CASE|Select]" statement.
    • Default Severity:
      Critical
    • Impact:
      High
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      switch-without-default, SwitchWithoutDefault, SwitchLastCaseIsDefaultCheck, SelectWithoutCaseElse, SelectWithoutOtherwise, COBOL.EvaluateStatementUsageCheck
    • Targeted languages:
      RPG, TypeScript
    • Covered Languages:
      ABAP, C#, C, C++, Cobol, Flex, Go, Java, JavaScript, Objective-C, PHP, PL/I, PL/SQL, Ruby, T-SQL, VB.Net, VB6
    • Irrelevant for Languages:
      HTML, Kotlin, Python, Swift, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Common Rule:
      Yes
    • CERT:
      MSC01-C.
    • CWE:
      CWE-478
    • Checkstyle:
      DefaultComesLast, MissingSwitchDefault
    • ESLint:
      default-case
    • FindBugs:
      SF_SWITCH_NO_DEFAULT
    • PC-Lint:
      744, 1744, 9014, 9082
    • PMD:
      DefaultLabelNotLastInSwitchStmt,SwitchStmtsShouldHaveDefault

      Description

      The requirement for a final default clause is defensive programming. The clause should either take appropriate action, or contain a suitable comment as to why no action is taken.

      See

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated: