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.

Instance Attribute Summary

Attributes inherited from HamlLint::Linter

#lints, #parser

Instance Method Summary collapse

Methods included from HamlLint::LinterRegistry

extract_linters_from, included

Methods inherited from HamlLint::Linter

#name

Methods included from HamlVisitor

#visit, #visit_children

Constructor Details

#initialize(config) ⇒ RuboCop

Returns a new instance of RuboCop.


10
11
12
13
14
# File 'lib/haml_lint/linter/rubocop.rb', line 10

def initialize(config)
  super
  @rubocop = ::RuboCop::CLI.new
  @ignored_cops = Array(config['ignored_cops']).flatten
end

Instance Method Details

#run(parser) ⇒ Object


16
17
18
19
20
21
22
23
# File 'lib/haml_lint/linter/rubocop.rb', line 16

def run(parser)
  @parser = parser
  @extractor = ScriptExtractor.new(parser)
  extracted_code = @extractor.extract.strip

  # Ensure a final newline in the code we feed to RuboCop
  find_lints(extracted_code + "\n") unless extracted_code.empty?
end