From ff0ea323b5b3b9491f78d0c53e240ec777b9ad95 Mon Sep 17 00:00:00 2001 From: Adam Vandenberg Date: Tue, 10 Aug 2010 13:04:51 -0700 Subject: [PATCH] brew audit - check used and documented options --- Library/Contributions/examples/brew-audit.rb | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Library/Contributions/examples/brew-audit.rb b/Library/Contributions/examples/brew-audit.rb index 84334a95b8..916f93d8f2 100755 --- a/Library/Contributions/examples/brew-audit.rb +++ b/Library/Contributions/examples/brew-audit.rb @@ -60,6 +60,40 @@ def audit_formula_text text return problems end +def audit_formula_options f, text + problems = [] + + # Find possible options + options = [] + text.scan(/ARGV\.include\?[ ]*\(?(['"])(.+?)\1/) { |m| options << m[1] } + options.reject! {|o| o.include? "#"} + options.uniq! + + # Find documented options + begin + opts = f.options + documented_options = [] + opts.each{ |o| documented_options << o[0] } + documented_options.reject! {|o| o.include? "="} + rescue + documented_options = [] + end + + if options.length > 0 + options.each do |o| + problems << " * Option #{o} is not documented" unless documented_options.include? o + end + end + + if documented_options.length > 0 + documented_options.each do |o| + problems << " * Option #{o} is unused" unless options.include? o + end + end + + return problems +end + def audit_some_formulae ff.each do |f| problems = [] @@ -82,6 +116,7 @@ def audit_some_formulae text_without_patch = (text.split("__END__")[0]).strip() problems += audit_formula_text(text_without_patch) + problems += audit_formula_options(f, text_without_patch) unless problems.empty? puts "#{f.name}:"