Apply suggestions from code review

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
nandahkrishna 2021-03-04 23:54:25 +05:30
parent ab0e427d3e
commit 8ddf9b37bd
No known key found for this signature in database
GPG Key ID: 067E5FCD58ADF3AA
3 changed files with 67 additions and 65 deletions

View File

@ -40,14 +40,14 @@ module Homebrew
raise UsageError, "`--limit` must be used with either `--formula` or `--cask`." raise UsageError, "`--limit` must be used with either `--formula` or `--cask`."
end end
formulae_and_casks = formulae_and_casks = if args.formula?
if args.formula?
args.named.to_formulae args.named.to_formulae
elsif args.cask? elsif args.cask?
args.named.to_casks args.named.to_casks
else else
args.named.to_formulae_and_casks args.named.to_formulae_and_casks
end&.sort_by do |formula_or_cask| end
formulae_and_casks = formulae_and_casks&.sort_by do |formula_or_cask|
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
end end
@ -58,19 +58,20 @@ module Homebrew
ambiguous_casks = [] ambiguous_casks = []
if !args.formula? && !args.cask? if !args.formula? && !args.cask?
ambiguous_casks = formulae_and_casks ambiguous_casks = formulae_and_casks.group_by { |item| Livecheck.formula_or_cask_name(item, full_name: true) }
.group_by { |item| Livecheck.formula_or_cask_name(item, full_name: true) } .values
.select { |_name, items| items.length > 1 } .select { |items| items.length > 1 }
.values.flatten .flatten
.select { |item| item.is_a?(Cask::Cask) } .select { |item| item.is_a?(Cask::Cask) }
end end
ambiguous_names = [] ambiguous_names = []
unless args.full_name? unless args.full_name?
ambiguous_names = (formulae_and_casks - ambiguous_casks) ambiguous_names =
.group_by { |item| Livecheck.formula_or_cask_name(item) } (formulae_and_casks - ambiguous_casks).group_by { |item| Livecheck.formula_or_cask_name(item) }
.select { |_name, items| items.length > 1 } .values
.values.flatten .select { |items| items.length > 1 }
.flatten
end end
formulae_and_casks.each_with_index do |formula_or_cask, i| formulae_and_casks.each_with_index do |formula_or_cask, i|
@ -135,7 +136,7 @@ module Homebrew
end end
name = Livecheck.formula_or_cask_name(formula_or_cask) name = Livecheck.formula_or_cask_name(formula_or_cask)
ambiguous_cask = begin ambiguous_cask = begin
formula_or_cask.is_a?(Cask::Cask) && !args.cask? && Formula[name] ? true : false formula_or_cask.is_a?(Cask::Cask) && !args.cask? && Formula[name]
rescue FormulaUnavailableError rescue FormulaUnavailableError
false false
end end

View File

@ -61,8 +61,7 @@ module Homebrew
puts ENV["HOMEBREW_LIVECHECK_WATCHLIST"] if ENV["HOMEBREW_LIVECHECK_WATCHLIST"].present? puts ENV["HOMEBREW_LIVECHECK_WATCHLIST"] if ENV["HOMEBREW_LIVECHECK_WATCHLIST"].present?
end end
formulae_and_casks_to_check = formulae_and_casks_to_check = if args.tap
if args.tap
tap = Tap.fetch(args.tap) tap = Tap.fetch(args.tap)
formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) } formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) }
casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) } casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) }
@ -96,7 +95,8 @@ module Homebrew
end end
else else
raise UsageError, "A watchlist file is required when no arguments are given." raise UsageError, "A watchlist file is required when no arguments are given."
end&.sort_by do |formula_or_cask| end
formulae_and_casks_to_check = formulae_and_casks_to_check.sort_by do |formula_or_cask|
formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
end end

View File

@ -105,19 +105,20 @@ module Homebrew
ambiguous_casks = [] ambiguous_casks = []
if handle_name_conflict if handle_name_conflict
ambiguous_casks = formulae_and_casks_to_check ambiguous_casks = formulae_and_casks_to_check.group_by { |item| formula_or_cask_name(item, full_name: true) }
.group_by { |item| formula_or_cask_name(item, full_name: true) } .values
.select { |_name, items| items.length > 1 } .select { |items| items.length > 1 }
.values.flatten .flatten
.select { |item| item.is_a?(Cask::Cask) } .select { |item| item.is_a?(Cask::Cask) }
end end
ambiguous_names = [] ambiguous_names = []
unless full_name unless full_name
ambiguous_names = (formulae_and_casks_to_check - ambiguous_casks) ambiguous_names =
.group_by { |item| formula_or_cask_name(item) } (formulae_and_casks_to_check - ambiguous_casks).group_by { |item| formula_or_cask_name(item) }
.select { |_name, items| items.length > 1 } .values
.values.flatten .select { |items| items.length > 1 }
.flatten
end end
has_a_newer_upstream_version = T.let(false, T::Boolean) has_a_newer_upstream_version = T.let(false, T::Boolean)