Auto-correct block delimiters.

This commit is contained in:
Markus Reiter 2016-10-23 14:44:14 +02:00
parent 827b48912a
commit 8d15bddedb
15 changed files with 47 additions and 46 deletions

View File

@ -9,6 +9,11 @@ AllCops:
- '**/Casks/**/*' - '**/Casks/**/*'
- '**/vendor/**/*' - '**/vendor/**/*'
Style/BlockDelimiters:
Exclude:
- '**/cask/spec/**/*'
- '**/cask/test/**/*'
# so many of these in formulae but none in here # so many of these in formulae but none in here
Lint/AmbiguousRegexpLiteral: Lint/AmbiguousRegexpLiteral:
Enabled: true Enabled: true

View File

@ -28,15 +28,15 @@ module Hbc
# sources and should be refactored for consistency # sources and should be refactored for consistency
def self.expand_path_strings(path_strings) def self.expand_path_strings(path_strings)
path_strings.map { |path_string| path_strings.map do |path_string|
path_string.start_with?("~") ? Pathname.new(path_string).expand_path : Pathname.new(path_string) path_string.start_with?("~") ? Pathname.new(path_string).expand_path : Pathname.new(path_string)
} end
end end
def self.remove_relative_path_strings(action, path_strings) def self.remove_relative_path_strings(action, path_strings)
relative = path_strings.map { |path_string| relative = path_strings.map do |path_string|
path_string if %r{/\.\.(?:/|\Z)}.match(path_string) || !%r{\A/}.match(path_string) path_string if %r{/\.\.(?:/|\Z)}.match(path_string) || !%r{\A/}.match(path_string)
}.compact end.compact
relative.each do |path_string| relative.each do |path_string|
opoo "Skipping #{action} for relative path #{path_string}" opoo "Skipping #{action} for relative path #{path_string}"
end end
@ -44,9 +44,9 @@ module Hbc
end end
def self.remove_undeletable_path_strings(action, path_strings) def self.remove_undeletable_path_strings(action, path_strings)
undeletable = path_strings.map { |path_string| undeletable = path_strings.map do |path_string|
path_string if MacOS.undeletable?(Pathname.new(path_string)) path_string if MacOS.undeletable?(Pathname.new(path_string))
}.compact end.compact
undeletable.each do |path_string| undeletable.each do |path_string|
opoo "Skipping #{action} for undeletable path #{path_string}" opoo "Skipping #{action} for undeletable path #{path_string}"
end end

View File

@ -6,12 +6,12 @@ module Hbc
begin begin
saved_languages = MacOS.instance_variable_get(:@languages) saved_languages = MacOS.instance_variable_get(:@languages)
languages_blocks.keys.map { |languages| languages_blocks.keys.map do |languages|
ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.join(", ")}" ohai "Auditing language: #{languages.map { |lang| "'#{lang}'" }.join(", ")}"
MacOS.instance_variable_set(:@languages, languages) MacOS.instance_variable_set(:@languages, languages)
audit_cask_instance(Hbc.load(cask.sourcefile_path), audit_download, check_token_conflicts) audit_cask_instance(Hbc.load(cask.sourcefile_path), audit_download, check_token_conflicts)
CLI::Cleanup.run(cask.token) if audit_download CLI::Cleanup.run(cask.token) if audit_download
}.all? end.all?
ensure ensure
MacOS.instance_variable_set(:@languages, saved_languages) MacOS.instance_variable_set(:@languages, saved_languages)
end end

View File

@ -12,7 +12,7 @@ module Hbc
def graph_dependencies def graph_dependencies
deps_in = ->(csk) { csk.depends_on ? csk.depends_on.cask || [] : [] } deps_in = ->(csk) { csk.depends_on ? csk.depends_on.cask || [] : [] }
walk = lambda { |acc, deps| walk = lambda do |acc, deps|
deps.each do |dep| deps.each do |dep|
next if acc.key?(dep) next if acc.key?(dep)
succs = deps_in.call Hbc.load(dep) succs = deps_in.call Hbc.load(dep)
@ -20,7 +20,7 @@ module Hbc
walk.call(acc, succs) walk.call(acc, succs)
end end
acc acc
} end
graphed = walk.call({}, @cask.depends_on.cask) graphed = walk.call({}, @cask.depends_on.cask)
TopologicalHash[graphed] TopologicalHash[graphed]

View File

