audit: add --new-formula option.

Rather than nudge people to run `--strict` and then ignore some of the
results sometimes (e.g. GitHub repository notability) instead add a
dedicated `--new-formula` option that implies this is a one-time
advisory check.
This commit is contained in:
Mike McQuaid 2016-08-02 10:59:39 +01:00
parent ebe8b8d328
commit 0302a6bc7c
5 changed files with 27 additions and 21 deletions

View File

@ -1,15 +1,19 @@
#: * `audit` [`--strict`] [`--online`] [`--display-cop-names`] [`--display-filename`] [<formulae>]: #: * `audit` [`--strict`] [`--online`] [`--new-formula`] [`--display-cop-names`] [`--display-filename`] [<formulae>]:
#: Check <formulae> for Homebrew coding style violations. This should be #: Check <formulae> for Homebrew coding style violations. This should be
#: run before submitting a new formula. #: run before submitting a new formula.
#: #:
#: If no <formulae> are provided, all of them are checked. #: If no <formulae> are provided, all of them are checked.
#: #:
#: If `--strict` is passed, additional checks are run, including RuboCop #: If `--strict` is passed, additional checks are run, including RuboCop
#: style checks. This should be used when creating new formulae. #: style checks.
#: #:
#: If `--online` is passed, additional slower checks that require a network #: If `--online` is passed, additional slower checks that require a network
#: connection are run. This should be used when creating for new formulae. #: connection are run.
#: #
#: If `--new-formula` is passed, various additional checks are run that check
#: if a new formula is eligable for Homebrew. This should be used when creating
#: new formulae and implies `--strict` and `--online`.
#
#: If `--display-cop-names` is passed, the RuboCop cop name for each violation #: If `--display-cop-names` is passed, the RuboCop cop name for each violation
#: is included in the output. #: is included in the output.
#: #:
@ -43,9 +47,10 @@ module Homebrew
formula_count = 0 formula_count = 0
problem_count = 0 problem_count = 0
strict = ARGV.include? "--strict" new_formula = ARGV.include? "--new-formula"
strict = new_formula || ARGV.include?("--strict")
style = strict && RUBY_2_OR_LATER style = strict && RUBY_2_OR_LATER
online = ARGV.include? "--online" online = new_formula || ARGV.include?("--online")
ENV.activate_extensions! ENV.activate_extensions!
ENV.setup_build_environment ENV.setup_build_environment
@ -63,7 +68,7 @@ module Homebrew
end end
ff.each do |f| ff.each do |f|
options = { :strict => strict, :online => online } options = { :new_formula => new_formula, :strict => strict, :online => online }
options[:style_offenses] = style_results.file_offenses(f.path) if style options[:style_offenses] = style_results.file_offenses(f.path) if style
fa = FormulaAuditor.new(f, options) fa = FormulaAuditor.new(f, options)
fa.audit fa.audit
@ -150,6 +155,7 @@ class FormulaAuditor
def initialize(formula, options = {}) def initialize(formula, options = {})
@formula = formula @formula = formula
@new_formula = !!options[:new_formula]
@strict = !!options[:strict] @strict = !!options[:strict]
@online = !!options[:online] @online = !!options[:online]
# Accept precomputed style offense results, for efficiency # Accept precomputed style offense results, for efficiency
@ -534,6 +540,7 @@ class FormulaAuditor
def audit_github_repository def audit_github_repository
return unless @online return unless @online
return unless @new_formula
regex = %r{https?://github\.com/([^/]+)/([^/]+)/?.*} regex = %r{https?://github\.com/([^/]+)/([^/]+)/?.*}
_, user, repo = *regex.match(formula.stable.url) if formula.stable _, user, repo = *regex.match(formula.stable.url) if formula.stable

View File

@ -85,7 +85,7 @@ module Homebrew
fc.generate! fc.generate!
puts "Please `brew audit --strict #{fc.name}` before submitting, thanks." puts "Please `brew audit --new-formula #{fc.name}` before submitting, thanks."
exec_editor fc.path exec_editor fc.path
end end

View File

@ -445,7 +445,7 @@ module Homebrew
fetch_args << "--force" if ARGV.include? "--cleanup" fetch_args << "--force" if ARGV.include? "--cleanup"
audit_args = [formula_name] audit_args = [formula_name]
audit_args << "--strict" << "--online" if @added_formulae.include? formula_name audit_args << "--new-formula" if @added_formulae.include? formula_name
if formula.stable if formula.stable
unless satisfied_requirements?(formula, :stable) unless satisfied_requirements?(formula, :stable)

View File

@ -39,18 +39,20 @@ If no search term is given, all locally available formulae are listed.</p></dd>
Read more at <a href="https://git.io/brew-analytics" data-bare-link="true">https://git.io/brew-analytics</a>.</p></dd> Read more at <a href="https://git.io/brew-analytics" data-bare-link="true">https://git.io/brew-analytics</a>.</p></dd>
<dt><code>analytics</code> (<code>on</code>|<code>off</code>)</dt><dd><p>Turn on/off Homebrew's analytics.</p></dd> <dt><code>analytics</code> (<code>on</code>|<code>off</code>)</dt><dd><p>Turn on/off Homebrew's analytics.</p></dd>
<dt><code>analytics</code> <code>regenerate-uuid</code></dt><dd><p>Regenerate UUID used in Homebrew's analytics.</p></dd> <dt><code>analytics</code> <code>regenerate-uuid</code></dt><dd><p>Regenerate UUID used in Homebrew's analytics.</p></dd>
<dt><code>audit</code> [<code>--strict</code>] [<code>--online</code>] [<code>--display-cop-names</code>] [<code>--display-filename</code>] [<var>formulae</var>]</dt><dd><p>Check <var>formulae</var> for Homebrew coding style violations. This should be <dt><code>audit</code> [<code>--strict</code>] [<code>--online</code>] [<code>--new-formula</code>] [<code>--display-cop-names</code>] [<code>--display-filename</code>] [<var>formulae</var>]</dt><dd><p>Check <var>formulae</var> for Homebrew coding style violations. This should be
run before submitting a new formula.</p> run before submitting a new formula.</p>
<p>If no <var>formulae</var> are provided, all of them are checked.</p> <p>If no <var>formulae</var> are provided, all of them are checked.</p>
<p>If <code>--strict</code> is passed, additional checks are run, including RuboCop <p>If <code>--strict</code> is passed, additional checks are run, including RuboCop
style checks. This should be used when creating new formulae.</p> style checks.</p>
<p>If <code>--online</code> is passed, additional slower checks that require a network <p>If <code>--online</code> is passed, additional slower checks that require a network
connection are run. This should be used when creating for new formulae.</p> connection are run.
If <code>--new-formula</code> is passed, various additional checks are run that check
<p>If <code>--display-cop-names</code> is passed, the RuboCop cop name for each violation if a new formula is eligable for Homebrew. This should be used when creating
new formulae and implies <code>--strict</code> and <code>--online</code>.
If <code>--display-cop-names</code> is passed, the RuboCop cop name for each violation
is included in the output.</p> is included in the output.</p>
<p>If <code>--display-filename</code> is passed, every line of output is prefixed with the <p>If <code>--display-filename</code> is passed, every line of output is prefixed with the

View File

@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "BREW" "1" "July 2016" "Homebrew" "brew" .TH "BREW" "1" "August 2016" "Homebrew" "brew"
. .
.SH "NAME" .SH "NAME"
\fBbrew\fR \- The missing package manager for OS X \fBbrew\fR \- The missing package manager for OS X
@ -56,20 +56,17 @@ Turn on/off Homebrew\'s analytics\.
Regenerate UUID used in Homebrew\'s analytics\. Regenerate UUID used in Homebrew\'s analytics\.
. .
.TP .TP
\fBaudit\fR [\fB\-\-strict\fR] [\fB\-\-online\fR] [\fB\-\-display\-cop\-names\fR] [\fB\-\-display\-filename\fR] [\fIformulae\fR] \fBaudit\fR [\fB\-\-strict\fR] [\fB\-\-online\fR] [\fB\-\-new\-formula\fR] [\fB\-\-display\-cop\-names\fR] [\fB\-\-display\-filename\fR] [\fIformulae\fR]
Check \fIformulae\fR for Homebrew coding style violations\. This should be run before submitting a new formula\. Check \fIformulae\fR for Homebrew coding style violations\. This should be run before submitting a new formula\.
. .
.IP .IP
If no \fIformulae\fR are provided, all of them are checked\. If no \fIformulae\fR are provided, all of them are checked\.
. .
.IP .IP
If \fB\-\-strict\fR is passed, additional checks are run, including RuboCop style checks\. This should be used when creating new formulae\. If \fB\-\-strict\fR is passed, additional checks are run, including RuboCop style checks\.
. .
.IP .IP
If \fB\-\-online\fR is passed, additional slower checks that require a network connection are run\. This should be used when creating for new formulae\. If \fB\-\-online\fR is passed, additional slower checks that require a network connection are run\. If \fB\-\-new\-formula\fR is passed, various additional checks are run that check if a new formula is eligable for Homebrew\. This should be used when creating new formulae and implies \fB\-\-strict\fR and \fB\-\-online\fR\. If \fB\-\-display\-cop\-names\fR is passed, the RuboCop cop name for each violation is included in the output\.
.
.IP
If \fB\-\-display\-cop\-names\fR is passed, the RuboCop cop name for each violation is included in the output\.
. .
.IP .IP
If \fB\-\-display\-filename\fR 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 \fB\-\-display\-filename\fR 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\.