Class: RuboCop::Cop::RubyLsp::UseLanguageServerAliases
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::RubyLsp::UseLanguageServerAliases
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb
Overview
Prefer using ‘Interface`, `Transport` and `Constant` aliases within the `RubyLsp` module, without having to prefix with `LanguageServer::Protocol`
Constant Summary collapse
- ALIASED_CONSTANTS =
T.let([:Interface, :Transport, :Constant].freeze, T::Array[Symbol])
- MSG =
"Use constant alias `%{constant}`."
Instance Method Summary collapse
Instance Method Details
permalink #on_new_investigation ⇒ Object
[View source]
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rubocop/cop/ruby_lsp/use_language_server_aliases.rb', line 44 def on_new_investigation return if processed_source.blank? ruby_lsp_modules(processed_source.ast).each do |ruby_lsp_mod| lsp_constant_usages(ruby_lsp_mod).each do |node| lsp_const = node.children.last next unless ALIASED_CONSTANTS.include?(lsp_const) add_offense(node, message: format(MSG, constant: lsp_const)) do |corrector| corrector.replace(node, lsp_const) end end end end |