Class: Standard::Lsp::Standardizer
- Inherits:
-
Object
- Object
- Standard::Lsp::Standardizer
- Defined in:
- lib/standard/lsp/standardizer.rb
Instance Method Summary collapse
- #format(path, text) ⇒ Object
-
#initialize(config) ⇒ Standardizer
constructor
A new instance of Standardizer.
- #offenses(path, text, document_encoding = nil) ⇒ Object
Constructor Details
#initialize(config) ⇒ Standardizer
Returns a new instance of Standardizer.
7 8 9 10 11 12 13 |
# File 'lib/standard/lsp/standardizer.rb', line 7 def initialize(config) @diagnostic_runner = ::Standard::Lsp::StdinRubocopRunner.new(config) @format_runner = ::Standard::Lsp::StdinRubocopRunner.new(config.dup.tap { |c| c.[:autocorrect] = true }) @cop_registry = RuboCop::Cop::Registry.global.to_h end |
Instance Method Details
#format(path, text) ⇒ Object
15 16 17 18 |
# File 'lib/standard/lsp/standardizer.rb', line 15 def format(path, text) @format_runner.run(path, text) @format_runner.formatted_source end |
#offenses(path, text, document_encoding = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/standard/lsp/standardizer.rb', line 20 def offenses(path, text, document_encoding = nil) @diagnostic_runner.run(path, text) @diagnostic_runner.offenses.map do |offense| Diagnostic.new( document_encoding, offense, path, @cop_registry[offense.cop_name]&.first ).to_lsp_diagnostic(@diagnostic_runner.config_for_working_directory) end end |