Fix RuboCop offenses.

This commit is contained in:
Markus Reiter 2020-11-13 17:21:51 +01:00
parent f2693a0a00
commit 1b732ec7b2
12 changed files with 73 additions and 94 deletions

View File

@ -67,12 +67,9 @@ class PATH
sig { params(other: T.untyped).returns(T::Boolean) } sig { params(other: T.untyped).returns(T::Boolean) }
def ==(other) def ==(other)
if other.respond_to?(:to_ary) && to_ary == other.to_ary || (other.respond_to?(:to_ary) && to_ary == other.to_ary) ||
other.respond_to?(:to_str) && to_str == other.to_str (other.respond_to?(:to_str) && to_str == other.to_str) ||
true
else
false false
end
end end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }

View File

@ -62,7 +62,9 @@ class Build
def expand_deps def expand_deps
formula.recursive_dependencies do |dependent, dep| formula.recursive_dependencies do |dependent, dep|
build = effective_build_options_for(dependent) 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 Dependency.prune
elsif dep.build? elsif dep.build?
Dependency.keep_but_prune_recursive_deps Dependency.keep_but_prune_recursive_deps

View File

@ -60,11 +60,10 @@ module Cask
options[:quarantine] = true if options[:quarantine].nil? options[:quarantine] = true if options[:quarantine].nil?
casks = args.named.flat_map do |name| casks = args.named.flat_map do |name|
if File.exist?(name) && name.count("/") != 1 next name if File.exist?(name)
name next Tap.fetch(name).cask_files if name.count("/") == 1
else
Tap.fetch(name).cask_files name
end
end end
casks = casks.map { |c| CaskLoader.load(c, config: Config.from_args(args)) } casks = casks.map { |c| CaskLoader.load(c, config: Config.from_args(args)) }
casks = Cask.to_a if casks.empty? casks = Cask.to_a if casks.empty?

View File

@ -76,6 +76,12 @@ class Cleaner
path.text_executable? || path.executable? path.text_executable? || path.executable?
end 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 # Clean a top-level (bin, sbin, lib) directory, recursively, by fixing file
# permissions and removing .la files, unless the files (or parent # permissions and removing .la files, unless the files (or parent
# directories) are protected by skip_clean. # directories) are protected by skip_clean.
@ -93,12 +99,7 @@ class Cleaner
next if path.directory? next if path.directory?
files_to_skip = %w[perllocal.pod .packlist] if path.extname == ".la" || PERL_BASENAMES.include?(path.basename.to_s)
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.
path.unlink path.unlink
elsif path.symlink? elsif path.symlink?
# Skip it. # Skip it.

View File

@ -440,22 +440,14 @@ module Homebrew
if key == "cellar" if key == "cellar"
# Prioritize HOMEBREW_CELLAR over :any over :any_skip_relocation # Prioritize HOMEBREW_CELLAR over :any over :any_skip_relocation
cellars = [first, second] cellars = [first, second]
if cellars.include?(HOMEBREW_CELLAR) next HOMEBREW_CELLAR if cellars.include?(HOMEBREW_CELLAR)
HOMEBREW_CELLAR next first if first.start_with?("/")
elsif first.start_with?("/") next second if second.start_with?("/")
first next "any" if cellars.include?("any")
elsif second.start_with?("/") next "any_skip_relocation" if cellars.include?("any_skip_relocation")
second
elsif cellars.include?("any")
"any"
elsif cellars.include?("any_skip_relocation")
"any_skip_relocation"
else # rubocop:disable Lint/DuplicateBranch
second
end
else
second
end end
second
end end
end end

View File

