Sha256: b63d873fa37e7185ac2f5eefc10e919fe9d88d3c8cbcdb67a12f270bbf11989a

Contents?: true

Size: 877 Bytes

Versions: 13

Compression:

Stored size: 877 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
        extend AutoCorrector

        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) do |corrector|
              corrector.replace(second_arg, "-> { #{second_arg.source} }")
            end
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-rails-2.14.2/lib/rubocop/cop/rails/scope_args.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-rails-2.14.2/lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.14.2 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.14.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.14.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.13.2 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.13.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.13.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.12.4 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.12.3 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.12.2 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.12.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-rails-2.12.0 lib/rubocop/cop/rails/scope_args.rb