From 6f37dc4c413b2d7884aa2d452aa6f36e28087617 Mon Sep 17 00:00:00 2001 From: nandahkrishna Date: Fri, 22 May 2020 15:18:01 +0530 Subject: [PATCH] livecheck: modified urls cop --- Library/Homebrew/rubocops/urls.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/rubocops/urls.rb b/Library/Homebrew/rubocops/urls.rb index 33c1ded388cd5..f0872b3c1f6a1 100644 --- a/Library/Homebrew/rubocops/urls.rb +++ b/Library/Homebrew/rubocops/urls.rb @@ -13,11 +13,12 @@ class Urls < FormulaCop https://downloads.sourceforge.net/project/bittwist/ https://downloads.sourceforge.net/project/launch4j/ https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard/archive/ - https://github.com/obihann/archey-osx/archive/ + https://github.com/obihann/archey-osx https://github.com/sindresorhus/macos-wallpaper/archive/ https://raw.githubusercontent.com/liyanage/macosx-shell-scripts/ https://osxbook.com/book/bonus/chapter8/core/download/gcore https://naif.jpl.nasa.gov/pub/naif/toolkit/C/MacIntel_OSX_AppleC_64bit/packages/ + https://artifacts.videolan.org/x264/release-macos/ ].freeze # These are formulae that, sadly, require an upstream binary to bootstrap. @@ -48,6 +49,12 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) urls = find_every_func_call_by_name(body_node, :url) mirrors = find_every_func_call_by_name(body_node, :mirror) + # Identify livecheck urls, to skip some checks for them + livecheck_url = if (livecheck = find_every_func_call_by_name(body_node, :livecheck).first) && + (livecheck_url = find_every_func_call_by_name(livecheck.parent, :url).first) + string_content(parameters(livecheck_url).first) + end + # GNU urls; doesn't apply to mirrors gnu_pattern = %r{^(?:https?|ftp)://ftpmirror.gnu.org/(.*)} audit_urls(urls, gnu_pattern) do |match, url| @@ -63,6 +70,8 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) apache_pattern = %r{^https?://(?:[^/]*\.)?apache\.org/(?:dyn/closer\.cgi\?path=/?|dist/)(.*)}i audit_urls(urls, apache_pattern) do |match, url| + next if url == livecheck_url + problem "#{url} should be `https://www.apache.org/dyn/closer.lua?path=#{match[1]}`" end @@ -158,7 +167,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node) problem "Don't use /download in SourceForge urls (url is #{url})." if url.end_with?("/download") - if url.match?(%r{^https?://sourceforge\.}) + if url.match?(%r{^https?://sourceforge\.}) && url != livecheck_url problem "Use https://downloads.sourceforge.net to get geolocation (url is #{url})." end