@ -1233,9 +1233,9 @@ class DownloadStrategyDetector
when %r{^https?://(.+?\.)?googlecode\.com/svn}, when %r{^https?://(.+?\.)?googlecode\.com/svn},
%r{^https?://svn\.}, %r{^https?://svn\.},
%r{^svn://}, %r{^svn://},
%r{^https?://(.+?\.)?sourceforge\.net/svnroot/},
%r{^svn\+http://}, %r{^svn\+http://},
%r{^http://svn\.apache\.org/repos/} %r{^http://svn\.apache\.org/repos/},
%r{^https?://(.+?\.)?sourceforge\.net/svnroot/}
SubversionDownloadStrategy SubversionDownloadStrategy
when %r{^cvs://} when %r{^cvs://}
CVSDownloadStrategy CVSDownloadStrategy

View File

@ -1271,7 +1271,7 @@ class Formula
end end
if current_version || 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 else
all_kegs += old_installed_formulae.flat_map(&:installed_kegs) all_kegs += old_installed_formulae.flat_map(&:installed_kegs)

View File

@ -537,7 +537,7 @@ class FormulaInstaller
if req.prune_from_option?(build) || if req.prune_from_option?(build) ||
req.satisfied?(env: env, cc: cc, build_bottle: @build_bottle, bottle_arch: bottle_arch) || req.satisfied?(env: env, cc: cc, build_bottle: @build_bottle, bottle_arch: bottle_arch) ||
((req.build? || req.test?) && !keep_build_test) || ((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 Requirement.prune
else else
unsatisfied_reqs[dependent] << req unsatisfied_reqs[dependent] << req
@ -566,8 +566,7 @@ class FormulaInstaller
keep_build_test ||= dep.test? && include_test? && include_test_formulae.include?(dependent.full_name) 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? keep_build_test ||= dep.build? && !install_bottle_for?(dependent, build) && !dependent.latest_version_installed?
if dep.prune_from_option?(build) || if dep.prune_from_option?(build) || ((dep.build? || dep.test?) && !keep_build_test)
((dep.build? || dep.test?) && !keep_build_test)
Dependency.prune Dependency.prune
elsif dep.satisfied?(inherited_options[dep.name]) elsif dep.satisfied?(inherited_options[dep.name])
Dependency.skip Dependency.skip

View File

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

View File

@ -189,24 +189,20 @@ module OS
# installed CLT version. This is useful as they are packaged # installed CLT version. This is useful as they are packaged
# simultaneously so workarounds need to apply to both based on their # simultaneously so workarounds need to apply to both based on their
# comparable version. # comparable version.
# rubocop:disable Lint/DuplicateBranch
latest_stable = "12.0"
case (DevelopmentTools.clang_version.to_f * 10).to_i 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" 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 end
# rubocop:enable Lint/DuplicateBranch
end end
def default_prefix? def default_prefix?
@ -276,12 +272,10 @@ module OS
# Bump these when the new version is distributed through Software Update # Bump these when the new version is distributed through Software Update
# and our CI systems have been updated. # and our CI systems have been updated.
# rubocop:disable Lint/DuplicateBranch
sig { returns(String) } sig { returns(String) }
def latest_clang_version def latest_clang_version
case MacOS.version case MacOS.version
when "11.0" then "1200.0.32.27" when "11.0", "10.15" then "1200.0.32.27"
when "10.15" then "1200.0.32.27"
when "10.14" then "1100.0.33.17" when "10.14" then "1100.0.33.17"
when "10.13" then "1000.10.44.2" when "10.13" then "1000.10.44.2"
when "10.12" then "900.0.39.2" when "10.12" then "900.0.39.2"
@ -290,7 +284,6 @@ module OS
else "600.0.57" else "600.0.57"
end end
end end
# rubocop:enable Lint/DuplicateBranch
# Bump these if things are badly broken (e.g. no SDK for this macOS) # 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 # without this. Generally this will be the first stable CLT release on

View File

@ -22,18 +22,7 @@ module RuboCop
problem "The homepage should start with http or https (URL is #{homepage})." problem "The homepage should start with http or https (URL is #{homepage})."
end end
# rubocop:disable Lint/DuplicateBranch
case homepage 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. # 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 # To enable https Freedesktop change the URL from http://project.freedesktop.org/wiki to
# https://wiki.freedesktop.org/project_name. # https://wiki.freedesktop.org/project_name.
@ -49,14 +38,6 @@ module RuboCop
when %r{^https?://code\.google\.com/p/[^/]+[^/]$} when %r{^https?://code\.google\.com/p/[^/]+[^/]$}
problem "#{homepage} should end with a slash" 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(/|$)} when %r{^http://([^/]*)\.(sf|sourceforge)\.net(/|$)}
problem "#{homepage} should be `https://#{Regexp.last_match(1)}.sourceforge.io/`" problem "#{homepage} should be `https://#{Regexp.last_match(1)}.sourceforge.io/`"
@ -68,15 +49,28 @@ module RuboCop
offending_node(parameters(homepage_node).first) offending_node(parameters(homepage_node).first)
problem "GitHub homepages (`#{homepage}`) should not end with .git" problem "GitHub homepages (`#{homepage}`) should not end with .git"
# There's an auto-redirect here, but this mistake is incredibly common too. # People will run into mixed content sometimes, but we should enforce and then add
# Only applies to the homepage and subdomains for now, not the FTP URLs. # exemptions as they are discovered. Treat mixed content on homepages as a bug.
when %r{^http://((?:build|cloud|developer|download|extensions|git| # Justify each exemptions with a code comment so we can keep track here.
glade|help|library|live|nagios|news|people| #
projects|rt|static|wiki|www)\.)?gnome\.org}x
problem "Please use https:// for #{homepage}"
# Compact the above into this list as we're able to remove detailed notations, etc over time. # 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://packages\.debian\.org},
%r{^http://wiki\.freedesktop\.org/}, %r{^http://wiki\.freedesktop\.org/},
%r{^http://((?:www)\.)?gnupg\.org/}, %r{^http://((?:www)\.)?gnupg\.org/},
@ -89,7 +83,6 @@ module RuboCop
%r{^http://(?:[^/]*\.)?archive\.org} %r{^http://(?:[^/]*\.)?archive\.org}
problem "Please use https:// for #{homepage}" problem "Please use https:// for #{homepage}"
end end
# rubocop:enable Lint/DuplicateBranch
end end
def autocorrect(node) def autocorrect(node)

View File

@ -516,16 +516,16 @@ class Version
l += 1 l += 1
r += 1 r += 1
next next
elsif a.numeric? == b.numeric? elsif a.numeric? && !b.numeric?
return a <=> b
elsif a.numeric?
return 1 if a > NULL_TOKEN return 1 if a > NULL_TOKEN
l += 1 l += 1
elsif b.numeric? elsif !a.numeric? && b.numeric?
return -1 if b > NULL_TOKEN return -1 if b > NULL_TOKEN
r += 1 r += 1
else
return a <=> b
end end
end end