Class: RuboCop::Cop::Primer::DeprecatedLabelSchemes
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/primer/deprecated_label_schemes.rb
Overview
This cop ensures that components don’t use deprecated ‘Label` schemes.
bad Primer::Beta::Label.new(scheme: :info)
good Primer::Beta::Label.new(scheme: :accent)
Constant Summary collapse
- INVALID_MESSAGE =
"Avoid using deprecated schemes: https://primer.style/view-components/deprecated#labelcomponent.\n"
- DEPRECATIONS =
This is a hash of deprecated schemes and their replacements.
{ info: ":accent", warning: ":attention", orange: ":severe", purple: ":done" }.freeze
Instance Method Summary collapse
Methods inherited from BaseCop
Instance Method Details
#on_send(node) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubocop/cop/primer/deprecated_label_schemes.rb', line 30 def on_send(node) return unless label_node?(node) return unless node.arguments? # we are looking for hash arguments and they are always last kwargs = node.arguments.last return unless kwargs.type == :hash kwargs.pairs.each do |pair| # Skip if we're not dealing with a symbol next if pair.key.type != :sym next unless pair.value.type == :sym || pair.value.type == :str value = pair.value.value.to_sym next unless DEPRECATIONS.key?(value) add_offense(pair.value, message: INVALID_MESSAGE) do |corrector| replacement = DEPRECATIONS[pair.value.value.to_sym] corrector.replace(pair.value, replacement) end end end |