Add cop to disallow delegating predicate methods
This cop looks for delegations to predicate methods with `allow_nil` option. When delegating with this option enabled, we ends up with true, false and nil and this does not preserve the boolean nature of predicate methods. The preferred implementation is to define a method to handle `nil` and returns the correct Boolean value instead. delegate :is_foo?, to: :bar, allow_nil: true def is_foo? return false unless bar bar.is_foo? end def is_foo? !!bar&.is_foo? end
Showing
Please register or sign in to comment