Class: RuboCop::Lsp::StdinRunner Private

Inherits:
Runner
  • Object
show all
Defined in:
lib/rubocop/lsp/stdin_runner.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Originally lifted from: https://github.com/Shopify/ruby-lsp/blob/8d4c17efce4e8ecc8e7c557ab2981db6b22c0b6d/lib/ruby_lsp/requests/support/rubocop_runner.rb#L20

Defined Under Namespace

Classes: ConfigurationError

Constant Summary collapse

DEFAULT_RUBOCOP_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  stderr: true,
  force_exclusion: true,
  formatters: ['RuboCop::Formatter::BaseFormatter'],
  raise_cop_error: true,
  todo_file: nil,
  todo_ignore_files: []
}.freeze

Constants inherited from Runner

Runner::MAX_ITERATIONS, Runner::REDUNDANT_COP_DISABLE_DIRECTIVE_RULES

Instance Attribute Summary collapse

Attributes inherited from Runner

#aborting, #errors, #warnings

Instance Method Summary collapse

Methods inherited from Runner

#aborting?, ruby_extractors

Constructor Details

#initialize(config_store) ⇒ StdinRunner

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of StdinRunner.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/lsp/stdin_runner.rb', line 31

def initialize(config_store)
  @options = {}

  @offenses = []
  @warnings = []
  @errors = []

  @config_for_working_directory = config_store.for_pwd

  super(@options, config_store)
end

Instance Attribute Details

#config_for_working_directoryObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/rubocop/lsp/stdin_runner.rb', line 20

def config_for_working_directory
  @config_for_working_directory
end

#offensesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/rubocop/lsp/stdin_runner.rb', line 20

def offenses
  @offenses
end

#processed_sourceObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
# File 'lib/rubocop/lsp/stdin_runner.rb', line 20

def processed_source
  @processed_source
end

Instance Method Details

#formatted_sourceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



59
60
61
# File 'lib/rubocop/lsp/stdin_runner.rb', line 59

def formatted_source
  @options[:stdin]
end

#reset_project_indexObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Drop the cached project index so the next run rebuilds it. Called when a file is saved or a watched file changes, i.e. when the on-disk state the index is derived from may have changed.



66
67
68
69
# File 'lib/rubocop/lsp/stdin_runner.rb', line 66

def reset_project_index
  @project_index = nil
  @project_index_built = false
end

#run(path, contents, options, prism_result: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (Interrupt)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rubocop/lsp/stdin_runner.rb', line 43

def run(path, contents, options, prism_result: nil)
  @options = options.merge(DEFAULT_RUBOCOP_OPTIONS)
  @options[:stdin] = contents

  @prism_result = prism_result
  @processed_source = nil

  @offenses = []
  @warnings = []
  @errors = []

  super([path])

  raise Interrupt if aborting?
end