Skip to content

Files

Latest commit

 

History

History
31 lines (21 loc) · 621 Bytes

shift.md

File metadata and controls

31 lines (21 loc) · 621 Bytes

Pattern: Useless shift

Issue: -

Description

This rule checks if shift or shift-assign operations shift by more than the length of the underlying variable. Update variable type or shift count to make your intention and code more clear.

Example of incorrect code:

func ShiftTest() {
  var i8 int8
  _ = i8 >> 8    // i8 is too small for shift of 8
}

Example of correct code:

func ShiftTest() {
  var i8 int8
  _ = i8 << 7
}

Further Reading