Class: RuboCop::Cop::Cask::UrlLegacyCommaSeparators

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
OnUrlStanza
Defined in:
rubocops/cask/url_legacy_comma_separators.rb

Overview

This cop checks for version.before_comma and version.after_comma

Constant Summary collapse

MSG_CSV =
"Use 'version.csv.first' instead of 'version.before_comma' " \
"and 'version.csv.second' instead of 'version.after_comma'"

Instance Method Summary collapse

Methods included from OnUrlStanza

#on_cask

Methods included from CaskHelp

#on_block

Instance Method Details

#on_url_stanza(stanza) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'rubocops/cask/url_legacy_comma_separators.rb', line 18

def on_url_stanza(stanza)
  return if stanza.stanza_node.type == :block

  url_node = stanza.stanza_node.first_argument

  legacy_comma_separator_pattern = /version\.(before|after)_comma/

  url = url_node.source

  return unless url.match?(legacy_comma_separator_pattern)

  corrected_url = url.sub("before_comma", "csv.first")&.sub("after_comma", "csv.second")

  add_offense(url_node.loc.expression, message: format(MSG_CSV, url: url)) do |corrector|
    corrector.replace(url_node.source_range, corrected_url)
  end
end