Sha256: b7a788ef16e674c3fac238361eaebc9c0639a055828e6aef3bf145441a626949
Contents?: true
Size: 1.64 KB
Versions: 6
Compression:
Stored size: 1.64 KB
Contents
# typed: strict # frozen_string_literal: true begin require "rubocop" rescue LoadError return end require "cgi" require "singleton" module RubyLsp module Requests module Support # :nodoc: class RuboCopDiagnosticsRunner < RuboCop::Runner extend T::Sig include Singleton sig { void } def initialize @options = T.let({}, T::Hash[Symbol, T.untyped]) @uri = T.let(nil, T.nilable(String)) @diagnostics = T.let([], T::Array[Support::RuboCopDiagnostic]) super( ::RuboCop::Options.new.parse([ "--stderr", # Print any output to stderr so that our stdout does not get polluted "--force-exclusion", "--format", "RuboCop::Formatter::BaseFormatter", # Suppress any output by using the base formatter ]).first, ::RuboCop::ConfigStore.new ) end sig { params(uri: String, document: Document).returns(T::Array[Support::RuboCopDiagnostic]) } def run(uri, document) @diagnostics.clear @uri = uri file = CGI.unescape(URI.parse(uri).path) # We communicate with Rubocop via stdin @options[:stdin] = document.source # Invoke RuboCop with just this file in `paths` super([file]) @diagnostics end private sig { params(_file: String, offenses: T::Array[RuboCop::Cop::Offense]).void } def file_finished(_file, offenses) @diagnostics = offenses.map { |offense| Support::RuboCopDiagnostic.new(offense, T.must(@uri)) } end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems