Skip to content

Commit

Permalink
Fix RuboCop offenses.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Nov 13, 2020
1 parent 1edd92c commit d3ef856
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 95 deletions.
8 changes: 2 additions & 6 deletions Library/Homebrew/PATH.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@ def to_str

sig { params(other: T.untyped).returns(T::Boolean) }
def ==(other)
if other.respond_to?(:to_ary) && to_ary == other.to_ary ||
other.respond_to?(:to_str) && to_str == other.to_str
true
else
false
end
((other.respond_to?(:to_ary) && to_ary == other.to_ary) ||
(other.respond_to?(:to_str) && to_str == other.to_str))
end

sig { returns(T::Boolean) }
Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def expand_reqs
def expand_deps
formula.recursive_dependencies do |dependent, dep|
build = effective_build_options_for(dependent)
if dep.prune_from_option?(build) || dep.prune_if_build_and_not_dependent?(dependent, formula) || dep.test?
if dep.prune_from_option?(build) ||
dep.prune_if_build_and_not_dependent?(dependent, formula) ||
(dep.test? && !dep.build?)
Dependency.prune
elsif dep.build?
Dependency.keep_but_prune_recursive_deps
Expand Down
9 changes: 4 additions & 5 deletions Library/Homebrew/cask/cmd/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ def run
options[:quarantine] = true if options[:quarantine].nil?

casks = args.named.flat_map do |name|
if File.exist?(name) && name.count("/") != 1
name
else
Tap.fetch(name).cask_files
end
next name if File.exist?(name)
next Tap.fetch(name).cask_files if name.count("/") == 1

name
end
casks = casks.map { |c| CaskLoader.load(c, config: Config.from_args(args)) }
casks = Cask.to_a if casks.empty?
Expand Down
13 changes: 7 additions & 6 deletions Library/Homebrew/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ def executable_path?(path)
path.text_executable? || path.executable?
end

# Both these files are completely unnecessary to package and cause
# pointless conflicts with other formulae. They are removed by Debian,
# Arch & MacPorts amongst other packagers as well. The files are
# created as part of installing any Perl module.
PERL_BASENAMES = Set.new(%w[perllocal.pod .packlist]).freeze

# Clean a top-level (bin, sbin, lib) directory, recursively, by fixing file
# permissions and removing .la files, unless the files (or parent
# directories) are protected by skip_clean.
Expand All @@ -93,12 +99,7 @@ def clean_dir(d)

next if path.directory?

files_to_skip = %w[perllocal.pod .packlist]
if path.extname == ".la" || (!path.symlink? && files_to_skip.include?(path.basename.to_s))
# Both the `perllocal.pod` & `.packlist` files are completely unnecessary
# to package & causes pointless conflict with other formulae. They are
# removed by Debian, Arch & MacPorts amongst other packagers as well.
# The files are created as part of installing any Perl module.
if path.extname == ".la" || PERL_BASENAMES.include?(path.basename.to_s)
path.unlink
elsif path.symlink?
# Skip it.
Expand Down
22 changes: 7 additions & 15 deletions Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,22 +440,14 @@ def merge(args:)
if key == "cellar"
# Prioritize HOMEBREW_CELLAR over :any over :any_skip_relocation
cellars = [first, second]
if cellars.include?(HOMEBREW_CELLAR)
HOMEBREW_CELLAR
elsif first.start_with?("/")
first
elsif second.start_with?("/")
second
elsif cellars.include?("any")
"any"
elsif cellars.include?("any_skip_relocation")
"any_skip_relocation"
else # rubocop:disable Lint/DuplicateBranch
second
end
else
second
next HOMEBREW_CELLAR if cellars.include?(HOMEBREW_CELLAR)
next first if first.start_with?("/")
next second if second.start_with?("/")
next "any" if cellars.include?("any")
next "any_skip_relocation" if cellars.include?("any_skip_relocation")
end

