Merge pull request #1873 from GauthamGoli/audit_custom_cops
Custom Cops for `brew audit`
This commit is contained in:
commit
674e5f13f8
@ -6,6 +6,11 @@ AllCops:
|
||||
- '**/Casks/**/*'
|
||||
- '**/vendor/**/*'
|
||||
|
||||
require: ./Homebrew/rubocops.rb
|
||||
|
||||
Homebrew/CorrectBottleBlock:
|
||||
Enabled: true
|
||||
|
||||
Metrics/AbcSize:
|
||||
Enabled: false
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#: * `audit` [`--strict`] [`--online`] [`--new-formula`] [`--display-cop-names`] [`--display-filename`] [<formulae>]:
|
||||
#: * `audit` [`--strict`] [`--fix`] [`--online`] [`--new-formula`] [`--display-cop-names`] [`--display-filename`] [<formulae>]:
|
||||
#: Check <formulae> for Homebrew coding style violations. This should be
|
||||
#: run before submitting a new formula.
|
||||
#:
|
||||
@ -7,6 +7,9 @@
|
||||
#: If `--strict` is passed, additional checks are run, including RuboCop
|
||||
#: style checks.
|
||||
#:
|
||||
#: If `--fix` is passed, style violations will be
|
||||
#: automatically fixed using RuboCop's `--auto-correct` feature.
|
||||
#:
|
||||
#: If `--online` is passed, additional slower checks that require a network
|
||||
#: connection are run.
|
||||
#:
|
||||
@ -62,8 +65,9 @@ module Homebrew
|
||||
end
|
||||
|
||||
if strict
|
||||
options = { fix: ARGV.flag?("--fix"), realpath: true }
|
||||
# Check style in a single batch run up front for performance
|
||||
style_results = check_style_json(files, realpath: true)
|
||||
style_results = check_style_json(files, options)
|
||||
end
|
||||
|
||||
ff.each do |f|
|
||||
|
1
Library/Homebrew/rubocops.rb
Normal file
1
Library/Homebrew/rubocops.rb
Normal file
@ -0,0 +1 @@
|
||||
require_relative "./rubocops/bottle_block_cop"
|
36
Library/Homebrew/rubocops/bottle_block_cop.rb
Normal file
36
Library/Homebrew/rubocops/bottle_block_cop.rb
Normal file
@ -0,0 +1,36 @@
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Homebrew
|
||||
class CorrectBottleBlock < Cop
|
||||
MSG = "Use rebuild instead of revision in bottle block".freeze
|
||||
|
||||
def on_block(node)
|
||||
return if block_length(node).zero?
|
||||
method, _args, body = *node
|
||||
_keyword, method_name = *method
|
||||
|
||||
return unless method_name == :bottle
|
||||
check_revision?(body)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def autocorrect(node)
|
||||
lambda do |corrector|
|
||||
correction = node.source.sub("revision", "rebuild")
|
||||
corrector.insert_before(node.source_range, correction)
|
||||
corrector.remove(node.source_range)
|
||||
end
|
||||
end
|
||||
|
||||
def check_revision?(body)
|
||||
body.children.each do |method_call_node|
|
||||
_receiver, method_name, _args = *method_call_node
|
||||
next unless method_name == :revision
|
||||
add_offense(method_call_node, :expression)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -453,7 +453,7 @@ the <code>prefix</code> and <code>repository</code> are the same directory.</p><
|
||||
<h2 id="DEVELOPER-COMMANDS">DEVELOPER COMMANDS</h2>
|
||||
|
||||
<dl>
|
||||
<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
|
||||
<dt><code>audit</code> [<code>--strict</code>] [<code>--fix</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>
|
||||
|
||||
<p>If no <var>formulae</var> are provided, all of them are checked.</p>
|
||||
@ -461,6 +461,9 @@ run before submitting a new formula.</p>
|
||||
<p>If <code>--strict</code> is passed, additional checks are run, including RuboCop
|
||||
style checks.</p>
|
||||
|
||||
<p>If <code>--fix</code> is passed, style violations will be
|
||||
automatically fixed using RuboCop's <code>--auto-correct</code> feature.</p>
|
||||
|
||||
<p>If <code>--online</code> is passed, additional slower checks that require a network
|
||||
connection are run.</p>
|
||||
|
||||
|
@ -625,7 +625,7 @@ Print the version number of Homebrew to standard output and exit\.
|
||||
.SH "DEVELOPER COMMANDS"
|
||||
.
|
||||
.TP
|
||||
\fBaudit\fR [\fB\-\-strict\fR] [\fB\-\-online\fR] [\fB\-\-new\-formula\fR] [\fB\-\-display\-cop\-names\fR] [\fB\-\-display\-filename\fR] [\fIformulae\fR]
|
||||
\fBaudit\fR [\fB\-\-strict\fR] [\fB\-\-fix\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\.
|
||||
.
|
||||
.IP
|
||||
@ -635,6 +635,9 @@ If no \fIformulae\fR are provided, all of them are checked\.
|
||||
If \fB\-\-strict\fR is passed, additional checks are run, including RuboCop style checks\.
|
||||
.
|
||||
.IP
|
||||
If \fB\-\-fix\fR is passed, style violations will be automatically fixed using RuboCop\'s \fB\-\-auto\-correct\fR feature\.
|
||||
.
|
||||
.IP
|
||||
If \fB\-\-online\fR is passed, additional slower checks that require a network connection are run\.
|
||||
.
|
||||
.IP
|
||||
|
Loading…
x
Reference in New Issue
Block a user