Sha256: 45784bc4f33c96487ab27db9d4716c6130c76c2f2d3013879ea9b31e18036a87

Contents?: true

Size: 812 Bytes

Versions: 13

Compression:

Stored size: 812 Bytes

Contents

# encoding: utf-8
# 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]

          add_offense(second_arg, :expression) if second_arg.type == :send
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/rails/scope_args.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/rails/scope_args.rb
rubocop-0.42.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.41.2 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.41.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.41.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.40.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.39.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.38.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.37.2 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.37.1 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.37.0 lib/rubocop/cop/rails/scope_args.rb
rubocop-0.36.0 lib/rubocop/cop/rails/scope_args.rb