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

"break" should be the only statement in a "case"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Remove this extraneous "break".
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Default Quality Profiles:
      Sonar way
    • Covered Languages:
      Swift, VB.Net
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min

      Description

      Because case statements in a Swift switch do not fall through, there is no need to use break at the end of a case unless it would otherwise be empty. Since an empty case isn't allowed, an explicit break is needed to make such code compilable. There is no other reason to use break in a case.

      Noncompliant Code Example

      switch weekday {
        case sunday:
          break
        case monday:
          getUpEarly()
          break  // Noncompliant
        case tuesday
          // ...
      }
      

      Compliant Solution

      switch weekday {
        case sunday:
          break
        case monday:
          getUpEarly()
        case tuesday
          // ...
      }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: