class HamlLint::Linter::InstanceVariables

Checks for the presence of instance variables

Attributes

enabled[R]

Tracks whether the linter is enabled for the file.

@api private @return [true, false]

enabled?[R]

Tracks whether the linter is enabled for the file.

@api private @return [true, false]

Public Instance Methods

visit_root(node) click to toggle source

Enables the linter if the tree is for the right file type.

@param [HamlLint::Tree::RootNode] the root of a syntax tree @return [true, false] whether the linter is enabled for the tree

# File lib/haml_lint/linter/instance_variables.rb, line 12
def visit_root(node)
  @enabled = matcher.match(File.basename(node.file)) ? true : false
end
visit_script(node) click to toggle source

Checks for instance variables in script nodes when the linter is enabled.

@param [HamlLint::Tree:ScriptNode] @return [void]

# File lib/haml_lint/linter/instance_variables.rb, line 20
def visit_script(node)
  return unless enabled?

  if node.parsed_script.contains_instance_variables?
    record_lint(node, "Avoid using instance variables in #{file_types} views")
  end
end
Also aliased as: visit_silent_script
visit_silent_script(node)

@!method visit_silent_script(node)

Checks for instance variables in script nodes when the linter is enabled.

@param [HamlLint::Tree:SilentScriptNode]
@return [void]
Alias for: visit_script
visit_tag(node) click to toggle source

Checks for instance variables in tag nodes when the linter is enabled.

@param [HamlLint::Tree:TagNode] @return [void]

# File lib/haml_lint/linter/instance_variables.rb, line 39
def visit_tag(node)
  return unless enabled?

  visit_script(node) ||
    if node.parsed_attributes.contains_instance_variables?
      record_lint(node, "Avoid using instance variables in #{file_types} views")
    end
end

Private Instance Methods

file_types() click to toggle source

The type of files the linter is configured to check.

@api private @return [String]

# File lib/haml_lint/linter/instance_variables.rb, line 67
def file_types
  @file_types ||= config['file_types'] || 'partial'
end
matcher() click to toggle source

The matcher to use for testing whether to check a file by file name.

@api private @return [Regexp]

# File lib/haml_lint/linter/instance_variables.rb, line 75
def matcher
  @matcher ||= Regexp.new(config['matchers'][file_types] || '\A_.*\.haml\z')
end