Class: Standard::Lsp::StdinRubocopRunner

Inherits:
RuboCop::Runner
  • Object
show all
Defined in:
lib/standard/lsp/stdin_rubocop_runner.rb

Overview

Defined Under Namespace

Classes: ConfigurationError

Constant Summary collapse

DEFAULT_RUBOCOP_OPTIONS =
{
  stderr: true,
  force_exclusion: true,
  formatters: ["RuboCop::Formatter::BaseFormatter"],
  raise_cop_error: true,
  todo_file: nil,
  todo_ignore_files: []
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ StdinRubocopRunner

Returns a new instance of StdinRubocopRunner.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/standard/lsp/stdin_rubocop_runner.rb', line 21

def initialize(config)
  @options = {}
  @offenses = []
  @errors = []
  @warnings = []

  @config_for_working_directory = config.rubocop_config_store.for_pwd

  super(
    config.rubocop_options.merge(DEFAULT_RUBOCOP_OPTIONS),
    config.rubocop_config_store
  )
end

Instance Attribute Details

#config_for_working_directoryObject (readonly)

Returns the value of attribute config_for_working_directory.



10
11
12
# File 'lib/standard/lsp/stdin_rubocop_runner.rb', line 10

def config_for_working_directory
  @config_for_working_directory
end

#offensesObject (readonly)

Returns the value of attribute offenses.



8
9
10
# File 'lib/standard/lsp/stdin_rubocop_runner.rb', line 8

def offenses
  @offenses
end

Instance Method Details

#formatted_sourceObject



60
61
62
# File 'lib/standard/lsp/stdin_rubocop_runner.rb', line 60

def formatted_source
  @options[:stdin]
end

#run(path, contents) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/standard/lsp/stdin_rubocop_runner.rb', line 35

def run(path, contents)
  @errors = []
  @warnings = []
  @offenses = []
  @options[:stdin] = contents

  super([path])

  raise Interrupt if aborting?
rescue ::RuboCop::Runner::InfiniteCorrectionLoop => error
  if defined?(::RubyLsp::Requests::Formatting::Error)
    raise ::RubyLsp::Requests::Formatting::Error, error.message
  else
    raise error
  end
rescue ::RuboCop::ValidationError => error
  raise ConfigurationError, error.message
rescue => error
  if defined?(::RubyLsp::Requests::Formatting::Error)
    raise ::RubyLsp::Requests::Support::InternalRuboCopError, error
  else
    raise error
  end
end