Run RuboCop on all core files. (#22855)

Add Style/BlockDelimiters cop.
This commit is contained in:
Markus Reiter
2016-07-19 14:11:22 -04:00
committed by Joshua Hagins
parent ade6178efb
commit ed5452b728
94 changed files with 2107 additions and 1967 deletions
+47 -8
View File
@@ -4,16 +4,8 @@ AllCops:
TargetRubyVersion: 2.0
Exclude:
- '**/Casks/**/*'
- '**/spec/*.rb'
- '**/spec/support/*.rb'
- '**/test/*.rb'
- '**/test/support/*.rb'
- 'developer/**/*'
- 'lib/vendor/**/*'
- 'spec/cask/**/*'
- 'test/cask/**/*'
- 'test/plist/**/*'
- 'test/support/shared_examples/**/*'
Metrics/AbcSize:
Enabled: false
@@ -37,6 +29,53 @@ Metrics/ModuleLength:
- 'lib/hbc/macos.rb'
- 'lib/hbc/utils.rb'
Style/BlockDelimiters:
EnforcedStyle: semantic
FunctionalMethods:
- expect
- let
- let!
- subject
- watch
- inject
- map
- map!
- collect
- collect!
- reject
- reject!
- delete_if
- with_object
ProceduralMethods:
- after
- at_exit
- before
- benchmark
- bm
- bmbm
- capture_io
- capture_output
- capture_subprocess_io
- chdir
- context
- create
- each_with_object
- fork
- measure
- new
- open
- realtime
- shutup
- tap
- each
- reverse_each
IgnoredMethods:
- it
- its
- lambda
- proc
Style/ClassAndModuleChildren:
EnforcedStyle: compact
+138 -143
View File
@@ -15,12 +15,12 @@
### dependencies
###
require 'pathname'
require 'open3'
require "pathname"
require "open3"
begin
# not available by default
require 'active_support/inflector'
require "active_support/inflector"
rescue LoadError
end
@@ -29,95 +29,95 @@ end
###
EXPANDED_SYMBOLS = {
'+' => 'plus',
'@' => 'at',
}
"+" => "plus",
"@" => "at",
}.freeze
CASK_FILE_EXTENSION = '.rb'
CASK_FILE_EXTENSION = ".rb".freeze
# Hardcode App names that cannot be transformed automatically.
# Example: in "x48.app", "x48" is not a version number.
# The value in the hash should be a valid Cask token.
APP_EXCEPTION_PATS = {
# looks like a trailing version, but is not.
%r{\Aiterm\Z}i => 'iterm2',
%r{\Aiterm2\Z}i => 'iterm2',
%r{\Apgadmin3\Z}i => 'pgadmin3',
%r{\Ax48\Z}i => 'x48',
%r{\Avitamin-r[\s\d\.]*\Z}i => 'vitamin-r',
%r{\Aimagealpha\Z}i => 'imagealpha',
# upstream is in the midst of changing branding
%r{\Abitcoin-?qt\Z}i => 'bitcoin-core',
# "mac" cannot be separated from the name because it is in an English phrase
%r{\Aplayonmac\Z}i => 'playonmac',
%r{\Acleanmymac[\s\d\.]*\Z}i => 'cleanmymac',
# arguably we should not have kept these two exceptions
%r{\Akismac\Z}i => 'kismac',
%r{\Avoicemac\Z}i => 'voicemac',
}
# looks like a trailing version, but is not.
%r{\Aiterm\Z}i => "iterm2",
%r{\Aiterm2\Z}i => "iterm2",
%r{\Apgadmin3\Z}i => "pgadmin3",
%r{\Ax48\Z}i => "x48",
%r{\Avitamin-r[\s\d\.]*\Z}i => "vitamin-r",
%r{\Aimagealpha\Z}i => "imagealpha",
# upstream is in the midst of changing branding
%r{\Abitcoin-?qt\Z}i => "bitcoin-core",
# "mac" cannot be separated from the name because it is in an English phrase
%r{\Aplayonmac\Z}i => "playonmac",
%r{\Acleanmymac[\s\d\.]*\Z}i => "cleanmymac",
# arguably we should not have kept these two exceptions
%r{\Akismac\Z}i => "kismac",
%r{\Avoicemac\Z}i => "voicemac",
}.freeze
# Preserve trailing patterns on App names that could be mistaken
# for version numbers, etc
PRESERVE_TRAILING_PATS = [
%r{id3}i,
%r{mp3}i,
%r{3[\s-]*d}i,
%r{diff3}i,
%r{\A[^\d]+\+\Z}i,
]
%r{id3}i,
%r{mp3}i,
%r{3[\s-]*d}i,
%r{diff3}i,
%r{\A[^\d]+\+\Z}i,
].freeze
# The code that employs these patterns against App names
# - hacks a \b (word-break) between CamelCase and snake_case transitions
# - anchors the pattern to end-of-string
# - applies the patterns repeatedly until there is no match
REMOVE_TRAILING_PATS = [
# spaces
%r{\s+}i,
# spaces
%r{\s+}i,
# generic terms
%r{\bapp}i,
%r{\b(?:quick[\s-]*)?launcher}i,
# generic terms
%r{\bapp}i,
%r{\b(?:quick[\s-]*)?launcher}i,
# "mac", "for mac", "for OS X", "macOS", "for macOS".
%r{\b(?:for)?[\s-]*mac(?:intosh|OS)?}i,
%r{\b(?:for)?[\s-]*os[\s-]*x}i,
# "mac", "for mac", "for OS X", "macOS", "for macOS".
%r{\b(?:for)?[\s-]*mac(?:intosh|OS)?}i,
%r{\b(?:for)?[\s-]*os[\s-]*x}i,
# hardware designations such as "for x86", "32-bit", "ppc"
%r{(?:\bfor\s*)?x.?86}i,
%r{(?:\bfor\s*)?\bppc}i,
%r{(?:\bfor\s*)?\d+.?bits?}i,
# hardware designations such as "for x86", "32-bit", "ppc"
%r{(?:\bfor\s*)?x.?86}i,
%r{(?:\bfor\s*)?\bppc}i,
%r{(?:\bfor\s*)?\d+.?bits?}i,
# frameworks
%r{\b(?:for)?[\s-]*(?:oracle|apple|sun)*[\s-]*(?:jvm|java|jre)}i,
%r{\bgtk}i,
%r{\bqt}i,
%r{\bwx}i,
%r{\bcocoa}i,
# frameworks
%r{\b(?:for)?[\s-]*(?:oracle|apple|sun)*[\s-]*(?:jvm|java|jre)}i,
%r{\bgtk}i,
%r{\bqt}i,
%r{\bwx}i,
%r{\bcocoa}i,
# localizations
%r{en\s*-\s*us}i,
# localizations
%r{en\s*-\s*us}i,
# version numbers
%r{[^a-z0-9]+}i,
%r{\b(?:version|alpha|beta|gamma|release|release.?candidate)(?:[\s\.\d-]*\d[\s\.\d-]*)?}i,
%r{\b(?:v|ver|vsn|r|rc)[\s\.\d-]*\d[\s\.\d-]*}i,
%r{\d+(?:[a-z\.]\d+)*}i,
%r{\b\d+\s*[a-z]}i,
%r{\d+\s*[a-c]}i, # constrained to a-c b/c of false positives
]
# version numbers
%r{[^a-z0-9]+}i,
%r{\b(?:version|alpha|beta|gamma|release|release.?candidate)(?:[\s\.\d-]*\d[\s\.\d-]*)?}i,
%r{\b(?:v|ver|vsn|r|rc)[\s\.\d-]*\d[\s\.\d-]*}i,
%r{\d+(?:[a-z\.]\d+)*}i,
%r{\b\d+\s*[a-z]}i,
%r{\d+\s*[a-c]}i, # constrained to a-c b/c of false positives
].freeze
# Patterns which are permitted (undisturbed) following an interior version number
AFTER_INTERIOR_VERSION_PATS = [
%r{ce}i,
%r{pro}i,
%r{professional}i,
%r{client}i,
%r{server}i,
%r{host}i,
%r{viewer}i,
%r{launcher}i,
%r{installer}i,
]
%r{ce}i,
%r{pro}i,
%r{professional}i,
%r{client}i,
%r{server}i,
%r{host}i,
%r{viewer}i,
%r{launcher}i,
%r{installer}i,
].freeze
###
### classes
@@ -137,68 +137,65 @@ class AppName < String
end
def english_from_app_bundle
return self if self.ascii_only?
return self if ascii_only?
return self unless File.exist?(self)
# check Info.plist CFBundleDisplayName
bundle_name = Open3.popen3(*%w[
/usr/libexec/PlistBuddy -c
],
'Print CFBundleDisplayName',
Pathname.new(self).join('Contents', 'Info.plist').to_s
) do |stdin, stdout, stderr|
/usr/libexec/PlistBuddy -c
],
"Print CFBundleDisplayName",
Pathname.new(self).join("Contents", "Info.plist").to_s) do |_stdin, stdout, _stderr|
begin
stdout.gets.force_encoding("UTF-8").chomp
rescue
end
end
return AppName.new(bundle_name) if bundle_name and bundle_name.ascii_only?
return AppName.new(bundle_name) if bundle_name && bundle_name.ascii_only?
# check Info.plist CFBundleName
bundle_name = Open3.popen3(*%w[
/usr/libexec/PlistBuddy -c
],
'Print CFBundleName',
Pathname.new(self).join('Contents', 'Info.plist').to_s
) do |stdin, stdout, stderr|
/usr/libexec/PlistBuddy -c
],
"Print CFBundleName",
Pathname.new(self).join("Contents", "Info.plist").to_s) do |_stdin, stdout, _stderr|
begin
stdout.gets.force_encoding("UTF-8").chomp
rescue
end
end
return AppName.new(bundle_name) if bundle_name and bundle_name.ascii_only?
return AppName.new(bundle_name) if bundle_name && bundle_name.ascii_only?
# check localization strings
local_strings_file = Pathname.new(self).join('Contents', 'Resources', 'en.lproj', 'InfoPlist.strings')
local_strings_file = Pathname.new(self).join('Contents', 'Resources', 'English.lproj', 'InfoPlist.strings') unless local_strings_file.exist?
local_strings_file = Pathname.new(self).join("Contents", "Resources", "en.lproj", "InfoPlist.strings")
local_strings_file = Pathname.new(self).join("Contents", "Resources", "English.lproj", "InfoPlist.strings") unless local_strings_file.exist?
if local_strings_file.exist?
bundle_name = File.open(local_strings_file, 'r:UTF-16LE:UTF-8') do |fh|
%r{\ACFBundle(?:Display)?Name\s*=\s*"(.*)";\Z}.match(fh.readlines.grep(/^CFBundle(?:Display)?Name\s*=\s*/).first) do |match|
bundle_name = File.open(local_strings_file, "r:UTF-16LE:UTF-8") do |fh|
%r{\ACFBundle(?:Display)?Name\s*=\s*"(.*)";\Z}.match(fh.readlines.grep(%r{^CFBundle(?:Display)?Name\s*=\s*}).first) do |match|
match.captures.first
end
end
return AppName.new(bundle_name) if bundle_name and bundle_name.ascii_only?
return AppName.new(bundle_name) if bundle_name && bundle_name.ascii_only?
end
# check Info.plist CFBundleExecutable
bundle_name = Open3.popen3(*%w[
/usr/libexec/PlistBuddy -c
],
'Print CFBundleExecutable',
Pathname.new(self).join('Contents', 'Info.plist').to_s
) do |stdin, stdout, stderr|
/usr/libexec/PlistBuddy -c
],
"Print CFBundleExecutable",
Pathname.new(self).join("Contents", "Info.plist").to_s) do |_stdin, stdout, _stderr|
begin
stdout.gets.force_encoding("UTF-8").chomp
rescue
end
end
return AppName.new(bundle_name) if bundle_name and bundle_name.ascii_only?
return AppName.new(bundle_name) if bundle_name && bundle_name.ascii_only?
self
end
def basename
if Pathname.new(self).exist? then
if Pathname.new(self).exist?
AppName.new(Pathname.new(self).basename.to_s)
else
self
@@ -206,56 +203,54 @@ class AppName < String
end
def remove_extension
self.sub(/\.app\Z/i, '')
sub(%r{\.app\Z}i, "")
end
def decompose_to_ascii
# crudely (and incorrectly) decompose extended latin characters to ASCII
return self if self.ascii_only?
return self unless self.respond_to?(:mb_chars)
AppName.new(self.mb_chars.normalize(:kd).each_char.select(&:ascii_only?).join)
return self if ascii_only?
return self unless respond_to?(:mb_chars)
AppName.new(mb_chars.normalize(:kd).each_char.select(&:ascii_only?).join)
end
def hardcoded_exception
APP_EXCEPTION_PATS.each do |regexp, exception|
if regexp.match(self) then
return AppName.new(exception)
end
return AppName.new(exception) if regexp.match(self)
end
return nil
nil
end
def insert_vertical_tabs_for_camel_case
app_name = AppName.new(self)
if app_name.sub!(/(#{self.class.preserve_trailing_pat})\Z/i, '')
trailing = $1
if app_name.sub!(%r{(#{self.class.preserve_trailing_pat})\Z}i, "")
trailing = Regexp.last_match(1)
end
app_name.gsub!(/([^A-Z])([A-Z])/, "\\1\v\\2")
app_name.sub!(/\Z/, trailing) if trailing
app_name.gsub!(%r{([^A-Z])([A-Z])}, "\\1\v\\2")
app_name.sub!(%r{\Z}, trailing) if trailing
app_name
end
def insert_vertical_tabs_for_snake_case
self.gsub(/_/, "\v")
gsub(%r{_}, "\v")
end
def clean_up_vertical_tabs
self.gsub(/\v/, '')
gsub(%r{\v}, "")
end
def remove_interior_versions!
# done separately from REMOVE_TRAILING_PATS because this
# requires a substitution with a backreference
self.sub!(%r{(?<=.)[\.\d]+(#{self.class.after_interior_version_pat})\Z}i, '\1')
self.sub!(%r{(?<=.)[\s\.\d-]*\d[\s\.\d-]*(#{self.class.after_interior_version_pat})\Z}i, '-\1')
sub!(%r{(?<=.)[\.\d]+(#{self.class.after_interior_version_pat})\Z}i, '\1')
sub!(%r{(?<=.)[\s\.\d-]*\d[\s\.\d-]*(#{self.class.after_interior_version_pat})\Z}i, '-\1')
end
def remove_trailing_strings_and_versions
app_name = self.insert_vertical_tabs_for_camel_case
.insert_vertical_tabs_for_snake_case
while self.class.remove_trailing_pat.match(app_name) and
not self.class.preserve_trailing_pat.match(app_name)
app_name.sub!(self.class.remove_trailing_pat, '')
app_name = insert_vertical_tabs_for_camel_case
.insert_vertical_tabs_for_snake_case
while self.class.remove_trailing_pat.match(app_name) &&
!self.class.preserve_trailing_pat.match(app_name)
app_name.sub!(self.class.remove_trailing_pat, "")
end
app_name.remove_interior_versions!
app_name.clean_up_vertical_tabs
@@ -263,10 +258,10 @@ class AppName < String
def simplified
return @simplified if @simplified
@simplified = self.english_from_app_bundle
.basename
.decompose_to_ascii
.remove_extension
@simplified = english_from_app_bundle
.basename
.decompose_to_ascii
.remove_extension
@simplified = @simplified.hardcoded_exception || @simplified.remove_trailing_strings_and_versions
@simplified
end
@@ -274,23 +269,23 @@ end
class CaskFileName < String
def spaces_to_hyphens
self.gsub(/ +/, '-')
gsub(%r{ +}, "-")
end
def delete_invalid_chars
self.gsub(/[^a-z0-9-]+/, '')
gsub(%r{[^a-z0-9-]+}, "")
end
def collapse_multiple_hyphens
self.gsub(/--+/, '-')
gsub(%r{--+}, "-")
end
def delete_leading_hyphens
self.gsub(/^--+/, '')
gsub(%r{^--+}, "")
end
def delete_hyphens_before_numbers
self.gsub(/-([0-9])/, '\1')
gsub(%r{-([0-9])}, '\1')
end
def spell_out_symbols
@@ -298,32 +293,32 @@ class CaskFileName < String
EXPANDED_SYMBOLS.each do |k, v|
cask_file_name.gsub!(k, " #{v} ")
end
cask_file_name.sub(/ +\Z/, '')
cask_file_name.sub(%r{ +\Z}, "")
end
def add_extension
self.sub(/(?:#{escaped_cask_file_extension})?\Z/i, CASK_FILE_EXTENSION)
sub(%r{(?:#{escaped_cask_file_extension})?\Z}i, CASK_FILE_EXTENSION)
end
def remove_extension
self.sub(/#{escaped_cask_file_extension}\Z/i, '')
sub(%r{#{escaped_cask_file_extension}\Z}i, "")
end
def from_simplified_app_name
return @from_simplified_app_name if @from_simplified_app_name
@from_simplified_app_name = if APP_EXCEPTION_PATS.rassoc(self.remove_extension)
self.remove_extension
else
self.remove_extension
.downcase
.spell_out_symbols
.spaces_to_hyphens
.delete_invalid_chars
.collapse_multiple_hyphens
.delete_leading_hyphens
.delete_hyphens_before_numbers
@from_simplified_app_name = if APP_EXCEPTION_PATS.rassoc(remove_extension)
remove_extension
else
remove_extension
.downcase
.spell_out_symbols
.spaces_to_hyphens
.delete_invalid_chars
.collapse_multiple_hyphens
.delete_leading_hyphens
.delete_hyphens_before_numbers
end
raise "Could not determine Simplified App name" unless @from_simplified_app_name.length > 0
raise "Could not determine Simplified App name" if @from_simplified_app_name.empty?
@from_simplified_app_name.add_extension
end
end
@@ -335,8 +330,8 @@ end
def project_root
Dir.chdir File.dirname(File.expand_path(__FILE__))
@git_root ||= Open3.popen3(*%w[
git rev-parse --show-toplevel
]) do |stdin, stdout, stderr|
git rev-parse --show-toplevel
]) do |_stdin, stdout, _stderr|
begin
Pathname.new(stdout.gets.chomp)
rescue
@@ -352,7 +347,7 @@ def escaped_cask_file_extension
end
def simplified_app_name
@simplified_app_name ||= AppName.new("#{ARGV.first}".force_encoding("UTF-8")).simplified
@simplified_app_name ||= AppName.new(ARGV.first.to_s.force_encoding("UTF-8")).simplified
end
def cask_file_name
@@ -367,11 +362,11 @@ def warnings
return @warnings if @warnings
@warnings = []
unless APP_EXCEPTION_PATS.rassoc(cask_token)
if %r{\d}.match(cask_token)
if %r{\d} =~ cask_token
@warnings.push "WARNING: '#{cask_token}' contains digits. Digits which are version numbers should be removed."
end
end
filename = project_root.join('Casks', cask_file_name)
filename = project_root.join("Casks", cask_file_name)
if filename.exist?
@warnings.push "WARNING: the file '#{filename}' already exists. Prepend the vendor name if this is not a duplicate."
end
@@ -383,7 +378,7 @@ def report
puts "Proposed token: #{cask_token}"
puts "Proposed file name: #{cask_file_name}"
puts "Cask Header Line: cask '#{cask_token}' do"
if warnings.length > 0
unless warnings.empty?
$stderr.puts "\n"
$stderr.puts warnings
$stderr.puts "\n"
+3 -3
View File
@@ -7,13 +7,13 @@
### dependencies
###
require 'erb'
require "erb"
###
### constants
###
BASE_URL = 'https://github.com/caskroom/homebrew-cask/issues/new'
BASE_URL = "https://github.com/caskroom/homebrew-cask/issues/new".freeze
###
### methods
@@ -21,7 +21,7 @@ BASE_URL = 'https://github.com/caskroom/homebrew-cask/issues/new'
def main(args)
args.each do |file|
File.read(file).scan(/(.*?)\n(.*)/m) do |title, body|
File.read(file).scan(%r{(.*?)\n(.*)}m) do |title, body|
puts generate_url(title, body)
end
end
+4 -4
View File
@@ -7,7 +7,7 @@
### dependencies
###
require 'open3'
require "open3"
###
### methods
@@ -32,7 +32,7 @@ EOS
end
def process_args
if ARGV.first =~ /^-+h(?:elp)?$/
if ARGV.first =~ %r{^-+h(?:elp)?$}
puts usage
exit 0
elsif ARGV.length == 1
@@ -45,7 +45,7 @@ end
def list_login_items_for_app(app_path)
out, err, status = Open3.capture3(
'/usr/bin/osascript', '-e',
"/usr/bin/osascript", "-e",
"tell application \"System Events\" to get the name of every login item " \
"whose path contains \"#{File.basename(app_path)}\""
)
@@ -53,7 +53,7 @@ def list_login_items_for_app(app_path)
$stderr.puts err
exit status.exitstatus
end
puts out.gsub(', ', "\n")
puts out.gsub(", ", "\n")
end
###
+10 -10
View File
@@ -7,8 +7,8 @@
### dependencies
###
require 'open3'
require 'set'
require "open3"
require "set"
###
### globals
@@ -47,11 +47,11 @@ EOS
end
def process_args
while ! ARGV.empty? do
if ARGV.first =~ /^-+t(?:est)?$/ and ARGV.length > 1
until ARGV.empty?
if ARGV.first =~ %r{^-+t(?:est)?$} && ARGV.length > 1
ARGV.shift
$opt_test = ARGV.shift
elsif ARGV.first =~ /^-+h(?:elp)?$/
elsif ARGV.first =~ %r{^-+h(?:elp)?$}
puts usage
exit 0
else
@@ -62,12 +62,12 @@ def process_args
end
def load_apps
out, err, status = Open3.capture3('/usr/bin/osascript', '-e', 'tell application "System Events" to get (name, bundle identifier, unix id) of every process')
out, err, status = Open3.capture3("/usr/bin/osascript", "-e", 'tell application "System Events" to get (name, bundle identifier, unix id) of every process')
if status.exitstatus > 0
puts err
exit status.exitstatus
end
out = out.split(', ')
out = out.split(", ")
one_third = out.length / 3
@app_names = out.shift(one_third)
@bundle_ids = out.shift(one_third)
@@ -83,15 +83,15 @@ def excluded_bundle_id(bundle_id)
end
def excluded_app_name(app_name)
%r{^osascript$}.match(app_name) # this script itself
%r{^osascript$}.match(app_name) # this script itself
end
def report_apps
running = Set.new
@app_names.zip(@bundle_ids, @unix_ids).each do |app_name, bundle_id, unix_id|
@app_names.zip(@bundle_ids, @unix_ids).each do |app_name, bundle_id, _unix_id|
next if excluded_bundle_id bundle_id
next if excluded_app_name app_name
bundle_id.gsub!(/^(missing value)$/, '<\1>')
bundle_id.gsub!(%r{^(missing value)$}, '<\1>')
running.add "#{bundle_id}\t#{app_name}"
end
+53 -56
View File
@@ -15,49 +15,49 @@
### dependencies
###
require 'open3'
require 'set'
require "open3"
require "set"
###
### configurable constants
###
BINS = [
(1..10).to_a,
100,
1000,
(1..10).to_a,
100,
1000,
].flatten
OCCASIONAL_CUTOFF = 5
CASK_PATH = 'Casks'
CASK_PATH = "Casks".freeze
# all maintainers, past and present
MAINTAINERS = %w[
paul.t.hinze@gmail.com
fanquake@users.noreply.github.com
fanquake@gmail.com
kevin@suttle.io
leoj3n@gmail.com
nano@fdp.io
nanoid.xd@gmail.com
me@passcod.name
walker@pobox.com
info@vitorgalvao.com
calebcenter@live.com
ndr@qef.io
josh@joshbutts.com
goxberry@gmail.com
radek.simko@gmail.com
federicobond@gmail.com
claui@users.noreply.github.com
amorymeltzer@gmail.com
hagins.josh@gmail.com
dragon.vctr@gmail.com
mail@sebastianroeder.de
github@adityadalal.com
adityadalal924@users.noreply.github.com
]
paul.t.hinze@gmail.com
fanquake@users.noreply.github.com
fanquake@gmail.com
kevin@suttle.io
leoj3n@gmail.com
nano@fdp.io
nanoid.xd@gmail.com
me@passcod.name
walker@pobox.com
info@vitorgalvao.com
calebcenter@live.com
ndr@qef.io
josh@joshbutts.com
goxberry@gmail.com
radek.simko@gmail.com
federicobond@gmail.com
claui@users.noreply.github.com
amorymeltzer@gmail.com
hagins.josh@gmail.com
dragon.vctr@gmail.com
mail@sebastianroeder.de
github@adityadalal.com
adityadalal924@users.noreply.github.com
].freeze
###
### git methods
@@ -66,8 +66,8 @@ MAINTAINERS = %w[
def cd_to_project_root
Dir.chdir File.dirname(File.expand_path(__FILE__))
@git_root ||= Open3.popen3(*%w[
git rev-parse --show-toplevel
]) do |stdin, stdout, stderr|
git rev-parse --show-toplevel
]) do |_stdin, stdout, _stderr|
begin
stdout.gets.chomp
rescue
@@ -79,8 +79,8 @@ end
def authors
@authors ||= Open3.popen3(*%w[
git log --no-merges --format=%ae --
]) do |stdin, stdout, stderr|
git log --no-merges --format=%ae --
]) do |_stdin, stdout, _stderr|
h = {}
stdout.each_line do |line|
line.chomp!
@@ -93,14 +93,14 @@ end
def casks_by_author
@casks_by_author ||= Open3.popen3(*%w[
git log --no-merges --name-only --format=%ae --
],
CASK_PATH) do |stdin, stdout, stderr|
git log --no-merges --name-only --format=%ae --
],
CASK_PATH) do |_stdin, stdout, _stderr|
email = nil
h = {}
stdout.each_line.to_a.join('').split("\n\n").each do |paragraph|
if paragraph.include?('Casks/')
lines=paragraph.split("\n")
stdout.each_line.to_a.join("").split("\n\n").each do |paragraph|
if paragraph.include?("Casks/")
lines = paragraph.split("\n")
email = lines.pop
h[email] ||= Set.new
h[email].merge(lines.compact)
@@ -109,7 +109,7 @@ def casks_by_author
end
end
h
end
end
end
###
@@ -117,10 +117,9 @@ end
###
def all_casks
@all_casks ||= Open3.popen3('/usr/bin/find',
CASK_PATH,
*%w[-type f -name *.rb]
) do |stdin, stdout, stderr|
@all_casks ||= Open3.popen2("/usr/bin/find",
CASK_PATH,
*%w[-type f -name *.rb]) do |_stdin, stdout|
stdout.each_line.map(&:chomp)
end
end
@@ -131,13 +130,11 @@ end
def histogram
if @histogram.nil?
@histogram = Hash[*BINS.map{ |elt| [elt, 0] }.flatten]
authors.each do |name, num_commits|
@histogram = Hash[*BINS.map { |elt| [elt, 0] }.flatten]
authors.each do |_name, num_commits|
bottom = 0
BINS.each do |top|
if num_commits >= bottom and num_commits < top
@histogram[bottom] += 1
end
@histogram[bottom] += 1 if num_commits >= bottom && num_commits < top
bottom = top
end
end
@@ -149,7 +146,7 @@ def historic_occasional_cask_set
@historic_occasional_cask_set = authors.each.collect do |name, num_commits|
if num_commits > OCCASIONAL_CUTOFF
nil
elsif ! casks_by_author.key?(name)
elsif !casks_by_author.key?(name)
nil
else
casks_by_author[name].to_a
@@ -163,7 +160,7 @@ def extant_occasional_cask_count
end
def historic_nonmaintainer_cask_set
@historic_nonmaintainer_cask_set = authors.each.collect do |name, num_commits|
@historic_nonmaintainer_cask_set = authors.each.collect do |name, _num_commits|
if MAINTAINERS.include?(name)
nil
else
@@ -203,7 +200,7 @@ end
def occasional_author_percentage
# why is it so hard to slice a hash?
@occasional_author_percentage ||= (100 *
(1 .. OCCASIONAL_CUTOFF).to_a.collect{ |bin| histogram[bin] }.reduce(:+) /
(1..OCCASIONAL_CUTOFF).to_a.collect { |bin| histogram[bin] }.reduce(:+) /
authors.length).to_i
end
@@ -227,14 +224,14 @@ end
def print_table
BINS.each do |bin|
plural = (bin % 10) == 0 ? "'s" : ''
graph = '.' * ((histogram[bin]/graph_normalization) * graph_width)
plural = (bin % 10) == 0 ? "'s" : ""
graph = "." * ((histogram[bin] / graph_normalization) * graph_width)
puts "#{bin}#{plural}\t#{histogram[bin]}\t#{graph}"
end
end
def print_footer
puts %Q[\n#{occasional_author_percentage}% of contributors are "occasional" (with <= #{OCCASIONAL_CUTOFF} commits)]
puts %Q{\n#{occasional_author_percentage}% of contributors are "occasional" (with <= #{OCCASIONAL_CUTOFF} commits)}
puts "\n#{onetime_author_percentage}% of contributors commit only once"
puts "\n#{extant_occasional_cask_percentage}% - #{historic_occasional_cask_percentage}% of Casks depend on an occasional contributor"
puts "\n#{extant_nonmaintainer_cask_percentage}% - #{historic_nonmaintainer_cask_percentage}% of Casks depend on a contributor who is not a maintainer"
+8 -4
View File
@@ -5,7 +5,7 @@
# (c) 2014 MIT license
#
require 'rubygems'
require "rubygems"
class Hbc
def installed_version?
@@ -14,9 +14,13 @@ class Hbc
def installed_version
# returns latest installed version if possible
Pathname.glob(caskroom_path.join('*')).map(&:basename).sort{|x,y|
Pathname.glob(caskroom_path.join("*")).map(&:basename).sort do |x, y|
Gem::Version.new(x) <=> Gem::Version.new(y) # throws exception if invalid version is provided ...
}.last rescue nil # ... return nil in this case
end.last
rescue
nil
# ... return nil in this case
end
def update_available?
@@ -36,4 +40,4 @@ end
upgradable_casks = Hbc.upgradable
puts upgradable_casks.empty? && 'No outdated packages' || upgradable_casks
puts upgradable_casks.empty? && "No outdated packages" || upgradable_casks
+2 -2
View File
@@ -2,9 +2,9 @@ require "hbc/artifact/relocated"
class Hbc::Artifact::Moved < Hbc::Artifact::Relocated
def summary
contents = @cask.artifacts[self.class.artifact_dsl_key].map do |artifact|
contents = @cask.artifacts[self.class.artifact_dsl_key].map { |artifact|
summarize_artifact(artifact)
end - [nil]
}.compact
{
english_description: "#{self.class.artifact_english_name}s managed by brew-cask:",
+4 -4
View File
@@ -30,9 +30,9 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base
end
def self.remove_relative_path_strings(action, path_strings)
relative = path_strings.map do |path_string|
relative = path_strings.map { |path_string|
path_string if %r{/\.\.(?:/|\Z)}.match(path_string) || !%r{\A/}.match(path_string)
end.compact
}.compact
relative.each do |path_string|
opoo "Skipping #{action} for relative path #{path_string}"
end
@@ -40,9 +40,9 @@ class Hbc::Artifact::UninstallBase < Hbc::Artifact::Base
end
def self.remove_undeletable_path_strings(action, path_strings)
undeletable = path_strings.map do |path_string|
undeletable = path_strings.map { |path_string|
path_string if Hbc::MacOS.undeletable?(Pathname.new(path_string))
end.compact
}.compact
undeletable.each do |path_string|
opoo "Skipping #{action} for undeletable path #{path_string}"
end
+2 -2
View File
@@ -11,7 +11,7 @@ class Hbc::CaskDependencies
def graph_dependencies
deps_in = ->(csk) { csk.depends_on ? csk.depends_on.cask || [] : [] }
walk = lambda do |acc, deps|
walk = lambda { |acc, deps|
deps.each do |dep|
next if acc.key?(dep)
succs = deps_in.call Hbc.load(dep)
@@ -19,7 +19,7 @@ class Hbc::CaskDependencies
walk.call(acc, succs)
end
acc
end
}
graphed = walk.call({}, @cask.depends_on.cask)
Hbc::TopologicalHash[graphed]
+4 -4
View File
@@ -42,7 +42,7 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
end
def cache_incompletes
cache_symlinks.collect do |symlink|
cache_symlinks.collect { |symlink|
incomplete_file = Dir.chdir cache_location do
f = symlink.readlink
f = f.realpath if f.exist?
@@ -51,11 +51,11 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
incomplete_file = nil unless incomplete_file.exist?
incomplete_file = nil if outdated_only && incomplete_file && incomplete_file.stat.mtime > OUTDATED_TIMESTAMP
incomplete_file
end.compact
}.compact
end
def cache_completes
completes = cache_symlinks.collect do |symlink|
completes = cache_symlinks.collect { |symlink|
file = Dir.chdir cache_location do
f = symlink.readlink
f.exist? ? f.realpath : f
@@ -66,7 +66,7 @@ class Hbc::CLI::Cleanup < Hbc::CLI::Base
symlink = nil
end
[symlink, file]
end
}
completes
.flatten
.compact
+4 -1
View File
@@ -45,7 +45,10 @@ class Hbc::CLI::InternalAuditModifiedCasks < Hbc::CLI::InternalUseBase
end
def run
at_exit { cleanup }
at_exit do
cleanup
end
Dir.chdir git_root do
modified_cask_files.zip(modified_casks).each do |cask_file, cask|
audit(cask, cask_file)
+2 -2
View File
@@ -40,9 +40,9 @@ class Hbc::Container::Dmg < Hbc::Container::Base
def mounts_from_plist(plist)
return [] unless plist.respond_to?(:fetch)
plist.fetch("system-entities", []).map do |entity|
plist.fetch("system-entities", []).map { |entity|
entity["mount-point"]
end.compact
}.compact
end
def assert_mounts_found
+2 -2
View File
@@ -39,9 +39,9 @@ class Hbc::HbVCSDownloadStrategy < Hbc::AbstractDownloadStrategy
end
def extract_ref
key = REF_TYPES.find do |type|
key = REF_TYPES.find { |type|
uri_object.respond_to?(type) && uri_object.send(type)
end
}
[key, key ? uri_object.send(key) : nil]
end
+4 -4
View File
@@ -92,19 +92,19 @@ class Hbc::DSL::DependsOn
[[operator, release]]
else
raise "'depends_on :macos' comparison expressions cannot be combined" if @macos.first.is_a?(Symbol)
Array(*arg).map do |elt|
Array(*arg).map { |elt|
self.class.coerce_os_release(elt)
end.sort
}.sort
end
@macos.concat(macos)
end
def arch=(*arg)
@arch ||= []
arches = Array(*arg).map do |elt|
arches = Array(*arg).map { |elt|
elt = elt.to_s.downcase.sub(%r{^:}, "").tr("-", "_").to_sym
ARCH_SYNONYMS.key?(elt) ? ARCH_SYNONYMS[elt] : elt
end
}
invalid_arches = arches - VALID_ARCHES
raise "invalid 'depends_on :arch' values: #{invalid_arches.inspect}" unless invalid_arches.empty?
@arch.concat(arches)
+3 -1
View File
@@ -47,7 +47,9 @@ class Hbc::DSL::Version < ::String
end
end
DIVIDERS.keys.each { |divider| define_divider_methods(divider) }
DIVIDERS.keys.each do |divider|
define_divider_methods(divider)
end
attr_reader :raw_version
+2 -2
View File
@@ -50,9 +50,9 @@ module Hbc::Scopes
# TODO: ability to specify expected source when calling Hbc.load (minor perf benefit)
installed_cask_dirs.map do |install_dir|
cask_token = install_dir.basename.to_s
path_to_cask = all_tapped_cask_dirs.find do |tap_dir|
path_to_cask = all_tapped_cask_dirs.find { |tap_dir|
tap_dir.join("#{cask_token}.rb").exist?
end
}
@installed[cask_token] ||= if path_to_cask
Hbc.load(path_to_cask.join("#{cask_token}.rb"))
else
+2 -2
View File
@@ -24,10 +24,10 @@ module Hbc::Source
def self.for_query(query)
odebug "Translating '#{query}' into a valid Cask source"
raise Hbc::CaskUnavailableError, query if query.to_s =~ %r{^\s*$}
source = sources.find do |s|
source = sources.find { |s|
odebug "Testing source class #{s}"
s.me?(query)
end
}
raise Hbc::CaskUnavailableError, query unless source
odebug "Success! Using source class #{source}"
resolved_cask_source = source.new(query)
+2 -2
View File
@@ -60,13 +60,13 @@ class Hbc::SystemCommand
end
def expanded_command
@expanded_command ||= command.map do |arg|
@expanded_command ||= command.map { |arg|
if arg.respond_to?(:to_path)
File.absolute_path(arg)
else
String(arg)
end
end
}
end
def each_output_line(&b)
+13 -15
View File
@@ -1,24 +1,22 @@
require 'spec_helper'
require "spec_helper"
describe Hbc::Artifact::Binary do
let(:cask) {
Hbc.load('with-binary').tap do |cask|
Hbc.load("with-binary").tap do |cask|
shutup do
InstallHelper::install_without_artifacts(cask)
InstallHelper.install_without_artifacts(cask)
end
end
}
let(:expected_path) {
Hbc.binarydir.join('binary')
Hbc.binarydir.join("binary")
}
before(:each) {
before(:each) do
Hbc.binarydir.mkpath
}
after(:each) {
if expected_path.exist?
FileUtils.rm expected_path
end
}
end
after(:each) do
FileUtils.rm expected_path if expected_path.exist?
end
it "links the binary to the proper directory" do
shutup do
@@ -38,13 +36,13 @@ describe Hbc::Artifact::Binary do
end
it "clobbers an existing symlink" do
expected_path.make_symlink('/tmp')
expected_path.make_symlink("/tmp")
shutup do
Hbc::Artifact::Binary.new(cask).install_phase
end
expect(File.readlink(expected_path)).not_to eq('/tmp')
expect(File.readlink(expected_path)).not_to eq("/tmp")
end
it "respects --no-binaries flag" do
@@ -71,9 +69,9 @@ describe Hbc::Artifact::Binary do
context "binary is inside an app package" do
let(:cask) {
Hbc.load('with-embedded-binary').tap do |cask|
Hbc.load("with-embedded-binary").tap do |cask|
shutup do
InstallHelper::install_without_artifacts(cask)
InstallHelper.install_without_artifacts(cask)
end
end
}

Some files were not shown because too many files have changed in this diff Show More