Skip to content

Files

Latest commit

 

History

History
51 lines (39 loc) · 1.08 KB

FallThrough.md

File metadata and controls

51 lines (39 loc) · 1.08 KB

Pattern: Fall-through in switch statement

Issue: -

Description

This rule enforces convention to comment any fall-throughs (multiple case statements before termination) in switch block. Any of the following comments that communicate the idea of fall-through is sufficient: fallthru, fall through, fallthrough, falls through and fallsthrough (case sensitive).

Default configuration

<module name="FallThrough"/>

Examples

Example of incorrect code:

switch (input) {
  case 1:
  case 2:
    prepareOneOrTwo();
  case 3:
    handleOneTwoOrThree();
    break;
  default:
    handleLargeNumber(input);
}

Example of correct code:

switch (input) {
  case 1:
  case 2:
    prepareOneOrTwo();
    // fall through
  case 3:
    handleOneTwoOrThree();
    break;
  default:
    handleLargeNumber(input);
}

Further Reading