65 lines
2.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "json"
2017-05-29 01:21:36 +02:00
require "open3"
require "style"
2019-04-17 18:25:08 +09:00
require "cli/parser"
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
2018-11-07 23:44:34 +05:30
def style_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`style` [<options>] [<file>|<tap>|<formula>]
2018-11-07 23:44:34 +05:30
Check formulae or files for conformance to Homebrew style guidelines.
Lists of <file>, <tap> and <formula> may not be combined. If none are
2018-11-07 23:44:34 +05:30
provided, `style` will run style checks on the whole Homebrew library,
including core code and all formulae.
EOS
switch "--fix",
2019-04-30 08:44:35 +01:00
description: "Fix style violations automatically using RuboCop's auto-correct feature."
2018-11-07 23:44:34 +05:30
switch "--display-cop-names",
2019-04-30 08:44:35 +01:00
description: "Include the RuboCop cop name for each violation in the output."
2018-11-07 23:44:34 +05:30
comma_array "--only-cops",
2019-04-30 08:44:35 +01:00
description: "Specify a comma-separated <cops> list to check for violations of only the "\
"listed RuboCop cops."
2018-11-07 23:44:34 +05:30
comma_array "--except-cops",
2019-04-30 08:44:35 +01:00
description: "Specify a comma-separated <cops> list to skip checking for violations of the "\
"listed RuboCop cops."
2020-07-30 18:40:10 +02:00
2018-11-07 23:44:34 +05:30
conflicts "--only-cops", "--except-cops"
end
end
def style
2020-07-30 18:40:10 +02:00
args = style_args.parse
2018-11-07 23:44:34 +05:30
target = if args.no_named?
nil
elsif args.named.any? { |file| File.exist? file }
args.named
elsif args.named.any? { |tap| tap.count("/") == 1 }
args.named.map { |tap| Tap.fetch(tap).path }
else
args.formulae_paths
end
2018-11-07 23:44:34 +05:30
only_cops = args.only_cops
except_cops = args.except_cops
options = { fix: args.fix?, display_cop_names: args.display_cop_names? }
2018-11-07 23:44:34 +05:30
if only_cops
options[:only_cops] = only_cops
2018-11-07 23:44:34 +05:30
elsif except_cops
options[:except_cops] = except_cops
2018-11-07 23:44:34 +05:30
elsif only_cops.nil? && except_cops.nil?
options[:except_cops] = %w[FormulaAuditStrict]
end
2019-10-04 09:19:02 +02:00
Homebrew.failed = !Style.check_style_and_print(target, options)
end
end