简体   繁体   中英

Reek error RepeatedConditional

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?

Will an alias work?

alias :right :left
alias :move_forward :left

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM