class RubyLsp::Requests::Support::RuboCopRunner
:nodoc:
def cop_registry
def cop_registry @cop_registry ||= ::RuboCop::Cop::Registry.global.to_h #: Hash[String, [singleton(::RuboCop::Cop::Base)]]? end
def file_finished(_file, offenses)
def file_finished(_file, offenses) @offenses = offenses end
def find_cop_by_name(cop_name)
def find_cop_by_name(cop_name) cop_registry[cop_name]&.first end
def formatted_source
def formatted_source @options[:stdin] end
def initialize(*args)
def initialize(*args) @options = {} #: Hash[Symbol, untyped] @offenses = [] #: Array[::RuboCop::Cop::Offense] @errors = [] #: Array[String] @warnings = [] #: Array[String] args += DEFAULT_ARGS rubocop_options = ::RuboCop::Options.new.parse(args).first config_store = ::RuboCop::ConfigStore.new config_store.options_config = rubocop_options[:config] if rubocop_options[:config] @config_for_working_directory = config_store.for_pwd #: ::RuboCop::Config super(rubocop_options, config_store) end
def run(path, contents)
def run(path, contents) # Clear Runner state between runs since we get a single instance of this class # on every use site. @errors = [] @warnings = [] @offenses = [] @options[:stdin] = contents super([path]) # 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 raise Formatting::Error, error.message rescue ::RuboCop::ValidationError => error raise ConfigurationError, error.message rescue StandardError => error # Maintain the original backtrace so that debugging cops that are breaking is easier, but re-raise as a # different error class internal_error = InternalRuboCopError.new(error) internal_error.set_backtrace(error.backtrace) raise internal_error end