From ab19242d0484a91ca2b9dac28c8a131be08758d6 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 25 Jan 2012 22:41:53 -0600 Subject: [PATCH] audit: reorganize some checks Signed-off-by: Jack Nagel --- Library/Homebrew/cmd/audit.rb | 42 ++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb index a1a86d2c03..0910d207f0 100755 --- a/Library/Homebrew/cmd/audit.rb +++ b/Library/Homebrew/cmd/audit.rb @@ -199,6 +199,11 @@ def audit_formula_urls f problems << " * The homepage should start with http or https." end + # Google Code homepages should end in a slash + if f.homepage =~ %r[^https?://code\.google\.com/p/[^/]+[^/]$] + problems << " * Google Code homepage should end with a slash." + end + urls = [(f.url rescue nil), (f.head rescue nil)].reject {|p| p.nil?} urls.uniq! # head-only formulae result in duplicate entries @@ -251,6 +256,24 @@ def audit_formula_urls f return problems end +def audit_formula_specs text + problems = [] + + if text =~ /devel .+(url '.+').+(url '.+')/m + problems << " * 'devel' block found before stable 'url'" + end + + if text =~ /devel .+(head '.+')/m + problems << " * 'devel' block found before 'head'" + end + + if text =~ /devel do\s+end/ + problems << " * Empty 'devel' block found" + end + + return problems +end + def audit_formula_instance f problems = [] @@ -275,10 +298,7 @@ def audit_formula_instance f end end - # Google Code homepages should end in a slash - if f.homepage =~ %r[^https?://code\.google\.com/p/[^/]+[^/]$] - problems << " * Google Code homepage should end with a slash." - end + problems += [' * invalid or missing version'] if f.version.to_s.empty? return problems end @@ -310,15 +330,10 @@ module Homebrew extend self problems << " * 'DATA' was found, but no '__END__'" end - problems << " * File should end with a newline" if text =~ /.+\z/ - - problems += [' * invalid or missing version'] if f.version.to_s.empty? - - problems << " * 'devel' block found before stable 'url'" if text =~ /devel .+(url '.+').+(url '.+')/m - - problems << " * 'devel' block found before 'head'" if text =~ /devel .+(head '.+')/m - - problems << " * Empty 'devel' block found" if text =~ /devel do\s+end/ + # files should end with a newline + if text =~ /.+\z/ + problems << " * File should end with a newline" + end # Don't try remaining audits on text in __END__ text_without_patch = (text.split("__END__")[0]).strip() @@ -326,6 +341,7 @@ module Homebrew extend self problems += audit_formula_text(f.name, text_without_patch) problems += audit_formula_options(f, text_without_patch) problems += audit_formula_version(f, text_without_patch) + problems += audit_formula_specs(text_without_patch) unless problems.empty? errors = true