Class: RubyLsp::Requests::RuboCopRequest

Inherits:
RuboCop::Runner
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/ruby_lsp/requests/rubocop_request.rb

Overview

:nodoc:

Direct Known Subclasses

Diagnostics, Formatting

Constant Summary collapse

COMMON_RUBOCOP_FLAGS =
T.let([
  "--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, T::Array[String])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, document) ⇒ RuboCopRequest

Returns a new instance of RuboCopRequest.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ruby_lsp/requests/rubocop_request.rb', line 29

def initialize(uri, document)
  @file = T.let(CGI.unescape(URI.parse(uri).path), String)
  @document = document
  @text = T.let(document.source, String)
  @uri = uri
  @options = T.let({}, T::Hash[Symbol, T.untyped])
  @diagnostics = T.let([], T::Array[Support::RuboCopDiagnostic])

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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



23
24
25
# File 'lib/ruby_lsp/requests/rubocop_request.rb', line 23

def file
  @file
end

#textObject (readonly)

Returns the value of attribute text.



26
27
28
# File 'lib/ruby_lsp/requests/rubocop_request.rb', line 26

def text
  @text
end

Instance Method Details

#runObject



44
45
46
47
48
49
50
# File 'lib/ruby_lsp/requests/rubocop_request.rb', line 44

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