Sha256: 9ac01d4394297c187c6441ebb3767c9d6e0776b182002516e06d72f6b4337de6

Contents?: true

Size: 1.08 KB

Versions: 6871

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Rails
      # This cop checks if the value of the option `class_name`, in
      # the definition of a reflection is a string.
      #
      # @example
      #   # bad
      #   has_many :accounts, class_name: Account
      #   has_many :accounts, class_name: Account.name
      #
      #   # good
      #   has_many :accounts, class_name: 'Account'
      class ReflectionClassName < Cop
        MSG = 'Use a string value for `class_name`.'.freeze

        def_node_matcher :association_with_options?, <<-PATTERN
          (send nil? {:has_many :has_one :belongs_to} _ (hash $...))
        PATTERN

        def_node_search :reflection_class_name, <<-PATTERN
          (pair (sym :class_name) [!str !sym])
        PATTERN

        def on_send(node)
          return unless association_with_options?(node)

          reflection_class_name = reflection_class_name(node).first
          return unless reflection_class_name

          add_offense(node, location: reflection_class_name.loc.expression)
        end
      end
    end
  end
end

Version data entries

6,871 entries across 6,867 versions & 24 rubygems

Version Path
ory-client-0.0.1.alpha84 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha83 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha82 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha81 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha80 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha79 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha78 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha77 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha76 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha75 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha74 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha73 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha72 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha71 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha70 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha69 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha68 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha67 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-client-0.0.1.alpha66 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb
ory-oathkeeper-client-0.38.19.beta1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cop/rails/reflection_class_name.rb