News for hackers. Stuff that matters.
Re:My Beef with RuboCop by arto64 on Thursday November 19, 2020 @08:13AM (#25149115)
In his case, the guard clause is completely appropriate, because "super" is "the rest of the method" the guard clause is protecting. It's not a filter method, it's a selective render method.
Re:My Beef with RuboCop by ryanbrunner on Thursday November 19, 2020 @08:49AM (#25149376)
Sure, I can see that argument. But the larger point is that that can't be universally applied to every case that Rubocop flags.
Re:My Beef with RuboCop by WesolyKubeczek on Thursday November 19, 2020 @12:38PM (#25152001)
Then the author should have made their case with a more suitable example. I bet they could have found cases with something that's absolutely not a guard clause in a disguise getting converted into a guard clause proper.

Unless they couldn't, and the linter does a good job. ;-)

Re:My Beef with RuboCop by boyakasha on Friday November 20, 2020 @06:21AM (#25159380)
I literally hit two today. Off the top of my head:

    def enhance_payload(payload)
      payload[:h] = thing_h

      if situation_one?
        payload[:a] = thing_a
        payload[:b] = thing_b
      end

      if situation_two?
        payload[:x] = thing_x
        payload[:y] = thing_y
      end
    end
Which RuboCop suggests to turn into:

    def enhance_payload(payload)
      payload[:h] = thing_h

      if situation_one?
        payload[:a] = thing_a
        payload[:b] = thing_b
      end

      return unless situation_two?

      payload[:x] = thing_x
      payload[:y] = thing_y
    end
But if you move the first line of the method down to the be the last line, suddenly it's not important to use a guard clause anymore.

If you can't think of examples, then you haven't been doing much thinking.