Sha256: 43019da460c434cfcbc0259a854aecf8fad2d9682e20b6b842035ad87e36f3d6

Contents?: true

Size: 1 KB

Versions: 37

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Rails
      # Looks for delegations that pass :allow_blank as an option
      # instead of :allow_nil. :allow_blank is not a valid option to pass
      # to ActiveSupport#delegate.
      #
      # @example
      #   # bad
      #   delegate :foo, to: :bar, allow_blank: true
      #
      #   # good
      #   delegate :foo, to: :bar, allow_nil: true
      class DelegateAllowBlank < Base
        extend AutoCorrector

        MSG = '`allow_blank` is not a valid option, use `allow_nil`.'
        RESTRICT_ON_SEND = %i[delegate].freeze

        def_node_matcher :allow_blank_option, <<~PATTERN
          (send nil? :delegate _ (hash <$(pair (sym :allow_blank) true) ...>))
        PATTERN

        def on_send(node)
          return unless (offending_node = allow_blank_option(node))

          add_offense(offending_node) do |corrector|
            corrector.replace(offending_node.key, 'allow_nil')
          end
        end
      end
    end
  end
end

Version data entries

37 entries across 36 versions & 7 rubygems

Version Path
rubocop-rails-2.30.3 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.30.2 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.30.1 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.30.0 lib/rubocop/cop/rails/delegate_allow_blank.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-rails-2.29.1/lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.29.1 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.29.0 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.28.0 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.27.0 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.26.2 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.26.1 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.26.0 lib/rubocop/cop/rails/delegate_allow_blank.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.25.1/lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.25.1 lib/rubocop/cop/rails/delegate_allow_blank.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-rails-2.25.0/lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.24.1 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.24.0 lib/rubocop/cop/rails/delegate_allow_blank.rb
mlh-rubocop-config-1.0.3 vendor/bundle/ruby/3.2.0/gems/rubocop-rails-2.23.1/lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.23.1 lib/rubocop/cop/rails/delegate_allow_blank.rb
rubocop-rails-2.23.0 lib/rubocop/cop/rails/delegate_allow_blank.rb