diff options
| author | Mike McQuaid | 2017-04-18 09:18:55 +0100 |
|---|---|---|
| committer | GitHub | 2017-04-18 09:18:55 +0100 |
| commit | 55c02ae7747bf05eadec95c91497d06ec3dd2ded (patch) | |
| tree | 05ca665c3fce69e0e69058f9cb919dc3d42d6192 /Library/Homebrew | |
| parent | 20ad7f9cf6e69196b224f95e9fce4b8af8a6d284 (diff) | |
| parent | 3f8722c971cedf8b2c66d918fc4dd608bf439009 (diff) | |
| download | brew-55c02ae7747bf05eadec95c91497d06ec3dd2ded.tar.bz2 | |
Merge pull request #2478 from MikeMcQuaid/audit-skip-methods
audit: allow skipping audit methods.
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/dev-cmd/audit.rb | 62 | ||||
| -rw-r--r-- | Library/Homebrew/extend/os/mac/formula_cellar_checks.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/formula_cellar_checks.rb | 22 | ||||
| -rw-r--r-- | Library/Homebrew/formula_installer.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/test/dev-cmd/audit_spec.rb | 26 |
5 files changed, 65 insertions, 59 deletions
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 32ae5362c..8910c6af3 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -1,4 +1,4 @@ -#: * `audit` [`--strict`] [`--fix`] [`--online`] [`--new-formula`] [`--display-cop-names`] [`--display-filename`] [<formulae>]: +#: * `audit` [`--strict`] [`--fix`] [`--online`] [`--new-formula`] [`--display-cop-names`] [`--display-filename`] [`--only=`<method>|`--except=`<method] [<formulae>]: #: Check <formulae> for Homebrew coding style violations. This should be #: run before submitting a new formula. #: @@ -23,6 +23,10 @@ #: If `--display-filename` is passed, every line of output is prefixed with the #: name of the file or formula being audited, to make the output easy to grep. #: +#: If `--only` is passed, only the methods named `audit_<method>` will be run. +#: +#: If `--except` is passed, the methods named `audit_<method>` will not be run. +#: #: `audit` exits with a non-zero status if any errors are found. This is useful, #: for instance, for implementing pre-commit hooks. @@ -728,7 +732,7 @@ class FormulaAuditor } end - spec.patches.each { |p| audit_patch(p) if p.external? } + spec.patches.each { |p| patch_problems(p) if p.external? } end %w[Stable Devel].each do |name| @@ -864,10 +868,10 @@ class FormulaAuditor return if legacy_patches.empty? problem "Use the patch DSL instead of defining a 'patches' method" - legacy_patches.each { |p| audit_patch(p) } + legacy_patches.each { |p| patch_problems(p) } end - def audit_patch(patch) + def patch_problems(patch) case patch.url when /raw\.github\.com/, %r{gist\.github\.com/raw}, %r{gist\.github\.com/.+/raw}, %r{gist\.githubusercontent\.com/.+/raw} @@ -939,7 +943,13 @@ class FormulaAuditor problem "require \"language/go\" is unnecessary unless using `go_resource`s" end - def audit_line(line, _lineno) + def audit_lines + text.without_patch.split("\n").each_with_index do |line, lineno| + line_problems(line, lineno+1) + end + end + + def line_problems(line, _lineno) if line =~ /<(Formula|AmazonWebServicesFormula|ScriptFileFormula|GithubGistFormula)/ problem "Use a space in class inheritance: class Foo < #{$1}" end @@ -1142,11 +1152,11 @@ class FormulaAuditor end if line =~ /depends_on :(.+) (if.+|unless.+)$/ - audit_conditional_dep($1.to_sym, $2, $&) + conditional_dep_problems($1.to_sym, $2, $&) end if line =~ /depends_on ['"](.+)['"] (if.+|unless.+)$/ - audit_conditional_dep($1, $2, $&) + conditional_dep_problems($1, $2, $&) end if line =~ /(Dir\[("[^\*{},]+")\])/ @@ -1234,7 +1244,7 @@ class FormulaAuditor EOS end - def audit_conditional_dep(dep, condition, line) + def conditional_dep_problems(dep, condition, line) quoted_dep = quote_dep(dep) dep = Regexp.escape(dep.to_s) @@ -1250,30 +1260,26 @@ class FormulaAuditor dep.is_a?(Symbol) ? dep.inspect : "'#{dep}'" end - def audit_check_output(output) + def problem_if_output(output) problem(output) if output end def audit - audit_file - audit_formula_name - audit_class - audit_specs - audit_revision_and_version_scheme - audit_homepage - audit_bottle_spec - audit_github_repository - audit_deps - audit_conflicts - audit_options - audit_legacy_patches - audit_text - audit_caveats - text.without_patch.split("\n").each_with_index { |line, lineno| audit_line(line, lineno+1) } - audit_installed - audit_prefix_has_contents - audit_reverse_migration - audit_style + only_audits = ARGV.value("only").to_s.split(",") + except_audits = ARGV.value("except").to_s.split(",") + if !only_audits.empty? && !except_audits.empty? + odie "--only and --except cannot be used simulataneously!" + end + + methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name| + name = audit_method_name.gsub(/^audit_/, "") + if !only_audits.empty? + next unless only_audits.include?(name) + elsif !except_audits.empty? + next if except_audits.include?(name) + end + send(audit_method_name) + end end private diff --git a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb index 5b1c648bf..10379c981 100644 --- a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb +++ b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb @@ -67,7 +67,7 @@ module FormulaCellarChecks checker = LinkageChecker.new(keg, formula) return unless checker.broken_dylibs? - audit_check_output <<-EOS.undent + problem_if_output <<-EOS.undent The installation was broken. Broken dylib links found: #{checker.broken_dylibs.to_a * "\n "} @@ -76,9 +76,9 @@ module FormulaCellarChecks def audit_installed generic_audit_installed - audit_check_output(check_shadowed_headers) - audit_check_output(check_openssl_links) - audit_check_output(check_python_framework_links(formula.lib)) + problem_if_output(check_shadowed_headers) + problem_if_output(check_openssl_links) + problem_if_output(check_python_framework_links(formula.lib)) check_linkage end end diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index 7db5e748b..c4d599296 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -154,17 +154,17 @@ module FormulaCellarChecks end def audit_installed - audit_check_output(check_manpages) - audit_check_output(check_infopages) - audit_check_output(check_jars) - audit_check_output(check_non_libraries) - audit_check_output(check_non_executables(formula.bin)) - audit_check_output(check_generic_executables(formula.bin)) - audit_check_output(check_non_executables(formula.sbin)) - audit_check_output(check_generic_executables(formula.sbin)) - audit_check_output(check_easy_install_pth(formula.lib)) - audit_check_output(check_elisp_dirname(formula.share, formula.name)) - audit_check_output(check_elisp_root(formula.share, formula.name)) + problem_if_output(check_manpages) + problem_if_output(check_infopages) + problem_if_output(check_jars) + problem_if_output(check_non_libraries) + problem_if_output(check_non_executables(formula.bin)) + problem_if_output(check_generic_executables(formula.bin)) + problem_if_output(check_non_executables(formula.sbin)) + problem_if_output(check_generic_executables(formula.sbin)) + problem_if_output(check_easy_install_pth(formula.lib)) + problem_if_output(check_elisp_dirname(formula.share, formula.name)) + problem_if_output(check_elisp_root(formula.share, formula.name)) end alias generic_audit_installed audit_installed diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 017be51dc..0bdcb1661 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -858,15 +858,15 @@ class FormulaInstaller tab.write end - def audit_check_output(output) + def problem_if_output(output) return unless output opoo output @show_summary_heading = true end def audit_installed - audit_check_output(check_env_path(formula.bin)) - audit_check_output(check_env_path(formula.sbin)) + problem_if_output(check_env_path(formula.bin)) + problem_if_output(check_env_path(formula.sbin)) super end diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index a6bb22837..8a8096849 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -303,7 +303,7 @@ describe FormulaAuditor do end end - describe "#audit_line" do + describe "#line_problems" do specify "pkgshare" do fa = formula_auditor "foo", <<-EOS.undent, strict: true class Foo < Formula @@ -311,25 +311,25 @@ describe FormulaAuditor do end EOS - fa.audit_line 'ohai "#{share}/foo"', 3 + fa.line_problems 'ohai "#{share}/foo"', 3 expect(fa.problems.shift).to eq("Use \#{pkgshare} instead of \#{share}/foo") - fa.audit_line 'ohai "#{share}/foo/bar"', 3 + fa.line_problems 'ohai "#{share}/foo/bar"', 3 expect(fa.problems.shift).to eq("Use \#{pkgshare} instead of \#{share}/foo") - fa.audit_line 'ohai share/"foo"', 3 + fa.line_problems 'ohai share/"foo"', 3 expect(fa.problems.shift).to eq('Use pkgshare instead of (share/"foo")') - fa.audit_line 'ohai share/"foo/bar"', 3 + fa.line_problems 'ohai share/"foo/bar"', 3 expect(fa.problems.shift).to eq('Use pkgshare instead of (share/"foo")') - fa.audit_line 'ohai "#{share}/foo-bar"', 3 + fa.line_problems 'ohai "#{share}/foo-bar"', 3 expect(fa.problems).to eq([]) - fa.audit_line 'ohai share/"foo-bar"', 3 + fa.line_problems 'ohai share/"foo-bar"', 3 expect(fa.problems).to eq([]) - fa.audit_line 'ohai share/"bar"', 3 + fa.line_problems 'ohai share/"bar"', 3 expect(fa.problems).to eq([]) end @@ -344,11 +344,11 @@ describe FormulaAuditor do end EOS - fa.audit_line 'ohai "#{share}/foolibc++"', 3 + fa.line_problems 'ohai "#{share}/foolibc++"', 3 expect(fa.problems.shift) .to eq("Use \#{pkgshare} instead of \#{share}/foolibc++") - fa.audit_line 'ohai share/"foolibc++"', 3 + fa.line_problems 'ohai share/"foolibc++"', 3 expect(fa.problems.shift) .to eq('Use pkgshare instead of (share/"foolibc++")') end @@ -360,7 +360,7 @@ describe FormulaAuditor do end EOS - fa.audit_line "class Foo<Formula", 1 + fa.line_problems "class Foo<Formula", 1 expect(fa.problems.shift) .to eq("Use a space in class inheritance: class Foo < Formula") end @@ -368,10 +368,10 @@ describe FormulaAuditor do specify "default template" do fa = formula_auditor "foo", "class Foo < Formula; url '/foo-1.0.tgz'; end" - fa.audit_line '# system "cmake", ".", *std_cmake_args', 3 + fa.line_problems '# system "cmake", ".", *std_cmake_args', 3 expect(fa.problems.shift).to eq("Commented cmake call found") - fa.audit_line "# PLEASE REMOVE", 3 + fa.line_problems "# PLEASE REMOVE", 3 expect(fa.problems.shift).to eq("Please remove default template comments") end end |
