class Solargraph::Diagnostics::Cookstyle
Cookstyle
class
Constants
- SEVERITIES
Conversion of RuboCop severity names to LSP constants
Public Instance Methods
diagnose(source, _api_map)
click to toggle source
# File lib/solargraph_cookstyle.rb, line 25 def diagnose(source, _api_map) options, paths = generate_options(source.filename, source.code) store = RuboCop::ConfigStore.new runner = RuboCop::Runner.new(options, store) result = redirect_stdout { runner.run(paths) } make_array JSON.parse(result) rescue RuboCop::ValidationError, RuboCop::ConfigNotFoundError => e raise Solargraph::DiagnosticsError, "Error in RuboCop configuration: #{e.message}" rescue JSON::ParserError raise Solargraph::DiagnosticsError, 'RuboCop returned invalid data' end
Private Instance Methods
make_array(resp)
click to toggle source
# File lib/solargraph_cookstyle.rb, line 40 def make_array(resp) diagnostics = [] resp['files'].each do |file| file['offenses'].each do |off| diagnostics.push offense_to_diagnostic(off) end end diagnostics end
offense_ending_position(off)
click to toggle source
# File lib/solargraph_cookstyle.rb, line 71 def offense_ending_position(off) if off['location']['start_line'] != off['location']['last_line'] Position.new(off['location']['start_line'], 0) else Position.new( off['location']['start_line'] - 1, off['location']['last_column'] ) end end
offense_range(off)
click to toggle source
# File lib/solargraph_cookstyle.rb, line 59 def offense_range(off) Range.new(offense_start_position(off), offense_ending_position(off)) end
offense_start_position(off)
click to toggle source
# File lib/solargraph_cookstyle.rb, line 64 def offense_start_position(off) Position.new( off['location']['start_line'] - 1, off['location']['start_column'] - 1 ) end
offense_to_diagnostic(off)
click to toggle source
# File lib/solargraph_cookstyle.rb, line 50 def offense_to_diagnostic(off) { range: offense_range(off).to_hash, severity: SEVERITIES[off['severity']], source: off['cop_name'], message: off['message'].gsub(/^#{off['cop_name']}\:/, '') } end