Sha256: 8ff423660de71d4428438152f0f11764dc33f8e67a7353ebb09870849203b90e

Contents?: true

Size: 813 Bytes

Versions: 3

Compression:

Stored size: 813 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Rails
      # This cop checks for default_scope calls when it was passed
      # a lambda or a proc instead of a block.
      #
      # @example
      #
      #   # incorrect
      #   default_scope -> { something }
      #
      #   # correct
      #   default_scope { something }
      class DefaultScope < Cop
        MSG = 'default_scope expects a block as its sole argument.'

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

          _receiver, _method_name, *args = *node

          return unless args.size == 1

          first_arg = args[0]

          if first_arg.type != :block || lambda_or_proc?(first_arg)
            add_offence(first_arg, :expression)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.18.1 lib/rubocop/cop/rails/default_scope.rb
rubocop-0.18.0 lib/rubocop/cop/rails/default_scope.rb
rubocop-0.17.0 lib/rubocop/cop/rails/default_scope.rb