class RubyLsp::Requests::Support::RuboCopFormatter
def initialize
def initialize @diagnostic_runner = RuboCopRunner.new #: RuboCopRunner # -a is for "--auto-correct" (or "--autocorrect" on newer versions of RuboCop) @format_runner = RuboCopRunner.new("-a") #: RuboCopRunner end
def run_diagnostic(uri, document)
@override
def run_diagnostic(uri, document) filename = uri.to_standardized_path || uri.opaque #: as !nil # Invoke RuboCop with just this file in `paths` @diagnostic_runner.run(filename, document.source) @diagnostic_runner.offenses.map do |offense| Support::RuboCopDiagnostic.new( document, offense, uri, ).to_lsp_diagnostic(@diagnostic_runner.config_for_working_directory) end end
def run_formatting(uri, document)
@override
def run_formatting(uri, document) filename = uri.to_standardized_path || uri.opaque #: as !nil # Invoke RuboCop with just this file in `paths` @format_runner.run(filename, document.source) @format_runner.formatted_source end
def run_range_formatting(uri, source, base_indentation)
@override
RuboCop does not support range formatting
def run_range_formatting(uri, source, base_indentation) nil end