2018-02-01 16:06:17 -05:00
|
|
|
#: * `style` [`--fix`] [`--display-cop-names`] [`--only-cops=`<cops>|`--except-cops=`<cops>] [<files>|<taps>|<formulae>]:
|
2016-04-18 17:39:21 -04:00
|
|
|
#: Check formulae or files for conformance to Homebrew style guidelines.
|
|
|
|
#:
|
2018-02-01 16:06:17 -05:00
|
|
|
#: Lists of <files>, <taps> and <formulae> may not be combined. If none are
|
|
|
|
#: provided, `style` will run style checks on the whole Homebrew library,
|
|
|
|
#: including core code and all formulae.
|
2016-04-18 17:39:21 -04:00
|
|
|
#:
|
2018-02-01 16:06:17 -05:00
|
|
|
#: If `--fix` is passed, automatically fix style violations using RuboCop's
|
|
|
|
#: auto-correct feature.
|
2016-04-18 17:39:21 -04:00
|
|
|
#:
|
2018-02-01 16:06:17 -05:00
|
|
|
#: If `--display-cop-names` is passed, include the RuboCop cop name for each
|
|
|
|
#: violation in the output.
|
2016-04-18 17:39:21 -04:00
|
|
|
#:
|
2018-03-25 13:34:57 +01:00
|
|
|
#: If `--rspec` is passed, install and use the RuboCop RSpec gem.
|
|
|
|
#:
|
2018-02-01 16:06:17 -05:00
|
|
|
#: Passing `--only-cops=`<cops> will check for violations of only the listed
|
|
|
|
#: RuboCop <cops>, while `--except-cops=`<cops> will skip checking the listed
|
|
|
|
#: <cops>. For either option <cops> should be a comma-separated list of cop names.
|
2017-05-03 11:33:00 +05:30
|
|
|
#:
|
2016-04-18 17:39:21 -04:00
|
|
|
#: Exits with a non-zero status if any style violations are found.
|
|
|
|
|
2016-11-20 13:00:01 -05:00
|
|
|
require "json"
|
2017-05-29 01:21:36 +02:00
|
|
|
require "open3"
|
2018-06-05 23:19:18 -04:00
|
|
|
require "style"
|
2016-04-18 17:39:21 -04:00
|
|
|
|
2015-01-02 13:36:26 +00:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2015-01-02 13:36:26 +00:00
|
|
|
def style
|
|
|
|
target = if ARGV.named.empty?
|
2016-09-27 18:48:06 +02:00
|
|
|
nil
|
2015-08-06 15:39:08 +08:00
|
|
|
elsif ARGV.named.any? { |file| File.exist? file }
|
|
|
|
ARGV.named
|
2016-09-18 14:28:03 +01:00
|
|
|
elsif ARGV.named.any? { |tap| tap.count("/") == 1 }
|
|
|
|
ARGV.named.map { |tap| Tap.fetch(tap).path }
|
2015-01-02 13:36:26 +00:00
|
|
|
else
|
|
|
|
ARGV.formulae.map(&:path)
|
|
|
|
end
|
|
|
|
|
2017-05-03 11:33:00 +05:30
|
|
|
only_cops = ARGV.value("only-cops").to_s.split(",")
|
|
|
|
except_cops = ARGV.value("except-cops").to_s.split(",")
|
|
|
|
if !only_cops.empty? && !except_cops.empty?
|
|
|
|
odie "--only-cops and --except-cops cannot be used simultaneously!"
|
|
|
|
end
|
|
|
|
|
|
|
|
options = { fix: ARGV.flag?("--fix") }
|
|
|
|
if !only_cops.empty?
|
|
|
|
options[:only_cops] = only_cops
|
|
|
|
elsif !except_cops.empty?
|
|
|
|
options[:except_cops] = except_cops
|
2017-07-03 11:42:16 +05:30
|
|
|
elsif only_cops.empty? && except_cops.empty?
|
2017-07-15 22:40:26 +05:30
|
|
|
options[:except_cops] = %w[FormulaAudit
|
|
|
|
FormulaAuditStrict
|
|
|
|
NewFormulaAudit]
|
2017-05-03 11:33:00 +05:30
|
|
|
end
|
|
|
|
|
2018-06-05 23:19:18 -04:00
|
|
|
Homebrew.failed = Style.check_style_and_print(target, options)
|
2015-01-02 13:36:26 +00:00
|
|
|
end
|
|
|
|
end
|