Class: RubyLsp::Requests::RuboCopRequest

Inherits:
RuboCop::Runner
  • Object
show all
Defined in:
lib/ruby_lsp/requests/rubocop_request.rb

Overview

:nodoc:

Direct Known Subclasses

Diagnostics, Formatting

Constant Summary collapse

COMMON_RUBOCOP_FLAGS =
[
  "--stderr", # Print any output to stderr so that our stdout does not get polluted
  "--format",
  "RuboCop::Formatter::BaseFormatter", # Suppress any output by using the base formatter
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, document) ⇒ RuboCopRequest

Returns a new instance of RuboCopRequest.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby_lsp/requests/rubocop_request.rb', line 23

def initialize(uri, document)
  @file = CGI.unescape(URI.parse(uri).path)
  @document = document
  @text = document.source
  @uri = uri

  super(
    ::RuboCop::Options.new.parse(rubocop_flags).first,
    ::RuboCop::ConfigStore.new
  )
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



17
18
19
# File 'lib/ruby_lsp/requests/rubocop_request.rb', line 17

def file
  @file
end

#textObject (readonly)

Returns the value of attribute text.



17
18
19
# File 'lib/ruby_lsp/requests/rubocop_request.rb', line 17

def text
  @text
end

Class Method Details

.run(uri, document) ⇒ Object



19
20
21
# File 'lib/ruby_lsp/requests/rubocop_request.rb', line 19

def self.run(uri, document)
  new(uri, document).run
end

Instance Method Details

#runObject



35
36
37
38
39
40
41
# File 'lib/ruby_lsp/requests/rubocop_request.rb', line 35

def run
  # We communicate with Rubocop via stdin
  @options[:stdin] = text

  # Invoke the actual run method with just this file in `paths`
  super([file])
end