Class: RubyLsp::Requests::Support::RuboCopFormatter
- Inherits:
-
Object
- Object
- RubyLsp::Requests::Support::RuboCopFormatter
- Includes:
- Formatter
- Defined in:
- lib/ruby_lsp/requests/support/rubocop_formatter.rb
Instance Method Summary collapse
-
#initialize ⇒ RuboCopFormatter
constructor
: -> void.
-
#run_diagnostic(uri, document) ⇒ Object
: (URI::Generic uri, RubyDocument document) -> Array?.
-
#run_formatting(uri, document) ⇒ Object
: (URI::Generic uri, RubyDocument document) -> String?.
-
#run_range_formatting(uri, source, base_indentation) ⇒ Object
RuboCop does not support range formatting : (URI::Generic uri, String source, Integer base_indentation) -> String?.
Constructor Details
#initialize ⇒ RuboCopFormatter
: -> void
15 16 17 18 19 |
# File 'lib/ruby_lsp/requests/support/rubocop_formatter.rb', line 15 def initialize @diagnostic_runner = RuboCopRunner.new #: RuboCopRunner # -a is for "--auto-correct" (or "--autocorrect" on newer versions of RuboCop) @format_runner = RuboCopRunner.new("-a") #: RuboCopRunner end |
Instance Method Details
#run_diagnostic(uri, document) ⇒ Object
: (URI::Generic uri, RubyDocument document) -> Array?
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby_lsp/requests/support/rubocop_formatter.rb', line 40 def run_diagnostic(uri, document) filename = uri.to_standardized_path || uri.opaque #: as !nil # Invoke RuboCop with just this file in `paths` @diagnostic_runner.run(filename, document.source, document.parse_result) @diagnostic_runner.offenses.map do |offense| Support::RuboCopDiagnostic.new( document, offense, uri, ).to_lsp_diagnostic(@diagnostic_runner.config_for_working_directory) end end |
#run_formatting(uri, document) ⇒ Object
: (URI::Generic uri, RubyDocument document) -> String?
23 24 25 26 27 28 29 |
# File 'lib/ruby_lsp/requests/support/rubocop_formatter.rb', line 23 def run_formatting(uri, document) filename = uri.to_standardized_path || uri.opaque #: as !nil # Invoke RuboCop with just this file in `paths` @format_runner.run(filename, document.source, document.parse_result) @format_runner.formatted_source end |
#run_range_formatting(uri, source, base_indentation) ⇒ Object
RuboCop does not support range formatting : (URI::Generic uri, String source, Integer base_indentation) -> String?
34 35 36 |
# File 'lib/ruby_lsp/requests/support/rubocop_formatter.rb', line 34 def run_range_formatting(uri, source, base_indentation) nil end |