Class: HamlLint::Linter::InstanceVariables

Inherits:
HamlLint::Linter show all
Includes:
HamlLint::LinterRegistry
Defined in:
lib/haml_lint/linter/instance_variables.rb

Overview

Checks for the presence of instance variables

Instance Attribute Summary

Attributes inherited from HamlLint::Linter

#lints

Instance Method Summary collapse

Methods included from HamlLint::LinterRegistry

extract_linters_from, included

Methods inherited from HamlLint::Linter

#initialize, #name, #run, #run_or_raise, supports_autocorrect?, #supports_autocorrect?

Methods included from HamlVisitor

#visit, #visit_children

Constructor Details

This class inherits a constructor from HamlLint::Linter

Instance Method Details

#visit_root(node) ⇒ true, false

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

Parameters:

Returns:

  • (true, false)

    whether the linter is enabled for the tree



12
13
14
# 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) ⇒ void Also known as: visit_silent_script

This method returns an undefined value.

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

Parameters:

  • (HamlLint::Tree:ScriptNode)


20
21
22
23
24
25
26
# 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

#visit_tag(node) ⇒ void

This method returns an undefined value.

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

Parameters:

  • (HamlLint::Tree:TagNode)


39
40
41
42
43
44
45
46
# 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