Class: RuboCop::Cop::Heatwave::NoInlineFaIcon
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Heatwave::NoInlineFaIcon
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/heatwave/no_inline_fa_icon.rb
Overview
Flags raw <i class="fa-...">…</i> Font Awesome tags in ERB templates and
rewrites them as <%= fa_icon(...) %> calls against IconHelper#fa_icon.
The helper centralises family handling, custom SVG fallback, default
sharp-regular family and fa-kit inlining — see
app/helpers/icon_helper.rb.
Behaviour:
- Recognises the modern (
fa-solid,fa-regular,fa-sharp fa-solid,
fa-brands,fa-kit) families and the legacy short-prefix families
from FA4/FA5 (fa,fas,far,fab,fal,fad) plus the Pro-only
fa-light/fa-thin/fa-duotonestyles. Unsupported variants are
collapsed onto the project's adopted sharp-regular default. - Forwards arbitrary HTML attributes (
style,title,aria-*,data-*,
id,role, …) through to the helper as keyword arguments, since
fa_iconalready splats them onto the underlyingtag.icall. - Skips matches inside
<script>blocks (those are JS string literals,
not real markup). - Refuses to autocorrect — and therefore just flags — anything it cannot
safely rewrite (multiple icon candidates, ERB interpolation in
attribute values, unparseable attribute fragments).
Constant Summary collapse
- MSG =
'Use the `fa_icon` helper instead of inline `<i class="fa-...">` ' \ 'tags so icon styling stays consistent.'
- TAG_REGEX =
Empty
<i ...></i>tag with at least one fa-* class. Attribute string
may not contain<or>so we never accidentally match across an
embedded ERB tag — that case is handled byassert_no_offensein the
tests. %r{<i\b([^<>]*?)>\s*</i>}- FAMILY_TOKENS =
Recognised Font Awesome family / style tokens. Includes both the modern
fa-<style>long form and the legacy short prefixes from FA4/FA5. %w[ fa fas far fab fal fad fa-regular fa-solid fa-light fa-thin fa-duotone fa-brands fa-sharp fa-kit ].freeze
- SIZING_TOKENS =
Font Awesome utility classes that are NOT the icon name.
%w[ fa-2xs fa-xs fa-sm fa-lg fa-xl fa-2xl fa-1x fa-2x fa-3x fa-4x fa-5x fa-6x fa-7x fa-8x fa-9x fa-10x fa-fw fa-spin fa-spin-pulse fa-spin-reverse fa-pulse fa-beat fa-bounce fa-fade fa-flip fa-shake fa-rotate-90 fa-rotate-180 fa-rotate-270 fa-flip-horizontal fa-flip-vertical fa-flip-both fa-stack fa-stack-1x fa-stack-2x fa-inverse fa-border fa-pull-left fa-pull-right fa-li fa-ul ].freeze
- FAMILY_MAP =
Family-token combinations → fa_icon
family:option (or nil for the
helper's default of :sharp_regular). Keys are sorted Arrays.
Legacy/Pro-only families collapse onto the project's adopted standard:
fa(FA4 prefix-only) andfas/fa-solidmap to:solid,fab/
fa-brandsto:brands,fad/fa-duotoneto:solid(closest
filled equivalent), andfar/fal/fa-light/fa-thinto the
default sharp-regular. { %w[fa] => :solid, %w[fas] => :solid, %w[far] => nil, %w[fab] => :brands, %w[fal] => nil, %w[fad] => :solid, %w[fa-regular] => nil, %w[fa-sharp fa-regular].sort => nil, %w[fa-solid] => :solid, %w[fa-sharp fa-solid].sort => :sharp_solid, %w[fa-brands] => :brands, %w[fa-kit] => :kit, %w[fa-light] => nil, %w[fa-thin] => nil, %w[fa-duotone] => :solid }.freeze
Instance Method Summary collapse
-
#on_new_investigation ⇒ Object
Commissioner#investigatecallson_new_investigationfor files that parse as Ruby andon_other_filefor everything else (including ERB templates, which are never valid Ruby). - #on_other_file ⇒ Object
Instance Method Details
#on_new_investigation ⇒ Object
Commissioner#investigate calls on_new_investigation for files that
parse as Ruby and on_other_file for everything else (including ERB
templates, which are never valid Ruby). Hooking both means the cop
runs whether it's invoked via the rake task (ERB → on_other_file) or
plain RuboCop on a .rb fixture (on_new_investigation).
99 100 101 |
# File 'lib/rubocop/cop/heatwave/no_inline_fa_icon.rb', line 99 def on_new_investigation scan_source end |
#on_other_file ⇒ Object
103 104 105 |
# File 'lib/rubocop/cop/heatwave/no_inline_fa_icon.rb', line 103 def on_other_file scan_source end |