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, #toplevel_stanzas

Methods included from CaskHelp

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

Methods included from UrlHelper

#audit_url, #audit_urls

Methods included from HelperFunctions

#block_method_called_in_block?, #block_size, #check_precedence, #class_name, #component_precedes?, #end_column, #expression_negated?, #find_all_blocks, #find_block, #find_blocks, #find_const, #find_every_func_call_by_name, #find_every_method_call_by_name, #find_instance_call, #find_instance_method_call, #find_method_calls_by_name, #find_method_def, #find_method_with_args, #find_node_method_by_name, #find_strings, #format_component, #line_number, #line_start_column, #method_called?, #method_called_ever?, #method_name, #node_equals?, #offending_node, #parameters, #parameters_passed?, #problem, #regex_match_group, #size, #source_buffer, #start_column, #string_content

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