Class: RuboCop::Cop::Heatwave::RedundantHelpersFaIcon

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/heatwave/redundant_helpers_fa_icon.rb

Overview

Flags helpers.fa_icon(…) calls in views, components, and helpers.
fa_icon is delegated onto ViewComponent::Base (see
config/initializers/view_component_icon_helpers.rb) and is part of
ApplicationHelper, so the helpers. proxy is always redundant in
render contexts. Keeping it adds noise and makes ViewComponent
templates harder to scan.

Examples:

# bad
<%= helpers.fa_icon('gear', class: 'me-2') %>

# good
<%= fa_icon('gear', class: 'me-2') %>

Constant Summary collapse

MSG =
'Use bare `fa_icon` instead of `helpers.fa_icon` — it is ' \
'available on every component and view.'
TARGET_REGEX =

Match the helpers. (or helpers&.) prefix immediately before
fa_icon. Allow leading whitespace / ( / [ / , / = so we
don't accidentally rewrite my_helpers.fa_icon (different receiver).

/(?<![A-Za-z0-9_])helpers\s*&?\.\s*(fa_icon)\b/

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



30
31
32
# File 'lib/rubocop/cop/heatwave/redundant_helpers_fa_icon.rb', line 30

def on_new_investigation
  scan_source
end

#on_other_fileObject



34
35
36
# File 'lib/rubocop/cop/heatwave/redundant_helpers_fa_icon.rb', line 34

def on_other_file
  scan_source
end