aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/rubocops
diff options
context:
space:
mode:
authorMike McQuaid2017-06-25 08:54:59 +0100
committerGitHub2017-06-25 08:54:59 +0100
commitf4cdd7a051d2cc276729e8a670a9d3870611018b (patch)
tree692c6a0f929ab5b8bff21787fb7ba9a8a11af535 /Library/Homebrew/rubocops
parent73d81bb96d550271b3e2e8e62c3c15b99160c15c (diff)
parent2e8275477674c85b0bed5a7cd2f17b9acad6bd5a (diff)
downloadbrew-f4cdd7a051d2cc276729e8a670a9d3870611018b.tar.bz2
Merge pull request #2790 from GauthamGoli/audit_legacy_patches_rubocop
audit: Port audit_legacy_patches method to rubocop and add tests
Diffstat (limited to 'Library/Homebrew/rubocops')
-rw-r--r--Library/Homebrew/rubocops/legacy_patches_cop.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/Library/Homebrew/rubocops/legacy_patches_cop.rb b/Library/Homebrew/rubocops/legacy_patches_cop.rb
new file mode 100644
index 000000000..e569f650e
--- /dev/null
+++ b/Library/Homebrew/rubocops/legacy_patches_cop.rb
@@ -0,0 +1,53 @@
+require_relative "./extend/formula_cop"
+require_relative "../extend/string"
+
+module RuboCop
+ module Cop
+ module FormulaAudit
+ # This cop checks for and audits legacy patches in Formulae
+ class LegacyPatches < FormulaCop
+ def audit_formula(_node, _class_node, _parent_class_node, body)
+ patches_node = find_method_def(body, :patches)
+ return if patches_node.nil?
+ legacy_patches = find_strings(patches_node)
+ problem "Use the patch DSL instead of defining a 'patches' method"
+ legacy_patches.each { |p| patch_problems(p) }
+ end
+
+ def patch_problems(patch)
+ patch_url = string_content(patch)
+ gh_patch_patterns = Regexp.union([%r{/raw\.github\.com/},
+ %r{gist\.github\.com/raw},
+ %r{gist\.github\.com/.+/raw},
+ %r{gist\.githubusercontent\.com/.+/raw}])
+ if regex_match_group(patch, gh_patch_patterns)
+ unless patch_url =~ /[a-fA-F0-9]{40}/
+ problem "GitHub/Gist patches should specify a revision:\n#{patch_url}"
+ end
+ end
+
+ gh_patch_diff_pattern = %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}
+ if match_obj = regex_match_group(patch, gh_patch_diff_pattern)
+ problem <<-EOS.undent
+ use GitHub pull request URLs:
+ https://github.com/#{match_obj[1]}/#{match_obj[2]}/pull/#{match_ojb[3]}.patch
+ Rather than patch-diff:
+ #{patch_url}
+ EOS
+ end
+
+ if regex_match_group(patch, %r{macports/trunk})
+ problem "MacPorts patches should specify a revision instead of trunk:\n#{patch_url}"
+ end
+
+ if regex_match_group(patch, %r{^http://trac\.macports\.org})
+ problem "Patches from MacPorts Trac should be https://, not http:\n#{patch_url}"
+ end
+
+ return unless regex_match_group(patch, %r{^http://bugs\.debian\.org})
+ problem "Patches from Debian should be https://, not http:\n#{patch_url}"
+ end
+ end
+ end
+ end
+end