Update ActiveRecord cop to be more permissive outside presenters/serializers

What does this MR do?

This MR updates the CodeReuse/ActiveRecord cop to apply different levels of restrictions based on file type:

  • Presenters and Serializers: All current restrictions apply (strict mode)
  • Other files: Only restrict find_by, find_by!, and find_by_sql

Why?

Following the discussion in gitlab-org/gitlab!215048 (comment 2931423504), this change makes the cop more targeted and reduces false positives while still preventing the most problematic ActiveRecord method usage outside of models.

The rationale is that presenters and serializers should have stricter rules to prevent N+1 queries and performance issues, while other files can use most ActiveRecord methods with only the most dangerous query methods restricted.

Related to: gitlab-org/gitlab!215048 (comment 2931423504)

Merge request reports

Loading