80 lines
2.4 KiB
Ruby
Raw Normal View History

2020-11-25 17:03:23 +01:00
# typed: true
# 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
2020-10-20 12:03:48 +02:00
extend T::Sig
2016-09-26 01:44:51 +02:00
module_function
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
2018-11-07 23:44:34 +05:30
def style_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`style` [<options>] [<file>|<tap>|<formula>|<cask>] [<file>|<tap>|<formula>|<cask> ...]
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."
2020-11-29 14:21:06 -05:00
switch "--reset-cache",
description: "Reset the RuboCop cache."
2020-12-13 23:05:08 +09:00
switch "--formula", "--formulae",
description: "Treat all named arguments as formulae."
switch "--cask", "--casks",
description: "Treat all named arguments as casks."
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
2020-12-13 23:05:08 +09:00
conflicts "--formula", "--cask"
2018-11-07 23:44:34 +05:30
conflicts "--only-cops", "--except-cops"
2021-01-10 14:26:40 -05:00
named_args [:formula, :cask, :tap]
2018-11-07 23:44:34 +05:30
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
else
2020-12-17 21:14:18 +09:00
args.named.to_paths
end
2018-11-07 23:44:34 +05:30
only_cops = args.only_cops
except_cops = args.except_cops
options = {
2020-11-29 14:21:06 -05:00
fix: args.fix?,
display_cop_names: args.display_cop_names?,
reset_cache: args.reset_cache?,
debug: args.debug?,
verbose: args.verbose?,
}
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
2020-11-29 22:35:45 +01:00
else
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