Class: RuboCop::Cop::Glyphs::LegacyIconHelper

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp, LibraryCallHelpers
Defined in:
lib/rubocop/cop/glyphs/legacy_icon_helper.rb

Overview

Replaces legacy icon helper calls with Glyphs kit components.

Examples:

# bad
_lucide(:house, class: "size-4")
icon("check", library: "lucide")
icon("check")

# good
LucideIcon(:house, class: "size-4")
LucideIcon("check")
HeroIcon("check") # `DefaultLibraryComponent` when no library: is given

Constant Summary collapse

MSG =
"Use `%{component}(...)` instead of `%{helper}(...)`."
MSG_DYNAMIC =
"Use a Glyphs component (e.g. `LucideIcon(...)`) instead of `icon(...)` with a dynamic library."
MSG_UNKNOWN =
"Use a Glyphs component instead of `icon(...)`; add a `LibraryComponents` mapping " \
"for library `%{library}`."
DEFAULT_MAPPINGS =
{
  _lucide: "LucideIcon",
  _phosphor: "PhosphorIcon",
  _hero: "HeroIcon",
  _heroicon: "HeroIcon",
  _tabler: "TablerIcon"
}.freeze

Constants included from LibraryCallHelpers

RuboCop::Cop::Glyphs::LibraryCallHelpers::LIBRARY_KEYS, RuboCop::Cop::Glyphs::LibraryCallHelpers::LIBRARY_TO_COMPONENT

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/rubocop/cop/glyphs/legacy_icon_helper.rb', line 36

def on_send(node)
  return unless node.receiver.nil?

  if (component = mappings[node.method_name])
    rename_offense(node, component)
  elsif node.method_name == :icon && node.arguments.any?
    correct_icon_call(node)
  end
end