Class: ERBLint::Linters::Rubocop

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

Overview

Run selected rubocop cops on Ruby code

Direct Known Subclasses

RubocopText

Defined Under Namespace

Classes: ConfigSchema

Constant Summary collapse

SUFFIX_EXPR =
/[[:blank:]]*\Z/
BLOCK_EXPR =

copied from Rails: action_view/template/handlers/erb/erubi.rb

/\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/

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

find_by_name, included, load_custom_linters

Methods inherited from ERBLint::Linter

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

Constructor Details

#initialize(file_loader, config) ⇒ Rubocop

Returns a new instance of Rubocop.



25
26
27
28
29
30
# File 'lib/erb_lint/linters/rubocop.rb', line 25

def initialize(file_loader, config)
  super
  @only_cops = @config.only
  custom_config = config_from_hash(@config.rubocop_config)
  @rubocop_config = RuboCop::ConfigLoader.merge_with_default(custom_config, '')
end

Instance Method Details

#autocorrect(processed_source, offense) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/erb_lint/linters/rubocop.rb', line 38

def autocorrect(processed_source, offense)
  return unless offense.context

  lambda do |corrector|
    passthrough = Utils::OffsetCorrector.new(
      processed_source,
      corrector,
      offense.context[:offset],
      offense.context[:bound_range],
    )
    offense.context[:rubocop_correction].call(passthrough)
  end
end

#run(processed_source) ⇒ Object



32
33
34
35
36
# File 'lib/erb_lint/linters/rubocop.rb', line 32

def run(processed_source)
  descendant_nodes(processed_source).each do |erb_node|
    inspect_content(processed_source, erb_node)
  end
end