From 0d04f198d2c8fd4c0782290c8c922c4803821bab Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Thu, 21 Mar 2024 21:44:06 -0700 Subject: [PATCH] Port Homebrew::DevCmd::StyleCmd --- Library/Homebrew/dev-cmd/style.rb | 119 ++++++++++---------- Library/Homebrew/test/dev-cmd/style_spec.rb | 3 +- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/Library/Homebrew/dev-cmd/style.rb b/Library/Homebrew/dev-cmd/style.rb index 9741823010..58de7af85b 100644 --- a/Library/Homebrew/dev-cmd/style.rb +++ b/Library/Homebrew/dev-cmd/style.rb @@ -1,75 +1,74 @@ -# typed: true +# typed: strict # frozen_string_literal: true +require "abstract_command" require "json" require "open3" require "style" require "cli/parser" module Homebrew - module_function + module DevCmd + class StyleCmd < AbstractCommand + cmd_args do + description <<~EOS + Check formulae or files for conformance to Homebrew style guidelines. - sig { returns(CLI::Parser) } - def style_args - Homebrew::CLI::Parser.new do - description <<~EOS - Check formulae or files for conformance to Homebrew style guidelines. + Lists of , and may not be combined. If none are + provided, `style` will run style checks on the whole Homebrew library, + including core code and all formulae. + EOS + switch "--fix", + description: "Fix style violations automatically using RuboCop's auto-correct feature." + switch "--display-cop-names", + description: "Include the RuboCop cop name for each violation in the output.", + hidden: true + switch "--reset-cache", + description: "Reset the RuboCop cache." + switch "--formula", "--formulae", + description: "Treat all named arguments as formulae." + switch "--cask", "--casks", + description: "Treat all named arguments as casks." + comma_array "--only-cops", + description: "Specify a comma-separated list to check for violations of only the " \ + "listed RuboCop cops." + comma_array "--except-cops", + description: "Specify a comma-separated list to skip checking for violations of the " \ + "listed RuboCop cops." - Lists of , and may not be combined. If none are - provided, `style` will run style checks on the whole Homebrew library, - including core code and all formulae. - EOS - switch "--fix", - description: "Fix style violations automatically using RuboCop's auto-correct feature." - switch "--display-cop-names", - description: "Include the RuboCop cop name for each violation in the output.", - hidden: true - switch "--reset-cache", - description: "Reset the RuboCop cache." - switch "--formula", "--formulae", - description: "Treat all named arguments as formulae." - switch "--cask", "--casks", - description: "Treat all named arguments as casks." - comma_array "--only-cops", - description: "Specify a comma-separated list to check for violations of only the " \ - "listed RuboCop cops." - comma_array "--except-cops", - description: "Specify a comma-separated list to skip checking for violations of the " \ - "listed RuboCop cops." + conflicts "--formula", "--cask" + conflicts "--only-cops", "--except-cops" - conflicts "--formula", "--cask" - conflicts "--only-cops", "--except-cops" + named_args [:file, :tap, :formula, :cask], without_api: true + end - named_args [:file, :tap, :formula, :cask], without_api: true + sig { override.void } + def run + target = if args.no_named? + nil + else + args.named.to_paths + end + + only_cops = args.only_cops + except_cops = args.except_cops + + options = { + fix: args.fix?, + reset_cache: args.reset_cache?, + debug: args.debug?, + verbose: args.verbose?, + } + if only_cops + options[:only_cops] = only_cops + elsif except_cops + options[:except_cops] = except_cops + else + options[:except_cops] = %w[FormulaAuditStrict] + end + + Homebrew.failed = !Style.check_style_and_print(target, **options) + end end end - - def style - args = style_args.parse - - target = if args.no_named? - nil - else - args.named.to_paths - end - - only_cops = args.only_cops - except_cops = args.except_cops - - options = { - fix: args.fix?, - reset_cache: args.reset_cache?, - debug: args.debug?, - verbose: args.verbose?, - } - if only_cops - options[:only_cops] = only_cops - elsif except_cops - options[:except_cops] = except_cops - else - options[:except_cops] = %w[FormulaAuditStrict] - end - - Homebrew.failed = !Style.check_style_and_print(target, **options) - end end diff --git a/Library/Homebrew/test/dev-cmd/style_spec.rb b/Library/Homebrew/test/dev-cmd/style_spec.rb index 10e987883a..0b8f2edaf3 100644 --- a/Library/Homebrew/test/dev-cmd/style_spec.rb +++ b/Library/Homebrew/test/dev-cmd/style_spec.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true require "cmd/shared_examples/args_parse" +require "dev-cmd/style" -RSpec.describe "brew style" do +RSpec.describe Homebrew::DevCmd::StyleCmd do it_behaves_like "parseable arguments" end