Class: RuboCop::Lsp::Runtime Private
- Inherits:
-
Object
- Object
- RuboCop::Lsp::Runtime
- Defined in:
- lib/rubocop/lsp/runtime.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.
Runtime for Language Server Protocol of RuboCop.
Instance Method Summary collapse
-
#format(path, text) ⇒ Object
private
This abuses the ‘–stdin` option of rubocop and reads the formatted text from the `options` that rubocop mutates.
-
#initialize(config_store) ⇒ Runtime
constructor
private
A new instance of Runtime.
- #offenses(path, text) ⇒ Object private
Constructor Details
#initialize(config_store) ⇒ Runtime
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 Runtime.
17 18 19 20 |
# File 'lib/rubocop/lsp/runtime.rb', line 17 def initialize(config_store) @config_store = config_store @logged_paths = [] end |
Instance Method Details
#format(path, text) ⇒ 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.
This abuses the ‘–stdin` option of rubocop and reads the formatted text from the `options` that rubocop mutates. This depends on `parallel: false` as well as the fact that RuboCop doesn’t otherwise dup or reassign that options object. Risky business!
Reassigning ‘options` is done here:
https://github.com/rubocop/rubocop/blob/v1.52.0/lib/rubocop/cop/team.rb#L131
Printing ‘options`
https://github.com/rubocop/rubocop/blob/v1.52.0/lib/rubocop/cli/command/execute_runner.rb#L95
Setting ‘parallel: true` would break this here:
https://github.com/rubocop/rubocop/blob/v1.52.0/lib/rubocop/runner.rb#L72
33 34 35 36 37 38 39 40 41 |
# File 'lib/rubocop/lsp/runtime.rb', line 33 def format(path, text) = { stdin: text, force_exclusion: true, autocorrect: true, safe_autocorrect: true } redirect_stdout { run_rubocop(, path) } [:stdin] end |
#offenses(path, text) ⇒ 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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rubocop/lsp/runtime.rb', line 43 def offenses(path, text) = { stdin: text, force_exclusion: true, formatters: ['json'], format: 'json' } json = redirect_stdout { run_rubocop(, path) } results = JSON.parse(json, symbolize_names: true) if results[:files].empty? unless @logged_paths.include?(path) Logger.log "Ignoring file, per configuration: #{path}" @logged_paths << path end return [] end results.dig(:files, 0, :offenses) end |