Sha256: c445747c3de1513fb1b92c7d523ffad43036f92d9ad83ebeea2a7e74e3873f2c

Contents?: true

Size: 776 Bytes

Versions: 4

Compression:

Stored size: 776 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Rails
      # This cop checks for scope calls where it was passed
      # a method (usually a scope) instead of a lambda/proc.
      #
      # @example
      #
      #   # bad
      #   scope :something, where(something: true)
      #
      #   # good
      #   scope :something, -> { where(something: true) }
      class ScopeArgs < Cop
        MSG = 'Use `lambda`/`proc` instead of a plain method call.'

        def on_send(node)
          return unless command?(:scope, node)

          _receiver, _method_name, *args = *node

          return unless args.size == 2

          second_arg = args[1]

          add_offense(second_arg, :expression) if second_arg.type == :send
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.22.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.21.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.20.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.20.0 lib/rubocop/cop/rails/scope_args.rb