Sha256: 86da3b9d0a369d7714f7fe7d60d682db82438b949dbd96e4e73ff0bf0e7b0894

Contents?: true

Size: 741 Bytes

Versions: 8

Compression:

Stored size: 741 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 < Base
        MSG = 'Use `lambda`/`proc` instead of a plain method call.'
        RESTRICT_ON_SEND = %i[scope].freeze

        def_node_matcher :scope?, '(send nil? :scope _ $send)'

        def on_send(node)
          scope?(node) do |second_arg|
            add_offense(second_arg)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rubocop-rails-2.11.3 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.11.2 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.11.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.11.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.10.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.10.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.9.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.9.0 lib/rubocop/cop/rails/scope_args.rb