Class: ERBLint::Linters::PartialInstanceVariable

Inherits:
ERBLint::Linter show all
Includes:
ERBLint::LinterRegistry
Defined in:
lib/erb_lint/linters/partial_instance_variable.rb

Overview

Checks for instance variables in partials.

Constant Summary

Constants included from ERBLint::LinterRegistry

ERBLint::LinterRegistry::CUSTOM_LINTERS_DIR

Instance Attribute Summary

Attributes inherited from ERBLint::Linter

#offenses

Instance Method Summary collapse

Methods included from ERBLint::LinterRegistry

clear, find_by_name, included, linters, load_custom_linters

Methods inherited from ERBLint::Linter

#add_offense, #clear_offenses, #enabled?, #excludes_file?, inherited, #initialize, support_autocorrect?

Constructor Details

This class inherits a constructor from ERBLint::Linter

Instance Method Details

#run(processed_source) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# 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