diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 9af74e5389..9c2ced48c8 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -95,7 +95,7 @@ module Homebrew odie "--only-cops/--except-cops and --strict/--only cannot be used simultaneously!" end - options = { fix: args.fix?, realpath: true } + options = { fix: args.fix? } if only_cops options[:only_cops] = only_cops diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index 898883576f..0cb0d59806 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -6,19 +6,17 @@ module Homebrew # Checks style for a list of files, printing simple RuboCop output. # Returns true if violations were found, false otherwise. - def check_style_and_print(files, options = {}) - check_style_impl(files, :print, options) + def check_style_and_print(files, **options) + check_style_impl(files, :print, **options) end # Checks style for a list of files, returning results as a RubocopResults # object parsed from its JSON output. - def check_style_json(files, options = {}) - check_style_impl(files, :json, options) + def check_style_json(files, **options) + check_style_impl(files, :json, **options) end - def check_style_impl(files, output_type, options = {}) - fix = options[:fix] - + def check_style_impl(files, output_type, fix: false, except_cops: nil, only_cops: nil) Homebrew.install_bundler_gems! require "rubocop" require "rubocops" @@ -34,22 +32,22 @@ module Homebrew args += ["--extra-details", "--display-cop-names"] if ARGV.verbose? - if options[:except_cops] - options[:except_cops].map! { |cop| RuboCop::Cop::Cop.registry.qualified_cop_name(cop.to_s, "") } - cops_to_exclude = options[:except_cops].select do |cop| + if except_cops + except_cops.map! { |cop| RuboCop::Cop::Cop.registry.qualified_cop_name(cop.to_s, "") } + cops_to_exclude = except_cops.select do |cop| RuboCop::Cop::Cop.registry.names.include?(cop) || RuboCop::Cop::Cop.registry.departments.include?(cop.to_sym) end args << "--except" << cops_to_exclude.join(",") unless cops_to_exclude.empty? - elsif options[:only_cops] - options[:only_cops].map! { |cop| RuboCop::Cop::Cop.registry.qualified_cop_name(cop.to_s, "") } - cops_to_include = options[:only_cops].select do |cop| + elsif only_cops + only_cops.map! { |cop| RuboCop::Cop::Cop.registry.qualified_cop_name(cop.to_s, "") } + cops_to_include = only_cops.select do |cop| RuboCop::Cop::Cop.registry.names.include?(cop) || RuboCop::Cop::Cop.registry.departments.include?(cop.to_sym) end - odie "RuboCops #{options[:only_cops].join(",")} were not found" if cops_to_include.empty? + odie "RuboCops #{only_cops.join(",")} were not found" if cops_to_include.empty? args << "--only" << cops_to_include.join(",") end @@ -168,8 +166,8 @@ module Homebrew "[Corrected] " if corrected? end - def to_s(options = {}) - if options[:display_cop_name] + def to_s(display_cop_name: false) + if display_cop_name "#{severity_code}: #{location.to_short_s}: #{cop_name}: " \ "#{Tty.green}#{correction_status}#{Tty.reset}#{message}" else diff --git a/Library/Homebrew/test/cmd/style_spec.rb b/Library/Homebrew/test/cmd/style_spec.rb index d443afde92..0dcb681702 100644 --- a/Library/Homebrew/test/cmd/style_spec.rb +++ b/Library/Homebrew/test/cmd/style_spec.rb @@ -62,8 +62,10 @@ describe "brew style" do end end EOS - options = { fix: true, only_cops: ["NewFormulaAudit/DependencyOrder"], realpath: true } - rubocop_result = Homebrew::Style.check_style_json([formula], options) + rubocop_result = Homebrew::Style.check_style_json( + [formula], + fix: true, only_cops: ["NewFormulaAudit/DependencyOrder"], + ) offense_string = rubocop_result.file_offenses(formula.realpath).first.to_s expect(offense_string).to match(/\[Corrected\]/) end