Class: RuboCop::Cop::Primer::DeprecatedLabelVariants
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/primer/deprecated_label_variants.rb
Overview
This cop ensures that ‘LabelComponent`s don’t use the old ‘variant` argument.
bad Primer::Beta::Label.new(variant: :large)
good Primer::Beta::Label.new(size: :large)
bad Primer::Beta::Label.new(variant: :inline)
good Primer::Beta::Label.new(inline: true)
Instance Method Summary collapse
Methods inherited from BaseCop
Instance Method Details
#on_send(node) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rubocop/cop/primer/deprecated_label_variants.rb', line 24 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 or string next if pair.key.type != :sym next unless pair.value.type == :sym || pair.value.type == :str next if pair.key.value != :variant case pair.value.value when :large, "large" add_offense(pair, message: "Avoid using `variant: :large` with `LabelComponent`. Use `size: :large` instead.") do |corrector| corrector.replace(pair, "size: :large") end when :inline, "inline" add_offense(pair, message: "Avoid using `variant: :inline` with `LabelComponent`. Use `inline: true` instead.") do |corrector| corrector.replace(pair, "inline: true") end end end end |