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

clear, find_by_name, included, linters, 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.



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

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
# File 'lib/erb_lint/linters/rubocop.rb', line 38

def autocorrect(_processed_source, offense)
  return unless offense.context
  rubocop_correction = offense.context[:rubocop_correction]
  return unless rubocop_correction

  lambda do |corrector|
    corrector.import!(rubocop_correction, offset: offense.context[:offset])
  end
end

#run(processed_source) ⇒ Object



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

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