Class: Solargraph::Diagnostics::Rubocop

Inherits:
Base
  • Object
show all
Defined in:
lib/solargraph/diagnostics/rubocop.rb

Overview

This reporter provides linting through RuboCop.

Constant Summary collapse

SEVERITIES =

Conversion of RuboCop severity names to LSP constants

{
  'refactor' => Severities::HINT,
  'convention' => Severities::INFORMATION,
  'warning' => Severities::WARNING,
  'error' => Severities::ERROR,
  'fatal' => Severities::ERROR
}

Instance Method Summary collapse

Instance Method Details

#diagnose(source, api_map) ⇒ Array<Hash>

Parameters:

Returns:

  • (Array<Hash>)


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

def diagnose source, api_map
  options, paths = generate_options(source.filename, source.code)
  runner = RuboCop::Runner.new(options, RuboCop::ConfigStore.new)
  result = redirect_stdout{ runner.run(paths) }
  make_array JSON.parse(result)
rescue JSON::ParserError
  raise DiagnosticsError, 'RuboCop returned invalid data'
end