class HamlLint::Linter::InstanceVariables
Checks for the presence of instance variables
Attributes
Tracks whether the linter is enabled for the file.
@api private @return [true, false]
Tracks whether the linter is enabled for the file.
@api private @return [true, false]
Public Instance Methods
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
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
@!method visit_silent_script
(node)
Checks for instance variables in script nodes when the linter is enabled. @param [HamlLint::Tree:SilentScriptNode] @return [void]
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
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
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