Skip to content

Commit 1909d89

Browse files
authored
Merge pull request #12165 from Bo98/http-mirror
rubocops/urls: allow plain HTTP mirrors
2 parents 9908820 + 629dbb7 commit 1909d89

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Library/Homebrew/rubocops/extend/formula.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ def on_class(node)
3535
# @param urls [Array] url/mirror method call nodes
3636
# @param regex [Regexp] pattern to match URLs
3737
def audit_urls(urls, regex)
38-
urls.each do |url_node|
38+
urls.each_with_index do |url_node, index|
3939
url_string_node = parameters(url_node).first
4040
url_string = string_content(url_string_node)
4141
match_object = regex_match_group(url_string_node, regex)
4242
next unless match_object
4343

4444
offending_node(url_string_node.parent)
45-
yield match_object, url_string
45+
yield match_object, url_string, index
4646
end
4747
end
4848

Library/Homebrew/rubocops/urls.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
8383
%r{^http://(?:[^/]*\.)?archive\.org},
8484
%r{^http://(?:[^/]*\.)?freedesktop\.org},
8585
%r{^http://(?:[^/]*\.)?mirrorservice\.org/}])
86-
audit_urls(urls, http_to_https_patterns) do |_, url|
87-
problem "Please use https:// for #{url}"
86+
audit_urls(urls, http_to_https_patterns) do |_, url, index|
87+
# It's fine to have a plain HTTP mirror further down the mirror list.
88+
https_url = url.dup.insert(4, "s")
89+
https_index = nil
90+
audit_urls(urls, https_url) do |_, _, found_https_index|
91+
https_index = found_https_index
92+
end
93+
problem "Please use https:// for #{url}" if !https_index || https_index > index
8894
end
8995

9096
apache_mirror_pattern = %r{^https?://(?:[^/]*\.)?apache\.org/dyn/closer\.(?:cgi|lua)\?path=/?(.*)}i

0 commit comments

Comments
 (0)