Class: RuboCop::Cop::Heatwave::CanonicalFaIconName
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Heatwave::CanonicalFaIconName
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/heatwave/canonical_fa_icon_name.rb
Overview
Rewrites fa_icon('legacy-name', ...) calls to use the canonical Font
Awesome Pro 7+ icon name. The legacy → canonical map is generated from
the bundled FA Pro metadata (shims.yml + icons.yml/aliases.names)
via bundle exec rake lint:regenerate_fa_aliases. See the JSON file
at lib/rubocop/cop/heatwave/fa_icon_aliases.json.
The cop:
- Matches
fa_icon('NAME', ...),fa_icon "NAME", andfa_icon :name
in both ERB and Ruby files. - Skips dynamic arguments (variables, method calls, ERB
interpolation) — only string and bare-symbol literals are
considered. - Skips matches inside
<script>blocks for the same reason
Heatwave/NoInlineFaIcondoes. - Symbols whose canonical replacement contains a
-are converted
to single-quoted strings (Ruby symbol literals can't include
dashes without:'…'quoting; switching to a string keeps the
call site idiomatic).
Constant Summary collapse
- ALIASES_PATH =
File.('fa_icon_aliases.json', __dir__)
- ALIASES =
JSON.parse(File.read(ALIASES_PATH)).fetch('aliases').freeze
- FA_PRO_VERSION =
JSON.parse(File.read(ALIASES_PATH))['fa_pro_version']
- MSG =
'Use the canonical FA Pro %<version>s name `%<canonical>s` ' \ 'instead of legacy `%<legacy>s`.'
- STRING_CALL_REGEX =
fa_iconfirst-positional-argument literals. We deliberately keep the
regex strict so we never accidentally rewrite a non-icon argument:fa_icon('NAME',fa_icon "NAME",fa_icon('NAME')fa_icon(:name,fa_icon :name
Dashes are allowed inside the string form; bare symbol literals are
restricted to underscores (Ruby's symbol grammar) sofa_icon(:plus)
matches butfa_icon(:'circle-info')does not — the latter is rare
and rewriting:'…'literals adds parsing complexity for no benefit.
/\bfa_icon\s*\(?\s*(['"])([a-z][a-z0-9-]*)\1/- SYMBOL_CALL_REGEX =
/\bfa_icon\s*\(?\s*:([a-z_][a-z0-9_]*)/- QUOTED_SYMBOL_CALL_REGEX =
/\bfa_icon\s*\(?\s*:(['"])([a-z][a-z0-9-]*)\1/
Instance Method Summary collapse
Instance Method Details
#on_new_investigation ⇒ Object
59 60 61 |
# File 'lib/rubocop/cop/heatwave/canonical_fa_icon_name.rb', line 59 def on_new_investigation scan_source end |
#on_other_file ⇒ Object
63 64 65 |
# File 'lib/rubocop/cop/heatwave/canonical_fa_icon_name.rb', line 63 def on_other_file scan_source end |