Class: HamlLint::Linter::RuboCop

Inherits:
HamlLint::Linter show all
Includes:
HamlLint::LinterRegistry
Defined in:
lib/haml_lint/linter/rubocop.rb

Overview

Runs RuboCop on Ruby code contained within HAML templates.

Constant Summary collapse

SEVERITY_MAP =

Maps the ::RuboCop::Cop::Severity levels to our own levels.

{
  error: :error,
  fatal: :error,

  convention: :warning,
  refactor: :warning,
  warning: :warning,
}.freeze

Instance Attribute Summary

Attributes inherited from HamlLint::Linter

#lints

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HamlLint::LinterRegistry

extract_linters_from, included

Methods inherited from HamlLint::Linter

#initialize, #name, #run

Methods included from HamlVisitor

#visit, #visit_children

Constructor Details

This class inherits a constructor from HamlLint::Linter

Class Method Details

.rubocop_cliObject

A single CLI instance is shared between files to avoid RuboCop having to repeatedly reload .rubocop.yml.



32
33
34
35
36
# File 'lib/haml_lint/linter/rubocop.rb', line 32

def self.rubocop_cli
  # The ivar is stored on the class singleton rather than the Linter instance
  # because it can't be Marshal.dump'd (as used by Parallel.map)
  @rubocop_cli ||= ::RuboCop::CLI.new
end

Instance Method Details

#visit_root(_node) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/haml_lint/linter/rubocop.rb', line 21

def visit_root(_node)
  extractor = HamlLint::RubyExtractor.new
  extracted_source = extractor.extract(document)

  return if extracted_source.source.empty?

  find_lints(extracted_source.source, extracted_source.source_map)
end