second
end
end

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1233,9 +1233,9 @@ def self.detect_from_url(url)
when %r{^https?://(.+?\.)?googlecode\.com/svn},
%r{^https?://svn\.},
%r{^svn://},
%r{^https?://(.+?\.)?sourceforge\.net/svnroot/},
%r{^svn\+http://},
%r{^http://svn\.apache\.org/repos/}
%r{^http://svn\.apache\.org/repos/},
%r{^https?://(.+?\.)?sourceforge\.net/svnroot/}
SubversionDownloadStrategy
when %r{^cvs://}
CVSDownloadStrategy
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ def outdated_kegs(fetch_head: false)
end

if current_version ||
(latest_head_version && !head_version_outdated?(latest_head_version, fetch_head: fetch_head))
((head_version = latest_head_version) && !head_version_outdated?(head_version, fetch_head: fetch_head))
[]
else
all_kegs += old_installed_formulae.flat_map(&:installed_kegs)
Expand Down
5 changes: 2 additions & 3 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def expand_requirements
if req.prune_from_option?(build) ||
req.satisfied?(env: env, cc: cc, build_bottle: @build_bottle, bottle_arch: bottle_arch) ||
((req.build? || req.test?) && !keep_build_test) ||
(formula_deps_map.key?(dependent.name) && formula_deps_map[dependent.name].build?)
formula_deps_map[dependent.name]&.build?
Requirement.prune
else
unsatisfied_reqs[dependent] << req
Expand Down Expand Up @@ -566,8 +566,7 @@ def expand_dependencies(deps)
keep_build_test ||= dep.test? && include_test? && include_test_formulae.include?(dependent.full_name)
keep_build_test ||= dep.build? && !install_bottle_for?(dependent, build) && !dependent.latest_version_installed?

if dep.prune_from_option?(build) ||
((dep.build? || dep.test?) && !keep_build_test)
if dep.prune_from_option?(build) || ((dep.build? || dep.test?) && !keep_build_test)
Dependency.prune
elsif dep.satisfied?(inherited_options[dep.name])
Dependency.skip
Expand Down
13 changes: 8 additions & 5 deletions Library/Homebrew/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,15 @@ def link(**options)
%r{^guile/},
*SHARE_PATHS
:mkpath
else :link
else
:link
end
end

link_dir("lib", **options) do |relative_path|
case relative_path.to_s
when "charset.alias" then :skip_file
when "charset.alias"
:skip_file
when "pkgconfig", # pkg-config database gets explicitly created
"cmake", # cmake database gets explicitly created
"dtrace", # lib/language folders also get explicitly created
Expand All @@ -515,10 +517,11 @@ def link(**options)
"php",
/^python[23]\.\d/,
/^R/,
/^ruby/,
/^ruby/
:mkpath
# Everything else is symlinked to the cellar
else :link
else
# Everything else is symlinked to the cellar
:link
end
end

Expand Down
31 changes: 12 additions & 19 deletions Library/Homebrew/os/mac/xcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,20 @@ def detect_version_from_clang_version
# installed CLT version. This is useful as they are packaged
# simultaneously so workarounds need to apply to both based on their
# comparable version.
# rubocop:disable Lint/DuplicateBranch
latest_stable = "12.0"
case (DevelopmentTools.clang_version.to_f * 10).to_i
when 120 then latest_stable
when 110 then "11.5"
when 100 then "10.3"
when 91 then "9.4"
when 90 then "9.2"
when 81 then "8.3"
when 80 then "8.0"
when 73 then "7.3"
when 70 then "7.0"
when 61 then "6.1"
when 60 then "6.0"
when 0 then "dunno"
else latest_stable
when 60 then "6.0"
when 61 then "6.1"
when 70 then "7.0"
when 73 then "7.3"
when 80 then "8.0"
when 81 then "8.3"
when 90 then "9.2"
when 91 then "9.4"
when 100 then "10.3"
when 110 then "11.5"
else "12.0"
end
# rubocop:enable Lint/DuplicateBranch
end

def default_prefix?
Expand Down Expand Up @@ -276,12 +272,10 @@ def update_instructions

# Bump these when the new version is distributed through Software Update
# and our CI systems have been updated.
# rubocop:disable Lint/DuplicateBranch
sig { returns(String) }
def latest_clang_version
case MacOS.version
when "11.0" then "1200.0.32.27"
when "10.15" then "1200.0.32.27"
when "11.0", "10.15" then "1200.0.32.27"
when "10.14" then "1100.0.33.17"
when "10.13" then "1000.10.44.2"
when "10.12" then "900.0.39.2"
Expand All @@ -290,7 +284,6 @@ def latest_clang_version
else "600.0.57"
end
end
# rubocop:enable Lint/DuplicateBranch

# Bump these if things are badly broken (e.g. no SDK for this macOS)
# without this. Generally this will be the first stable CLT release on
Expand Down
49 changes: 21 additions & 28 deletions Library/Homebrew/rubocops/homepage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "The homepage should start with http or https (URL is #{homepage})."
end

# rubocop:disable Lint/DuplicateBranch
case homepage
# Check for http:// GitHub homepage URLs, https:// is preferred.
# Note: only check homepages that are repo pages, not *.github.com hosts
when %r{^http://github.com/}
problem "Please use https:// for #{homepage}"

# Savannah has full SSL/TLS support but no auto-redirect.
# Doesn't apply to the download URLs, only the homepage.
when %r{^http://savannah.nongnu.org/}
problem "Please use https:// for #{homepage}"

# Freedesktop is complicated to handle - It has SSL/TLS, but only on certain subdomains.
# To enable https Freedesktop change the URL from http://project.freedesktop.org/wiki to
# https://wiki.freedesktop.org/project_name.
Expand All @@ -49,14 +38,6 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
when %r{^https?://code\.google\.com/p/[^/]+[^/]$}
problem "#{homepage} should end with a slash"

# People will run into mixed content sometimes, but we should enforce and then add
# exemptions as they are discovered. Treat mixed content on homepages as a bug.
# Justify each exemptions with a code comment so we can keep track here.

when %r{^http://[^/]*\.github\.io/},
%r{^http://[^/]*\.sourceforge\.io/}
problem "Please use https:// for #{homepage}"

when %r{^http://([^/]*)\.(sf|sourceforge)\.net(/|$)}
problem "#{homepage} should be `https://#{Regexp.last_match(1)}.sourceforge.io/`"

Expand All @@ -68,15 +49,28 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
offending_node(parameters(homepage_node).first)
problem "GitHub homepages (`#{homepage}`) should not end with .git"

# There's an auto-redirect here, but this mistake is incredibly common too.
# Only applies to the homepage and subdomains for now, not the FTP URLs.
when %r{^http://((?:build|cloud|developer|download|extensions|git|
glade|help|library|live|nagios|news|people|
projects|rt|static|wiki|www)\.)?gnome\.org}x
problem "Please use https:// for #{homepage}"

# People will run into mixed content sometimes, but we should enforce and then add
# exemptions as they are discovered. Treat mixed content on homepages as a bug.
# Justify each exemptions with a code comment so we can keep track here.
#
# Compact the above into this list as we're able to remove detailed notations, etc over time.
when %r{^http://[^/]*\.apache\.org},
when
# Check for http:// GitHub homepage URLs, https:// is preferred.
# Note: only check homepages that are repo pages, not *.github.com hosts
%r{^http://github.com/},
%r{^http://[^/]*\.github\.io/},

# Savannah has full SSL/TLS support but no auto-redirect.
# Doesn't apply to the download URLs, only the homepage.
%r{^http://savannah.nongnu.org/},

%r{^http://[^/]*\.sourceforge\.io/},
# There's an auto-redirect here, but this mistake is incredibly common too.
# Only applies to the homepage and subdomains for now, not the FTP URLs.
%r{^http://((?:build|cloud|developer|download|extensions|git|
glade|help|library|live|nagios|news|people|
projects|rt|static|wiki|www)\.)?gnome\.org}x,
%r{^http://[^/]*\.apache\.org},
%r{^http://packages\.debian\.org},
%r{^http://wiki\.freedesktop\.org/},
%r{^http://((?:www)\.)?gnupg\.org/},
Expand All @@ -89,7 +83,6 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
%r{^http://(?:[^/]*\.)?archive\.org}
problem "Please use https:// for #{homepage}"
end
# rubocop:enable Lint/DuplicateBranch
end

def autocorrect(node)
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -516,16 +516,16 @@ def <=>(other)
l += 1
r += 1
next
elsif a.numeric? == b.numeric?
return a <=> b
elsif a.numeric?
elsif a.numeric? && !b.numeric?
return 1 if a > NULL_TOKEN

l += 1
elsif b.numeric?
elsif !a.numeric? && b.numeric?
return -1 if b > NULL_TOKEN

r += 1
else
return a <=> b
end
end

Expand Down

0 comments on commit d3ef856

Please sign in to comment.