Sha256: 802e2233962d13f0388f3331292652d23919bf5278294a43174c77d0750e4829

Contents?: true

Size: 813 Bytes

Versions: 3

Compression:

Stored size: 813 Bytes

Contents

# frozen_string_literal: true

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.'.freeze

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

          _receiver, _method_name, *args = *node

          return unless args.size == 2

          second_arg = args[1]

          return unless second_arg.send_type?

          add_offense(second_arg, :expression)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.45.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.44.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.44.0 lib/rubocop/cop/rails/scope_args.rb