2020-06-10 08:08:58 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
# Cop that blacklists the use of `default_scope`.
|
2022-09-14 11:12:56 -04:00
|
|
|
class DefaultScope < RuboCop::Cop::Base
|
2020-06-10 08:08:58 -04:00
|
|
|
MSG = <<~EOF
|
|
|
|
Do not use `default_scope`, as it does not follow the principle of
|
|
|
|
least surprise. See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/33847
|
|
|
|
for more details.
|
|
|
|
EOF
|
|
|
|
|
|
|
|
def_node_matcher :default_scope?, <<~PATTERN
|
|
|
|
(send {nil? (const nil? ...)} :default_scope ...)
|
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_send(node)
|
|
|
|
return unless default_scope?(node)
|
|
|
|
|
2022-09-14 11:12:56 -04:00
|
|
|
add_offense(node)
|
2020-06-10 08:08:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|