aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2017-02-12 13:09:28 +0000
committerGitHub2017-02-12 13:09:28 +0000
commit674e5f13f8e30dedee92abffa882406c883948d9 (patch)
treecfb30fcf22d3baf54daddcd5e626e58c903f2b16 /Library
parent1292a4b219ad6e99a06fdf2a8c623e99a2354710 (diff)
parent5dc358c1b7254aa622504cd98528779caf6dee00 (diff)
downloadbrew-674e5f13f8e30dedee92abffa882406c883948d9.tar.bz2
Merge pull request #1873 from GauthamGoli/audit_custom_cops
Custom Cops for `brew audit`
Diffstat (limited to 'Library')
-rw-r--r--Library/.rubocop.yml5
-rw-r--r--Library/Homebrew/dev-cmd/audit.rb8
-rw-r--r--Library/Homebrew/rubocops.rb1
-rw-r--r--Library/Homebrew/rubocops/bottle_block_cop.rb36
4 files changed, 48 insertions, 2 deletions
diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml
index 29a891e2a..30b9ec81e 100644
--- a/Library/.rubocop.yml
+++ b/Library/.rubocop.yml
@@ -6,6 +6,11 @@ AllCops:
- '**/Casks/**/*'
- '**/vendor/**/*'
+require: ./Homebrew/rubocops.rb
+
+Homebrew/CorrectBottleBlock:
+ Enabled: true
+
Metrics/AbcSize:
Enabled: false
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb
index e3ba46fe7..0e7c11005 100644
--- a/Library/Homebrew/dev-cmd/audit.rb
+++ b/Library/Homebrew/dev-cmd/audit.rb
@@ -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|
diff --git a/Library/Homebrew/rubocops.rb b/Library/Homebrew/rubocops.rb
new file mode 100644
index 000000000..1a28dd213
--- /dev/null
+++ b/Library/Homebrew/rubocops.rb
@@ -0,0 +1 @@
+require_relative "./rubocops/bottle_block_cop"
diff --git a/Library/Homebrew/rubocops/bottle_block_cop.rb b/Library/Homebrew/rubocops/bottle_block_cop.rb
new file mode 100644
index 000000000..55eb55152
--- /dev/null
+++ b/Library/Homebrew/rubocops/bottle_block_cop.rb
@@ -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