Sha256: 39d24cc9936eade9a884a627e009647cf7f345c5b2a6b3d8aa81f906c622cfa6

Contents?: true

Size: 715 Bytes

Versions: 14

Compression:

Stored size: 715 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_node_matcher :scope?, '(send nil :scope _ $send)'

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

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/rails/scope_args.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/rails/scope_args.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/rails/scope_args.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/rails/scope_args.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/rails/scope_args.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/rails/scope_args.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/rails/scope_args.rb
rubocop-0.49.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.49.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.48.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.48.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.47.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.47.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.46.0 lib/rubocop/cop/rails/scope_args.rb