@ -76,9 +76,9 @@ module Hbc
else else
start_withs = tokens.map { |token| "#{token}--" } start_withs = tokens.map { |token| "#{token}--" }
cache_files.select { |path| cache_files.select do |path|
path.basename.to_s.start_with?(*start_withs) path.basename.to_s.start_with?(*start_withs)
} end
end end
delete_paths(deletable_cache_files) delete_paths(deletable_cache_files)

View File

@ -78,12 +78,12 @@ module Hbc
end end
def bom_filelist_from_path(mount) def bom_filelist_from_path(mount)
Dir.chdir(mount) { Dir.chdir(mount) do
Dir.glob("**/*", File::FNM_DOTMATCH).map { |path| Dir.glob("**/*", File::FNM_DOTMATCH).map do |path|
next if skip_path?(Pathname(path)) next if skip_path?(Pathname(path))
path == "." ? path : path.prepend("./") path == "." ? path : path.prepend("./")
}.compact.join("\n").concat("\n") end.compact.join("\n").concat("\n")
} end
end end
def skip_path?(path) def skip_path?(path)
@ -117,9 +117,7 @@ module Hbc
def mounts_from_plist(plist) def mounts_from_plist(plist)
return [] unless plist.respond_to?(:fetch) return [] unless plist.respond_to?(:fetch)
plist.fetch("system-entities", []).map { |entity| plist.fetch("system-entities", []).map { |e| e["mount-point"] }.compact
entity["mount-point"]
}.compact
end end
def assert_mounts_found def assert_mounts_found

View File

@ -40,9 +40,9 @@ module Hbc
end end
def extract_ref def extract_ref
key = REF_TYPES.find { |type| key = REF_TYPES.find do |type|
uri_object.respond_to?(type) && uri_object.send(type) uri_object.respond_to?(type) && uri_object.send(type)
} end
[key, key ? uri_object.send(key) : nil] [key, key ? uri_object.send(key) : nil]
end end

View File

@ -123,9 +123,9 @@ module Hbc
end end
MacOS.languages.map(&Locale.method(:parse)).each do |locale| MacOS.languages.map(&Locale.method(:parse)).each do |locale|
key = @language_blocks.keys.detect { |strings| key = @language_blocks.keys.detect do |strings|
strings.any? { |string| locale.include?(string) } strings.any? { |string| locale.include?(string) }
} end
next if key.nil? next if key.nil?

View File

@ -93,19 +93,17 @@ module Hbc
[[operator, release]] [[operator, release]]
else else
raise "'depends_on macos' comparison expressions cannot be combined" if @macos.first.is_a?(Symbol) raise "'depends_on macos' comparison expressions cannot be combined" if @macos.first.is_a?(Symbol)
Array(*arg).map { |elt| [*arg].map(&self.class.method(:coerce_os_release)).sort
self.class.coerce_os_release(elt)
}.sort
end end
@macos.concat(macos) @macos.concat(macos)
end end
def arch=(*arg) def arch=(*arg)
@arch ||= [] @arch ||= []
arches = Array(*arg).map { |elt| arches = Array(*arg).map do |elt|
elt = elt.to_s.downcase.sub(/^:/, "").tr("-", "_").to_sym elt = elt.to_s.downcase.sub(/^:/, "").tr("-", "_").to_sym
ARCH_SYNONYMS.key?(elt) ? ARCH_SYNONYMS[elt] : elt ARCH_SYNONYMS.key?(elt) ? ARCH_SYNONYMS[elt] : elt
} end
invalid_arches = arches - VALID_ARCHES.keys invalid_arches = arches - VALID_ARCHES.keys
raise "invalid 'depends_on arch' values: #{invalid_arches.inspect}" unless invalid_arches.empty? raise "invalid 'depends_on arch' values: #{invalid_arches.inspect}" unless invalid_arches.empty?
@arch.concat(arches.map { |arch| VALID_ARCHES[arch] }) @arch.concat(arches.map { |arch| VALID_ARCHES[arch] })

View File

