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

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

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

This cop checks for version.before_comma and version.after_comma.

Constant Summary collapse

MSG_CSV =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"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

#inner_stanzas, #on_block, #on_cask, #on_cask_stanza_block, #on_system_methods

Instance Method Details

#on_url_stanza(stanza) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



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

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:)) do |corrector|
    corrector.replace(url_node.source_range, corrected_url)
  end
end