Sha256: 7c430239ee4bb2e50f7ff6b481f03cbc329eae1970d8181b918462ee740feede

Contents?: true

Size: 1.58 KB

Versions: 12

Compression:

Stored size: 1.58 KB

Contents

# typed: strict
# frozen_string_literal: true

return unless defined?(RubyLsp::Requests::Support::RuboCopRunner)

module RubyLsp
  module Requests
    module Support
      class RuboCopFormatter
        extend T::Sig
        include Formatter

        sig { void }
        def initialize
          @diagnostic_runner = T.let(RuboCopRunner.new, RuboCopRunner)
          # -a is for "--auto-correct" (or "--autocorrect" on newer versions of RuboCop)
          @format_runner = T.let(RuboCopRunner.new("-a"), RuboCopRunner)
        end

        sig { override.params(uri: URI::Generic, document: Document).returns(T.nilable(String)) }
        def run_formatting(uri, document)
          filename = T.must(uri.to_standardized_path || uri.opaque)

          # Invoke RuboCop with just this file in `paths`
          @format_runner.run(filename, document.source)
          @format_runner.formatted_source
        end

        sig do
          override.params(
            uri: URI::Generic,
            document: Document,
          ).returns(T.nilable(T::Array[Interface::Diagnostic]))
        end
        def run_diagnostic(uri, document)
          filename = T.must(uri.to_standardized_path || uri.opaque)
          # Invoke RuboCop with just this file in `paths`
          @diagnostic_runner.run(filename, document.source)

          @diagnostic_runner.offenses.map do |offense|
            Support::RuboCopDiagnostic.new(
              document,
              offense,
              uri,
            ).to_lsp_diagnostic(@diagnostic_runner.config_for_working_directory)
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ruby-lsp-0.17.13 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.12 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.11 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.10 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.9 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.8 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.7 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.6 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.5 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.4 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.3 lib/ruby_lsp/requests/support/rubocop_formatter.rb
ruby-lsp-0.17.2 lib/ruby_lsp/requests/support/rubocop_formatter.rb