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 Attribute Summary collapse
- #layout_mode ⇒ Object writeonly private
- #lint_mode ⇒ Object writeonly private
- #safe_autocorrect ⇒ Object writeonly private
Instance Method Summary collapse
-
#format(path, text, command:) ⇒ 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.
21 22 23 24 25 26 27 |
# File 'lib/rubocop/lsp/runtime.rb', line 21 def initialize(config_store) @config_store = config_store @logged_paths = [] @safe_autocorrect = true @lint_mode = false @layout_mode = false end |
Instance Attribute Details
#layout_mode=(value) ⇒ Object (writeonly)
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.
19 20 21 |
# File 'lib/rubocop/lsp/runtime.rb', line 19 def layout_mode=(value) @layout_mode = value end |
#lint_mode=(value) ⇒ Object (writeonly)
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.
19 20 21 |
# File 'lib/rubocop/lsp/runtime.rb', line 19 def lint_mode=(value) @lint_mode = value end |
#safe_autocorrect=(value) ⇒ Object (writeonly)
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.
19 20 21 |
# File 'lib/rubocop/lsp/runtime.rb', line 19 def safe_autocorrect=(value) @safe_autocorrect = value end |
Instance Method Details
#format(path, text, command:) ⇒ 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rubocop/lsp/runtime.rb', line 40 def format(path, text, command:) safe_autocorrect = if command command == 'rubocop.formatAutocorrects' else @safe_autocorrect end = { stdin: text, force_exclusion: true, autocorrect: true, safe_autocorrect: safe_autocorrect } [:only] = if @lint_mode || @layout_mode 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.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rubocop/lsp/runtime.rb', line 57 def offenses(path, text) = { stdin: text, force_exclusion: true, formatters: ['json'], format: 'json' } [:only] = if @lint_mode || @layout_mode 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 |