2

I have below error:

  tests @action.placed.!=(true) at least 3 times (RepeatedConditional)

Generated from below code:

    def left
        super unless @action.placed != true
    end

    def right
        super unless @action.placed != true
    end

    def move_forward
        super unless @action.placed != true
    end

How would we get rid of this repeat?

Zippie
  • 6,018
  • 6
  • 31
  • 46
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168

2 Answers2

0

Will an alias work?

alias :right :left
alias :move_forward :left
kristianp
  • 5,496
  • 37
  • 56
  • alias is not quite the same as the code he has. Thought the code looks similar, the call to super is calling a different method – Geoff Lee Mar 10 '18 at 20:22
0

I think this explains it best: https://github.com/troessner/reek/blob/master/lib/reek/report/code_climate/code_climate_configuration.yml#L619. Because your object is checking the same condition multiple times, it is probably assuming the role of 2 objects and is missing an abstraction.

The solution may be creating 2 classes, one where @action.placed is always true and one where it is not always true. Another could be moving the logic up. Or maybe just combining these methods into 1. Ideally the goal would be to only have to check that condition once.

Geoff Lee
  • 144
  • 6