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/**/*'
- '**/vendor/**/*'
Style/BlockDelimiters:
Exclude:
- '**/cask/spec/**/*'
- '**/cask/test/**/*'
# so many of these in formulae but none in here
Lint/AmbiguousRegexpLiteral:
Enabled: true

View File

@ -28,15 +28,15 @@ module Hbc
# sources and should be refactored for consistency
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)
}
end
end
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)
}.compact
end.compact
relative.each do |path_string|
opoo "Skipping #{action} for relative path #{path_string}"
end
@ -44,9 +44,9 @@ module Hbc
end
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))
}.compact
end.compact
undeletable.each do |path_string|
opoo "Skipping #{action} for undeletable path #{path_string}"
end

View File

@ -6,12 +6,12 @@ module Hbc
begin
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(", ")}"
MacOS.instance_variable_set(:@languages, languages)
audit_cask_instance(Hbc.load(cask.sourcefile_path), audit_download, check_token_conflicts)
CLI::Cleanup.run(cask.token) if audit_download
}.all?
end.all?
ensure
MacOS.instance_variable_set(:@languages, saved_languages)
end

View File

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

View File

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

View File

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

View File

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

View File

@ -123,9 +123,9 @@ module Hbc
end
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) }
}
end
next if key.nil?

View File

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

View File

@ -171,10 +171,10 @@ module Hbc
def arch_dependencies
return if @cask.depends_on.arch.nil?
@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] &&
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}"
end

View File

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

View File

@ -1,9 +1,9 @@
module Hbc
class Pkg
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)
}
end
end
attr_reader :package_id

View File

@ -15,11 +15,11 @@ module Hbc
end
def all_tokens
Tap.map { |t|
t.cask_files.map { |p|
Tap.map do |t|
t.cask_files.map do |p|
"#{t.name}/#{File.basename(p, ".rb")}"
}
}.flatten
end
end.flatten
end
def installed
@ -28,19 +28,19 @@ module Hbc
# 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)
Pathname.glob(caskroom.join("*"))
.map { |caskroom_path|
.map do |caskroom_path|
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?
}
end
if path_to_cask
Hbc.load(path_to_cask.join("#{token}.rb"))
else
Hbc.load(token)
end
}
end
end
end
end

View File

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

View File

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