Class: RubyLsp::Requests::Support::RuboCopFormattingRunner

Inherits:
RuboCop::Runner
  • Object
show all
Extended by:
T::Sig
Includes:
Singleton
Defined in:
lib/ruby_lsp/requests/support/rubocop_formatting_runner.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeRuboCopFormattingRunner

Returns a new instance of RuboCopFormattingRunner.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_lsp/requests/support/rubocop_formatting_runner.rb', line 22

def initialize
  @options = T.let({}, T::Hash[Symbol, T.untyped])

  super(
    ::RuboCop::Options.new.parse([
      "--stderr", # Print any output to stderr so that our stdout does not get polluted
      "--force-exclusion",
      "--format",
      "RuboCop::Formatter::BaseFormatter", # Suppress any output by using the base formatter
      "-a", # --auto-correct
    ]).first,
    ::RuboCop::ConfigStore.new
  )
end

Instance Method Details

#run(uri, document) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/ruby_lsp/requests/support/rubocop_formatting_runner.rb', line 38

def run(uri, document)
  file = CGI.unescape(URI.parse(uri).path)
  # We communicate with Rubocop via stdin
  @options[:stdin] = document.source

  # Invoke RuboCop with just this file in `paths`
  super([file])
  @options[:stdin]
end