From 1a09f4012ddf2b198b37131ef2a67425339b192b Mon Sep 17 00:00:00 2001 From: Aymeric Brisse Date: Fri, 10 Jan 2025 17:57:17 +0100 Subject: [PATCH] Use top level namespace operand on Rubocop (#3044) --- .../requests/support/rubocop_diagnostic.rb | 6 ++--- .../requests/support/rubocop_runner.rb | 26 +++++++++---------- lib/ruby_lsp/server.rb | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb b/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb index d543c117bd..7c5419487b 100644 --- a/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +++ b/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb @@ -31,7 +31,7 @@ class RuboCopDiagnostic # TODO: avoid passing document once we have alternative ways to get at # encoding and file source - sig { params(document: RubyDocument, offense: RuboCop::Cop::Offense, uri: URI::Generic).void } + sig { params(document: RubyDocument, offense: ::RuboCop::Cop::Offense, uri: URI::Generic).void } def initialize(document, offense, uri) @document = document @offense = offense @@ -48,7 +48,7 @@ def to_lsp_code_actions code_actions end - sig { params(config: RuboCop::Config).returns(Interface::Diagnostic) } + sig { params(config: ::RuboCop::Config).returns(Interface::Diagnostic) } def to_lsp_diagnostic(config) # highlighted_area contains the begin and end position of the first line # This ensures that multiline offenses don't clutter the editor @@ -90,7 +90,7 @@ def severity RUBOCOP_TO_LSP_SEVERITY[@offense.severity.name] end - sig { params(config: RuboCop::Config).returns(T.nilable(Interface::CodeDescription)) } + sig { params(config: ::RuboCop::Config).returns(T.nilable(Interface::CodeDescription)) } def code_description(config) cop = RuboCopRunner.find_cop_by_name(@offense.cop_name) return unless cop diff --git a/lib/ruby_lsp/requests/support/rubocop_runner.rb b/lib/ruby_lsp/requests/support/rubocop_runner.rb index 91d2d840a1..d91f046fe3 100644 --- a/lib/ruby_lsp/requests/support/rubocop_runner.rb +++ b/lib/ruby_lsp/requests/support/rubocop_runner.rb @@ -40,10 +40,10 @@ class InternalRuboCopError < StandardError For more details, run RuboCop on the command line. EOS - sig { params(rubocop_error: T.any(RuboCop::ErrorWithAnalyzedFileLocation, StandardError)).void } + sig { params(rubocop_error: T.any(::RuboCop::ErrorWithAnalyzedFileLocation, StandardError)).void } def initialize(rubocop_error) message = case rubocop_error - when RuboCop::ErrorWithAnalyzedFileLocation + when ::RuboCop::ErrorWithAnalyzedFileLocation format(MESSAGE, "for the #{rubocop_error.cop.name} cop") when StandardError format(MESSAGE, rubocop_error.message) @@ -53,7 +53,7 @@ def initialize(rubocop_error) end # :nodoc: - class RuboCopRunner < RuboCop::Runner + class RuboCopRunner < ::RuboCop::Runner extend T::Sig class ConfigurationError < StandardError; end @@ -68,14 +68,14 @@ class ConfigurationError < StandardError; end T::Array[String], ) - sig { returns(T::Array[RuboCop::Cop::Offense]) } + sig { returns(T::Array[::RuboCop::Cop::Offense]) } attr_reader :offenses sig { returns(::RuboCop::Config) } attr_reader :config_for_working_directory begin - RuboCop::Options.new.parse(["--raise-cop-error"]) + ::RuboCop::Options.new.parse(["--raise-cop-error"]) DEFAULT_ARGS << "--raise-cop-error" rescue OptionParser::InvalidOption # older versions of RuboCop don't support this flag @@ -85,7 +85,7 @@ class ConfigurationError < StandardError; end sig { params(args: String).void } def initialize(*args) @options = T.let({}, T::Hash[Symbol, T.untyped]) - @offenses = T.let([], T::Array[RuboCop::Cop::Offense]) + @offenses = T.let([], T::Array[::RuboCop::Cop::Offense]) @errors = T.let([], T::Array[String]) @warnings = T.let([], T::Array[String]) @@ -113,9 +113,9 @@ def run(path, contents) # RuboCop rescues interrupts and then sets the `@aborting` variable to true. We don't want them to be rescued, # so here we re-raise in case RuboCop received an interrupt. raise Interrupt if aborting? - rescue RuboCop::Runner::InfiniteCorrectionLoop => error + rescue ::RuboCop::Runner::InfiniteCorrectionLoop => error raise Formatting::Error, error.message - rescue RuboCop::ValidationError => error + rescue ::RuboCop::ValidationError => error raise ConfigurationError, error.message rescue StandardError => error raise InternalRuboCopError, error @@ -129,25 +129,25 @@ def formatted_source class << self extend T::Sig - sig { params(cop_name: String).returns(T.nilable(T.class_of(RuboCop::Cop::Base))) } + sig { params(cop_name: String).returns(T.nilable(T.class_of(::RuboCop::Cop::Base))) } def find_cop_by_name(cop_name) cop_registry[cop_name]&.first end private - sig { returns(T::Hash[String, [T.class_of(RuboCop::Cop::Base)]]) } + sig { returns(T::Hash[String, [T.class_of(::RuboCop::Cop::Base)]]) } def cop_registry @cop_registry ||= T.let( - RuboCop::Cop::Registry.global.to_h, - T.nilable(T::Hash[String, [T.class_of(RuboCop::Cop::Base)]]), + ::RuboCop::Cop::Registry.global.to_h, + T.nilable(T::Hash[String, [T.class_of(::RuboCop::Cop::Base)]]), ) end end private - sig { params(_file: String, offenses: T::Array[RuboCop::Cop::Offense]).void } + sig { params(_file: String, offenses: T::Array[::RuboCop::Cop::Offense]).void } def file_finished(_file, offenses) @offenses = offenses end diff --git a/lib/ruby_lsp/server.rb b/lib/ruby_lsp/server.rb index e2860c8b95..458dbd565c 100644 --- a/lib/ruby_lsp/server.rb +++ b/lib/ruby_lsp/server.rb @@ -339,7 +339,7 @@ def run_initialized if defined?(Requests::Support::RuboCopFormatter) begin @global_state.register_formatter("rubocop", Requests::Support::RuboCopFormatter.new) - rescue RuboCop::Error => e + rescue ::RuboCop::Error => e # The user may have provided unknown config switches in .rubocop or # is trying to load a non-existent config file. send_message(Notification.window_show_message(