Skip to content

Fix cop remaining cop offenses for Gitlab/DelegatePredicateMethods

Problem

In !54658 (merged), we've introduced a new 👮 Gitlab/DelegatePredicateMethods to discourage delegation of predicate methods with allow_nil: true.

This MR enabled the 👮 so new offences are prevented. Current offences still need to be fixed. This issue tracks its progress.

Proposed solutions

Resolve auto-correctable file by letting RuboCop auto-correct them automatically 🎉

  1. Pick a file from The List below e.g. app/models/clusters/cluster.rb
  2. Create a branch (e.g. tl-rubocop-delegate-predicate-methods-clusters)
  3. Delete the file from .rubocop_todo/gitlab/delegate_predicate_methods.yml
  4. Use the suggested changes below
# Option 1
def is_foo?
  return false unless bar
  bar.is_foo?
end

# Option 2
def is_foo?
  !!bar&.is_foo?
end

# WARNING: Some methods also take arguments, we need to pass them on too:
def feature_available?(feature)
  !!namespace&.feature_available?(feature)
end
  1. Check changes files and adjust if needed
  2. Commit and create a merge request adding Contributes to #324629 and static code analysis label
  3. Tick off the checkbox(es) and add the MR or mention this merge request in this issue
  4. 🎉

The List

The following offences need to be fixed:

Edited by Tan Le