class ERBLint::Linters::PartialInstanceVariable

Checks for instance variables in partials.

Public Instance Methods

run(processed_source) click to toggle source
# File lib/erb_lint/linters/partial_instance_variable.rb, line 9
def run(processed_source)
  instance_variable_regex = /\s@\w+/
  return unless processed_source.filename.match?(/.*_.*.erb\z/) &&
    processed_source.file_content.match?(instance_variable_regex)

  add_offense(
    processed_source.to_source_range(
      processed_source.file_content =~ instance_variable_regex..processed_source.file_content.size
    ),
    "Instance variable detected in partial."
  )
end