Sha256: 59dff2614939885670cfd660e47258f49b18fa032c5be1683c7ac948e0edb769

Contents?: true

Size: 968 Bytes

Versions: 17

Compression:

Stored size: 968 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Rails
      # This cop checks for use of the helper methods which reference
      # instance variables.
      #
      # Relying on instance variables makes it difficult to re-use helper
      # methods.
      #
      # If it seems awkward to explicitly pass in each dependent
      # variable, consider moving the behaviour elsewhere, for
      # example to a model, decorator or presenter.
      #
      # @example
      #   # bad
      #   def welcome_message
      #     "Hello #{@user.name}"
      #   end
      #
      #   # good
      #   def welcome_message(user)
      #     "Hello #{user.name}"
      #   end
      class HelperInstanceVariable < Cop
        MSG = 'Do not use instance variables in helpers.'

        def on_ivar(node)
          add_offense(node)
        end

        def on_ivasgn(node)
          add_offense(node, location: :name)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rubocop-rails-2.7.1 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.7.0 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.6.0 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.5.2 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.5.1 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.5.0 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.4.2 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.4.1 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.4.0 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.3.2 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.3.1 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.3.0 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.2.1 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.2.0 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.1.0 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.0.1 lib/rubocop/cop/rails/helper_instance_variable.rb
rubocop-rails-2.0.0 lib/rubocop/cop/rails/helper_instance_variable.rb