diff --git a/Library/Homebrew/.simplecov b/Library/Homebrew/.simplecov index aa76087f47..9bdc0df93f 100755 --- a/Library/Homebrew/.simplecov +++ b/Library/Homebrew/.simplecov @@ -45,8 +45,9 @@ SimpleCov.start do else command_name "#{command_name} (#{$PROCESS_ID})" + excludes = ["test", "vendor"] subdirs = Dir.chdir(SimpleCov.root) { Dir.glob("*") } - .reject { |d| d.end_with?(".rb") || ["test", "vendor"].include?(d) } + .reject { |d| d.end_with?(".rb") || excludes.include?(d) } .map { |d| "#{d}/**/*.rb" }.join(",") # Not using this during integration tests makes the tests 4x times faster diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index e6d17348d5..9cce7ed341 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -85,9 +85,10 @@ module Cask # :launchctl must come before :quit/:signal for cases where app would instantly re-launch def uninstall_launchctl(*services, command: nil, **_) + booleans = [false, true] services.each do |service| ohai "Removing launchctl service #{service}" - [false, true].each do |with_sudo| + booleans.each do |with_sudo| plist_status = command.run( "/bin/launchctl", args: ["list", service], diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 49a632c8de..39d6d7d3ed 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -204,7 +204,8 @@ module Cask end add_error "at least one name stanza is required" if cask.name.empty? # TODO: specific DSL knowledge should not be spread around in various files like this - installable_artifacts = cask.artifacts.reject { |k| [:uninstall, :zap].include?(k) } + rejected_artifacts = [:uninstall, :zap] + installable_artifacts = cask.artifacts.reject { |k| rejected_artifacts.include?(k) } add_error "at least one activatable artifact stanza is required" if installable_artifacts.empty? end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 59c13f63e1..a6bbd70544 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -893,8 +893,9 @@ module Homebrew bin_names += dir.children.map(&:basename).map(&:to_s) end + shell_commands = ["system", "shell_output", "pipe_output"] bin_names.each do |name| - ["system", "shell_output", "pipe_output"].each do |cmd| + shell_commands.each do |cmd| if text.to_s.match?(/test do.*#{cmd}[(\s]+['"]#{Regexp.escape(name)}[\s'"]/m) problem %Q(fully scope test #{cmd} calls, e.g. #{cmd} "\#{bin}/#{name}") end diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index e5168bd931..9574a1ba91 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -453,13 +453,14 @@ module Homebrew end end + any_cellars = ["any", "any_skip_relocation"] bottles_hash.each do |formula_name, bottle_hash| ohai formula_name bottle = BottleSpecification.new bottle.root_url bottle_hash["bottle"]["root_url"] cellar = bottle_hash["bottle"]["cellar"] - cellar = cellar.to_sym if ["any", "any_skip_relocation"].include?(cellar) + cellar = cellar.to_sym if any_cellars.include?(cellar) bottle.cellar cellar bottle.prefix bottle_hash["bottle"]["prefix"] bottle.rebuild bottle_hash["bottle"]["rebuild"] @@ -478,14 +479,14 @@ module Homebrew update_or_add = "update" if args.keep_old? mismatches = [] + valid_keys = %w[root_url prefix cellar rebuild sha1 sha256] bottle_block_contents = s.inreplace_string[/ bottle do(.+?)end\n/m, 1] bottle_block_contents.lines.each do |line| line = line.strip next if line.empty? key, old_value_original, _, tag = line.split " ", 4 - valid_key = %w[root_url prefix cellar rebuild sha1 sha256].include? key - next unless valid_key + next unless valid_keys.include?(key) old_value = old_value_original.to_s.delete "'\"" old_value = old_value.to_s.delete ":" if key != "root_url" diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index fbcc9eaf2a..a8ac5d5a2a 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -306,6 +306,11 @@ module Homebrew method_name end + CUSTOM_IMPLEMENTATIONS = %w[ + HOMEBREW_MAKE_JOBS + HOMEBREW_CASK_OPTS + ].freeze + ENVS.each do |env, hash| method_name = env_method_name(env, hash) env = env.to_s @@ -316,7 +321,7 @@ module Homebrew end elsif hash[:default].present? # Needs a custom implementation. - next if ["HOMEBREW_MAKE_JOBS", "HOMEBREW_CASK_OPTS"].include?(env) + next if CUSTOM_IMPLEMENTATIONS.include?(env) define_method(method_name) do ENV[env].presence || hash.fetch(:default).to_s diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index 4bed3fc569..7c71590d28 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -154,7 +154,9 @@ module FormulaCellarChecks # Emacs itself can do what it wants return if name == "emacs" - elisps = (share/"emacs/site-lisp").children.select { |file| %w[.el .elc].include? file.extname } + elisps = (share/"emacs/site-lisp").children.select do |file| + Keg::ELISP_EXTENSIONS.include? file.extname + end return if elisps.empty? <<~EOS diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index d2b3afc72d..8c8140190c 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -122,6 +122,10 @@ class Keg mime-info pixmaps sounds postgresql ].freeze + ELISP_EXTENSIONS = %w[.el .elc].freeze + PYC_EXTENSIONS = %w[.pyc .pyo].freeze + LIBTOOL_EXTENSIONS = %w[.la .lai].freeze + # Given an array of kegs, this method will try to find some other kegs # that depend on them. If it does, it returns: # @@ -423,7 +427,7 @@ class Keg def elisp_installed? return false unless (path/"share/emacs/site-lisp"/name).exist? - (path/"share/emacs/site-lisp"/name).children.any? { |f| %w[.el .elc].include? f.extname } + (path/"share/emacs/site-lisp"/name).children.any? { |f| ELISP_EXTENSIONS.include? f.extname } end def version @@ -559,7 +563,7 @@ class Keg end def delete_pyc_files! - find { |pn| pn.delete if %w[.pyc .pyo].include?(pn.extname) } + find { |pn| pn.delete if PYC_EXTENSIONS.include?(pn.extname) } find { |pn| FileUtils.rm_rf pn if pn.basename.to_s == "__pycache__" } end @@ -652,7 +656,7 @@ class Keg # Don't link pyc or pyo files because Python overwrites these # cached object files and next time brew wants to link, the # file is in the way. - Find.prune if %w[.pyc .pyo].include?(src.extname) && src.to_s.include?("/site-packages/") + Find.prune if PYC_EXTENSIONS.include?(src.extname) && src.to_s.include?("/site-packages/") case yield src.relative_path_from(root) when :skip_file, nil diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index bc9d32b879..1bdf422dca 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -170,7 +170,7 @@ class Keg libtool_files = [] path.find do |pn| - next if pn.symlink? || pn.directory? || ![".la", ".lai"].include?(pn.extname) + next if pn.symlink? || pn.directory? || !Keg::LIBTOOL_EXTENSIONS.include?(pn.extname) libtool_files << pn end diff --git a/Library/Homebrew/rubocops/deprecate_disable.rb b/Library/Homebrew/rubocops/deprecate_disable.rb index e767c39330..79f21dcfb4 100644 --- a/Library/Homebrew/rubocops/deprecate_disable.rb +++ b/Library/Homebrew/rubocops/deprecate_disable.rb @@ -37,6 +37,8 @@ module RuboCop # This cop audits deprecate! reason class DeprecateDisableReason < FormulaCop + PUNCTUATION_MARKS = %w[. ! ?].freeze + def audit_formula(_node, _class_node, _parent_class_node, body_node) [:deprecate!, :disable!].each do |method| node = find_node_method_by_name(body_node, method) @@ -53,7 +55,7 @@ module RuboCop problem "Do not start the reason with `it`" if reason_string.start_with?("it ") - problem "Do not end the reason with a punctuation mark" if %w[. ! ?].include?(reason_string[-1]) + problem "Do not end the reason with a punctuation mark" if PUNCTUATION_MARKS.include?(reason_string[-1]) end next if reason_found @@ -73,7 +75,7 @@ module RuboCop lambda do |corrector| reason = string_content(node) reason = reason[3..] if reason.start_with?("it ") - reason.chop! if %w[. ! ?].include?(reason[-1]) + reason.chop! if PUNCTUATION_MARKS.include?(reason[-1]) corrector.replace(node.source_range, "\"#{reason}\"") end end diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index ea3abd0ea5..32cfd2e8ac 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -178,6 +178,7 @@ module Homebrew json = json_result!(result) # Convert to same format as RuboCop offenses. + severity_hash = { "style" => "refactor", "info" => "convention" } json.group_by { |v| v["file"] } .map do |k, v| { @@ -188,7 +189,7 @@ module Homebrew o["cop_name"] = "SC#{o.delete("code")}" level = o.delete("level") - o["severity"] = { "style" => "refactor", "info" => "convention" }.fetch(level, level) + o["severity"] = severity_hash.fetch(level, level) line = o.delete("line") column = o.delete("column") diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 0d6f66eb51..f14b4e6387 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -433,9 +433,10 @@ module GitHub result = open_graphql(query, scopes: ["user:email"]) reviews = result["repository"]["pullRequest"]["reviews"]["nodes"] + valid_associations = %w[MEMBER OWNER] reviews.map do |r| next if commit.present? && commit != r["commit"]["oid"] - next unless %w[MEMBER OWNER].include? r["authorAssociation"] + next unless valid_associations.include? r["authorAssociation"] email = if r["author"]["email"].blank? "#{r["author"]["databaseId"]}+#{r["author"]["login"]}@users.noreply.github.com"