class RuboCop::Cop::Rails::HelperInstanceVariable


end
end
render Welcome.new(**)
def welcome(**)
end
end
@text = text
def initialize(text:)
class Welcome
module ButtonHelper
# good
end
“Hello #{user.name}”
def welcome_message(user)
# good
end
“Hello #{@user.name}”
def welcome_message
# bad
@example
an offense will not be registered.
Provided that an instance variable belongs to a class,
example to a model, decorator or presenter.
variable, consider moving the behavior elsewhere, for
If it seems awkward to explicitly pass in each dependent
methods.
Relying on instance variables makes it difficult to reuse helper
instance variables.
Checks for use of the helper methods which reference

def instance_variable_belongs_to_class?(node)

def instance_variable_belongs_to_class?(node)
  node.each_ancestor(:class).any?
end

def on_ivar(node)

def on_ivar(node)
  return if instance_variable_belongs_to_class?(node)
  add_offense(node)
end

def on_ivasgn(node)

def on_ivasgn(node)
  return if node.parent.or_asgn_type? || instance_variable_belongs_to_class?(node)
  add_offense(node.loc.name)
end