diff options
| author | Mike McQuaid | 2017-08-01 11:39:01 +0100 |
|---|---|---|
| committer | GitHub | 2017-08-01 11:39:01 +0100 |
| commit | f4983ab16b01776f57cc8665df1bc3421c0c4683 (patch) | |
| tree | 38ec5e272d3b9dc2d32b7ab4d73438b719c759b0 /Library/Homebrew/rubocops/extend | |
| parent | 43d68b6dda55c89a2f8cced5f874e866df7981c3 (diff) | |
| parent | c575f34d5fe802962bfb2749a00053ad3561da55 (diff) | |
| download | brew-f4983ab16b01776f57cc8665df1bc3421c0c4683.tar.bz2 | |
Merge pull request #2975 from GauthamGoli/audit_urls_rubocop_strict
audit: Port audit_urls strict rules to rubocop, add tests, autocorrect
Diffstat (limited to 'Library/Homebrew/rubocops/extend')
| -rw-r--r-- | Library/Homebrew/rubocops/extend/formula_cop.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index e42d6ee19..4be0c0fe3 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -37,6 +37,20 @@ module RuboCop match_object end + # Yields to block when there is a match + # Parameters: urls : Array of url/mirror method call nodes + # regex: regex pattern to match urls + def audit_urls(urls, regex) + urls.each do |url_node| + url_string_node = parameters(url_node).first + url_string = string_content(url_string_node) + match_object = regex_match_group(url_string_node, regex) + next unless match_object + offending_node(url_string_node.parent) + yield match_object, url_string + end + end + # Returns all string nodes among the descendants of given node def find_strings(node) return [] if node.nil? |