@ -171,10 +171,10 @@ module Hbc
def arch_dependencies def arch_dependencies
return if @cask.depends_on.arch.nil? return if @cask.depends_on.arch.nil?
@current_arch ||= { type: Hardware::CPU.type, bits: Hardware::CPU.bits } @current_arch ||= { type: Hardware::CPU.type, bits: Hardware::CPU.bits }
return if @cask.depends_on.arch.any? { |arch| return if @cask.depends_on.arch.any? do |arch|
arch[:type] == @current_arch[:type] && arch[:type] == @current_arch[:type] &&
Array(arch[:bits]).include?(@current_arch[:bits]) Array(arch[:bits]).include?(@current_arch[:bits])
} end
raise CaskError, "Cask #{@cask} depends on hardware architecture being one of [#{@cask.depends_on.arch.map(&:to_s).join(", ")}], but you are running #{@current_arch}" raise CaskError, "Cask #{@cask} depends on hardware architecture being one of [#{@cask.depends_on.arch.map(&:to_s).join(", ")}], but you are running #{@current_arch}"
end end

View File

@ -141,9 +141,9 @@ module Hbc
token_with_tap = if query =~ %r{\A[^/]+/[^/]+/[^/]+\Z} token_with_tap = if query =~ %r{\A[^/]+/[^/]+/[^/]+\Z}
query_without_extension query_without_extension
else else
all_tokens.detect { |tap_and_token| all_tokens.detect do |tap_and_token|
tap_and_token.split("/")[2] == query_without_extension tap_and_token.split("/")[2] == query_without_extension
} end
end end
if token_with_tap if token_with_tap

View File

@ -1,9 +1,9 @@
module Hbc module Hbc
class Pkg class Pkg
def self.all_matching(regexp, command) def self.all_matching(regexp, command)
command.run("/usr/sbin/pkgutil", args: ["--pkgs=#{regexp}"]).stdout.split("\n").map { |package_id| command.run("/usr/sbin/pkgutil", args: ["--pkgs=#{regexp}"]).stdout.split("\n").map do |package_id|
new(package_id.chomp, command) new(package_id.chomp, command)
} end
end end
attr_reader :package_id attr_reader :package_id

View File

@ -15,11 +15,11 @@ module Hbc
end end
def all_tokens def all_tokens
Tap.map { |t| Tap.map do |t|
t.cask_files.map { |p| t.cask_files.map do |p|
"#{t.name}/#{File.basename(p, ".rb")}" "#{t.name}/#{File.basename(p, ".rb")}"
} end
}.flatten end.flatten
end end
def installed def installed
@ -28,19 +28,19 @@ module Hbc
# TODO: speed up Hbc::Source::Tapped (main perf drag is calling Hbc.all_tokens repeatedly) # TODO: speed up Hbc::Source::Tapped (main perf drag is calling Hbc.all_tokens repeatedly)
# TODO: ability to specify expected source when calling Hbc.load (minor perf benefit) # TODO: ability to specify expected source when calling Hbc.load (minor perf benefit)
Pathname.glob(caskroom.join("*")) Pathname.glob(caskroom.join("*"))
.map { |caskroom_path| .map do |caskroom_path|
token = caskroom_path.basename.to_s token = caskroom_path.basename.to_s
path_to_cask = all_tapped_cask_dirs.find { |tap_dir| path_to_cask = all_tapped_cask_dirs.find do |tap_dir|
tap_dir.join("#{token}.rb").exist? tap_dir.join("#{token}.rb").exist?
} end
if path_to_cask if path_to_cask
Hbc.load(path_to_cask.join("#{token}.rb")) Hbc.load(path_to_cask.join("#{token}.rb"))
else else
Hbc.load(token) Hbc.load(token)
end end
} end
end end
end end
end end

View File

@ -23,10 +23,10 @@ module Hbc
def self.for_query(query) def self.for_query(query)
odebug "Translating '#{query}' into a valid Cask source" odebug "Translating '#{query}' into a valid Cask source"
raise CaskUnavailableError, query if query.to_s =~ /^\s*$/ raise CaskUnavailableError, query if query.to_s =~ /^\s*$/
source = sources.find { |s| source = sources.find do |s|
odebug "Testing source class #{s}" odebug "Testing source class #{s}"
s.me?(query) s.me?(query)
} end
raise CaskUnavailableError, query unless source raise CaskUnavailableError, query unless source
odebug "Success! Using source class #{source}" odebug "Success! Using source class #{source}"
resolved_cask_source = source.new(query) resolved_cask_source = source.new(query)

View File

@ -66,13 +66,13 @@ module Hbc
end end
def expanded_command def expanded_command
@expanded_command ||= command.map { |arg| @expanded_command ||= command.map do |arg|
if arg.respond_to?(:to_path) if arg.respond_to?(:to_path)
File.absolute_path(arg) File.absolute_path(arg)
else else
String(arg) String(arg)
end end
} end
end end
def each_output_line(&b) def each_output_line(&b)