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
Proposed solutions
Resolve auto-correctable file by letting RuboCop auto-correct them automatically
- Pick a file from The List below e.g.
app/models/clusters/cluster.rb
- Create a branch (e.g.
tl-rubocop-delegate-predicate-methods-clusters
) - Delete the file from
.rubocop_todo/gitlab/delegate_predicate_methods.yml
- 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
- Check changes files and adjust if needed
- Commit and create a merge request adding
Contributes to #324629
and static code analysis label - Tick off the checkbox(es) and add the MR or mention this merge request in this issue
🎉
The List
The following offences need to be fixed:
-
app/models/clusters/cluster.rb
- !65531 (merged) -
app/models/clusters/platforms/kubernetes.rb
- !76000 (merged) -
app/models/concerns/ci/metadatable.rb
- !58129 (closed) & !76001 (merged) -
app/models/concerns/diff_positionable_note.rb
- !76002 (merged) -
app/models/concerns/resolvable_discussion.rb
- !76003 (merged) -
app/models/concerns/integrations/base_data_fields.rb
- !89820 (merged) -
app/models/project.rb
- !90115 (merged) -
ee/app/models/concerns/ee/ci/metadatable.rb
- !91359 (merged) -
ee/app/models/ee/group.rb
- !76004 (merged) -
ee/app/models/ee/namespace.rb
- !76006 (merged) -
ee/app/models/ee/project.rb
- !56420 (merged) -
ee/app/models/license.rb
- !76007 (merged) -
lib/gitlab/ci/trace/stream.rb
- !76010 (merged)
Edited by Tan Le