Class: RuboCop::Cop::Rails::DuplicateScope

Inherits:
Base
  • Object
show all
Includes:
ClassSendNodeHelper
Defined in:
lib/rubocop/cop/rails/duplicate_scope.rb

Overview

Checks for multiple scopes in a model that have the same ‘where` clause. This often means you copy/pasted a scope, updated the name, and forgot to change the condition.

Examples:


# bad
scope :visible, -> { where(visible: true) }
scope :hidden, -> { where(visible: true) }

# good
scope :visible, -> { where(visible: true) }
scope :hidden, -> { where(visible: false) }

Constant Summary collapse

MSG =
'Multiple scopes share this same where clause.'

Instance Method Summary collapse

Methods included from ClassSendNodeHelper

#class_send_nodes

Instance Method Details

#on_class(class_node) ⇒ Object



28
29
30
31
32
# File 'lib/rubocop/cop/rails/duplicate_scope.rb', line 28

def on_class(class_node)
  offenses(class_node).each do |node|
    add_offense(node)
  end
end