Class: Solargraph::Diagnostics::Rubocop

Inherits:
Base
  • Object
show all
Includes:
RubocopHelpers
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 Attribute Summary

Attributes inherited from Base

#args

Instance Method Summary collapse

Methods included from RubocopHelpers

find_rubocop_file, fix_drive_letter, generate_options

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Solargraph::Diagnostics::Base

Instance Method Details

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


23
24
25
26
27
28
29
30
31
32
# File 'lib/solargraph/diagnostics/rubocop.rb', line 23

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 RuboCop::ValidationError, RuboCop::ConfigNotFoundError => e
  raise DiagnosticsError, "Error in RuboCop configuration: #{e.message}"
rescue JSON::ParserError
  raise DiagnosticsError, 'RuboCop returned invalid data'
end