brew style manual fixes

This commit is contained in:
Mike McQuaid 2020-09-01 14:05:52 +01:00
parent e09147fe75
commit 8b97c27c21
26 changed files with 72 additions and 120 deletions

View File

@ -47,15 +47,13 @@ class PATH
alias to_s to_str alias to_s to_str
def ==(other) def ==(other)
if other.respond_to?(:to_ary) if other.respond_to?(:to_ary) && to_ary == other.to_ary
return true if to_ary == other.to_ary true
elsif other.respond_to?(:to_str) && to_str == other.to_str
true
else
false
end end
if other.respond_to?(:to_str)
return true if to_str == other.to_str
end
false
end end
def empty? def empty?

View File

@ -13,7 +13,6 @@ require "cask/exceptions"
require "cask/denylist" require "cask/denylist"
require "cask/download" require "cask/download"
require "cask/dsl" require "cask/dsl"
require "cask/exceptions"
require "cask/installer" require "cask/installer"
require "cask/macos" require "cask/macos"
require "cask/metadata" require "cask/metadata"

View File

@ -14,10 +14,6 @@ module Cask
new(cask) new(cask)
end end
def initialize(cask)
super(cask)
end
def to_a def to_a
[true] [true]
end end

View File

@ -380,10 +380,10 @@ module Cask
add_warning "cask token contains .app" if token.end_with? ".app" add_warning "cask token contains .app" if token.end_with? ".app"
if /-(?<designation>alpha|beta|rc|release-candidate)$/ =~ cask.token if /-(?<designation>alpha|beta|rc|release-candidate)$/ =~ cask.token &&
if cask.tap.official? && cask.tap != "homebrew/cask-versions" cask.tap.official? &&
add_warning "cask token contains version designation '#{designation}'" cask.tap != "homebrew/cask-versions"
end add_warning "cask token contains version designation '#{designation}'"
end end
add_warning "cask token mentions launcher" if token.end_with? "launcher" add_warning "cask token mentions launcher" if token.end_with? "launcher"

View File

@ -44,9 +44,9 @@ module Cask
odebug "Uninstalling Cask #{cask}" odebug "Uninstalling Cask #{cask}"
if cask.installed? if cask.installed?
if installed_caskfile = cask.installed_caskfile if (installed_caskfile = cask.installed_caskfile) && installed_caskfile.exist?
# Use the same cask file that was used for installation, if possible. # Use the same cask file that was used for installation, if possible.
cask = CaskLoader.load(installed_caskfile) if installed_caskfile.exist? cask = CaskLoader.load(installed_caskfile)
end end
else else
raise CaskNotInstalledError, cask unless force raise CaskNotInstalledError, cask unless force

View File

@ -32,9 +32,9 @@ module Cask
odebug "Zapping Cask #{cask}" odebug "Zapping Cask #{cask}"
if cask.installed? if cask.installed?
if installed_caskfile = cask.installed_caskfile if (installed_caskfile = cask.installed_caskfile) && installed_caskfile.exist?
# Use the same cask file that was used for installation, if possible. # Use the same cask file that was used for installation, if possible.
cask = CaskLoader.load(installed_caskfile) if installed_caskfile.exist? cask = CaskLoader.load(installed_caskfile)
end end
else else
raise CaskNotInstalledError, cask unless args.force? raise CaskNotInstalledError, cask unless args.force?

View File

@ -285,10 +285,8 @@ module Cask
end end
end end
def respond_to_missing?(*) # No need to define it as its the default/superclass implementation.
super # rubocop:disable Style/MissingRespondToMissing
end
def method_missing(method, *) def method_missing(method, *)
if method if method
Utils.method_missing_message(method, token) Utils.method_missing_message(method, token)
@ -297,6 +295,7 @@ module Cask
super super
end end
end end
# rubocop:enable Style/MissingRespondToMissing
def appdir def appdir
cask.config.appdir cask.config.appdir

View File

@ -21,10 +21,8 @@ module Cask
@command.run!(executable, **options) @command.run!(executable, **options)
end end
def respond_to_missing?(*) # No need to define it as its the default/superclass implementation.
super # rubocop:disable Style/MissingRespondToMissing
end
def method_missing(method, *) def method_missing(method, *)
if method if method
underscored_class = self.class.name.gsub(/([[:lower:]])([[:upper:]][[:lower:]])/, '\1_\2').downcase underscored_class = self.class.name.gsub(/([[:lower:]])([[:upper:]][[:lower:]])/, '\1_\2').downcase
@ -35,6 +33,7 @@ module Cask
super super
end end
end end
# rubocop:enable Style/MissingRespondToMissing
end end
end end
end end

View File

@ -214,9 +214,7 @@ module Cask
odebug "Installing artifact of class #{artifact.class}" odebug "Installing artifact of class #{artifact.class}"
if artifact.is_a?(Artifact::Binary) next if artifact.is_a?(Artifact::Binary) && !binaries?
next unless binaries?
end
artifact.install_phase(command: @command, verbose: verbose?, force: force?) artifact.install_phase(command: @command, verbose: verbose?, force: force?)
already_installed_artifacts.unshift(artifact) already_installed_artifacts.unshift(artifact)
@ -226,13 +224,11 @@ module Cask
rescue => e rescue => e
begin begin
already_installed_artifacts.each do |artifact| already_installed_artifacts.each do |artifact|
next unless artifact.respond_to?(:uninstall_phase) if artifact.respond_to?(:uninstall_phase)
odebug "Reverting installation of artifact of class #{artifact.class}"
artifact.uninstall_phase(command: @command, verbose: verbose?, force: force?)
end
odebug "Reverting installation of artifact of class #{artifact.class}"
artifact.uninstall_phase(command: @command, verbose: verbose?, force: force?)
end
already_installed_artifacts.each do |artifact|
next unless artifact.respond_to?(:post_uninstall_phase) next unless artifact.respond_to?(:post_uninstall_phase)
odebug "Reverting installation of artifact of class #{artifact.class}" odebug "Reverting installation of artifact of class #{artifact.class}"
@ -455,13 +451,13 @@ module Cask
odebug "#{artifacts.length} artifact/s defined", artifacts odebug "#{artifacts.length} artifact/s defined", artifacts
artifacts.each do |artifact| artifacts.each do |artifact|
next unless artifact.respond_to?(:uninstall_phase) if artifact.respond_to?(:uninstall_phase)
odebug "Uninstalling artifact of class #{artifact.class}"
artifact.uninstall_phase(
command: @command, verbose: verbose?, skip: clear, force: force?, upgrade: upgrade?,
)
end
odebug "Uninstalling artifact of class #{artifact.class}"
artifact.uninstall_phase(command: @command, verbose: verbose?, skip: clear, force: force?, upgrade: upgrade?)
end
artifacts.each do |artifact|
next unless artifact.respond_to?(:post_uninstall_phase) next unless artifact.respond_to?(:post_uninstall_phase)
odebug "Post-uninstalling artifact of class #{artifact.class}" odebug "Post-uninstalling artifact of class #{artifact.class}"

View File

@ -416,9 +416,7 @@ module Homebrew
path.extend(ObserverPathnameExtension) path.extend(ObserverPathnameExtension)
if path.symlink? if path.symlink?
unless path.resolved_path_exists? unless path.resolved_path_exists?
if path.to_s.match?(Keg::INFOFILE_RX) path.uninstall_info if path.to_s.match?(Keg::INFOFILE_RX) && !dry_run?
path.uninstall_info unless dry_run?
end
if dry_run? if dry_run?
puts "Would remove (broken link): #{path}" puts "Would remove (broken link): #{path}"

View File

@ -63,8 +63,8 @@ module Homebrew
def info def info
args = info_args.parse args = info_args.parse
if args.days.present? if args.days.present? && !VALID_DAYS.include?(args.days)
raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}" unless VALID_DAYS.include?(args.days) raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}"
end end
if args.category.present? if args.category.present?
@ -79,10 +79,7 @@ module Homebrew
if args.json if args.json
raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json
raise FormulaUnspecifiedError if !(args.all? || args.installed?) && args.no_named?
if !(args.all? || args.installed?) && args.no_named?
raise FormulaUnspecifiedError if args.no_named?
end
print_json(args: args) print_json(args: args)
elsif args.github? elsif args.github?

View File

@ -5,10 +5,8 @@ module Homebrew
class Parser class Parser
module Compat module Compat
module DeprecatedArgs module DeprecatedArgs
def respond_to_missing?(*) # No need to define it as its the default/superclass implementation.
super # rubocop:disable Style/MissingRespondToMissing
end
def method_missing(method, *) def method_missing(method, *)
if ![:debug?, :quiet?, :verbose?, :value].include?(method) && !@printed_args_warning if ![:debug?, :quiet?, :verbose?, :value].include?(method) && !@printed_args_warning
odeprecated "Homebrew.args", "`args = <command>_args.parse` and pass `args` along the call chain" odeprecated "Homebrew.args", "`args = <command>_args.parse` and pass `args` along the call chain"
@ -17,6 +15,7 @@ module Homebrew
super super
end end
# rubocop:enable Style/MissingRespondToMissing
end end
def parse(*) def parse(*)

View File

@ -81,11 +81,6 @@ class DescriptionCacheStore < CacheStore
private private
# Not implemented; access is through `Searchable`.
def fetch
super
end
# `select` from the underlying database. # `select` from the underlying database.
def select(&block) def select(&block)
database.select(&block) database.select(&block)

View File

@ -1030,8 +1030,8 @@ module Homebrew
def audit_download_strategy def audit_download_strategy
url_strategy = DownloadStrategyDetector.detect(url) url_strategy = DownloadStrategyDetector.detect(url)
if using == :git || url_strategy == GitDownloadStrategy if (using == :git || url_strategy == GitDownloadStrategy) && specs[:tag] && !specs[:revision]
problem "Git should specify :revision when a :tag is specified." if specs[:tag] && !specs[:revision] problem "Git should specify :revision when a :tag is specified."
end end
return unless using return unless using

View File

@ -187,12 +187,10 @@ module Homebrew
absolute_symlinks_start_with_string << pn if link.to_s.start_with?(string) absolute_symlinks_start_with_string << pn if link.to_s.start_with?(string)
end end
if args.verbose? if args.verbose? && absolute_symlinks_start_with_string.present?
unless absolute_symlinks_start_with_string.empty? opoo "Absolute symlink starting with #{string}:"
opoo "Absolute symlink starting with #{string}:" absolute_symlinks_start_with_string.each do |pn|
absolute_symlinks_start_with_string.each do |pn| puts " #{pn} -> #{pn.resolved_path}"
puts " #{pn} -> #{pn.resolved_path}"
end
end end
end end

View File

@ -215,8 +215,8 @@ module Homebrew
bintray_key = ENV["HOMEBREW_BINTRAY_KEY"] bintray_key = ENV["HOMEBREW_BINTRAY_KEY"]
bintray_org = args.bintray_org || "homebrew" bintray_org = args.bintray_org || "homebrew"
if bintray_user.blank? || bintray_key.blank? if (bintray_user.blank? || bintray_key.blank?) && !args.dry_run? && !args.no_upload?
odie "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !args.dry_run? && !args.no_upload? odie "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!"
end end
workflow = args.workflow || "tests.yml" workflow = args.workflow || "tests.yml"

View File

@ -656,11 +656,6 @@ module Homebrew
end end
next if status.blank? next if status.blank?
# these will result in uncommitted gems.
if path == HOMEBREW_REPOSITORY
next if ENV["HOMEBREW_SORBET"]
end
message ||= "" message ||= ""
message += "\n" unless message.empty? message += "\n" unless message.empty?
message += <<~EOS message += <<~EOS

View File

@ -19,6 +19,8 @@ require "active_support/core_ext/object/try"
require "active_support/core_ext/array/access" require "active_support/core_ext/array/access"
require "active_support/core_ext/string/inflections" require "active_support/core_ext/string/inflections"
require "active_support/core_ext/array/conversions" require "active_support/core_ext/array/conversions"
require "active_support/core_ext/hash/deep_merge"
require "active_support/core_ext/file/atomic"
I18n.backend.available_locales # Initialize locales so they can be overwritten. I18n.backend.available_locales # Initialize locales so they can be overwritten.
I18n.backend.store_translations :en, support: { array: { last_word_connector: " and " } } I18n.backend.store_translations :en, support: { array: { last_word_connector: " and " } }
@ -66,7 +68,6 @@ HOMEBREW_DEFAULT_PREFIX = "/usr/local"
LINUXBREW_DEFAULT_PREFIX = "/home/linuxbrew/.linuxbrew" LINUXBREW_DEFAULT_PREFIX = "/home/linuxbrew/.linuxbrew"
require "fileutils" require "fileutils"
require "os"
require "os/global" require "os/global"
module Homebrew module Homebrew
@ -123,9 +124,6 @@ end.compact.freeze
require "set" require "set"
require "extend/string" require "extend/string"
require "active_support/core_ext/object/blank"
require "active_support/core_ext/hash/deep_merge"
require "active_support/core_ext/file/atomic"
require "system_command" require "system_command"
require "exceptions" require "exceptions"

View File

@ -297,8 +297,8 @@ class Keg
next if aliases.include?(a) next if aliases.include?(a)
alias_opt_symlink = opt/a alias_opt_symlink = opt/a
if alias_opt_symlink.symlink? && alias_opt_symlink.exist? if alias_opt_symlink.symlink? && alias_opt_symlink.exist? && rack == alias_opt_symlink.realpath.parent
alias_opt_symlink.delete if rack == alias_opt_symlink.realpath.parent alias_opt_symlink.delete
end end
alias_linkedkegs_symlink = linkedkegs/a alias_linkedkegs_symlink = linkedkegs/a

View File

@ -18,11 +18,9 @@ module RuboCop
option_call_nodes.each do |option_call| option_call_nodes.each do |option_call|
option = parameters(option_call).first option = parameters(option_call).first
problem DEPRECATION_MSG if regex_match_group(option, /32-bit/) problem DEPRECATION_MSG if regex_match_group(option, /32-bit/)
end
option_call_nodes.each do |option_call|
offending_node(option_call) offending_node(option_call)
option = string_content(parameters(option_call).first) option = string_content(option)
problem UNI_DEPRECATION_MSG if option == "universal" problem UNI_DEPRECATION_MSG if option == "universal"
if option !~ /with(out)?-/ && if option !~ /with(out)?-/ &&

View File

@ -48,13 +48,11 @@ module RuboCop
end end
gh_patch_param_pattern = %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)} gh_patch_param_pattern = %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)}
if regex_match_group(patch, gh_patch_param_pattern) if regex_match_group(patch, gh_patch_param_pattern) && !patch_url.match?(/\?full_index=\w+$/)
unless patch_url.match?(/\?full_index=\w+$/) problem <<~EOS
problem <<~EOS GitHub patches should use the full_index parameter:
GitHub patches should use the full_index parameter: #{patch_url}?full_index=1
#{patch_url}?full_index=1 EOS
EOS
end
end end
gh_patch_patterns = Regexp.union([%r{/raw\.github\.com/}, gh_patch_patterns = Regexp.union([%r{/raw\.github\.com/},
@ -62,13 +60,11 @@ module RuboCop
%r{gist\.github\.com/raw}, %r{gist\.github\.com/raw},
%r{gist\.github\.com/.+/raw}, %r{gist\.github\.com/.+/raw},
%r{gist\.githubusercontent\.com/.+/raw}]) %r{gist\.githubusercontent\.com/.+/raw}])
if regex_match_group(patch, gh_patch_patterns) if regex_match_group(patch, gh_patch_patterns) && !patch_url.match?(%r{/[a-fA-F0-9]{6,40}/})
unless patch_url.match?(%r{/[a-fA-F0-9]{6,40}/}) problem <<~EOS.chomp
problem <<~EOS.chomp GitHub/Gist patches should specify a revision:
GitHub/Gist patches should specify a revision: #{patch_url}
#{patch_url} EOS
EOS
end
end end
gh_patch_diff_pattern = gh_patch_diff_pattern =

View File

@ -64,8 +64,10 @@ module RuboCop
name_regex = name.delete("-").split("").join('[\s\-]?') name_regex = name.delete("-").split("").join('[\s\-]?')
problem "Description shouldn't start with the #{type} name." if regex_match_group(desc, /^#{name_regex}\b/i) problem "Description shouldn't start with the #{type} name." if regex_match_group(desc, /^#{name_regex}\b/i)
if type == :cask && match = regex_match_group(desc, /\b(macOS|Mac( ?OS( ?X)?)?|OS ?X)\b/i) if type == :cask &&
problem "Description shouldn't contain the platform." if match[1] != "MAC" (match = regex_match_group(desc, /\b(macOS|Mac( ?OS( ?X)?)?|OS ?X)\b/i)) &&
match[1] != "MAC"
problem "Description shouldn't contain the platform."
end end
# Check if a full stop is used at the end of a desc (apart from in the case of "etc."). # Check if a full stop is used at the end of a desc (apart from in the case of "etc.").

View File

@ -145,10 +145,7 @@ module SystemConfig
value = Homebrew::EnvConfig.send(method_name) value = Homebrew::EnvConfig.send(method_name)
next unless value next unless value
next if (default = hash[:default].presence) && value.to_s == default.to_s
if (default = hash[:default].presence)
next if value.to_s == default.to_s
end
if ENV.sensitive?(env) if ENV.sensitive?(env)
f.puts "#{env}: set" f.puts "#{env}: set"

View File

@ -272,8 +272,8 @@ class Tap
begin begin
safe_system "git", *args safe_system "git", *args
unless Readall.valid_tap?(self, aliases: true) if !Readall.valid_tap?(self, aliases: true) && !Homebrew::EnvConfig.developer?
raise "Cannot tap #{name}: invalid syntax in tap!" unless Homebrew::EnvConfig.developer? raise "Cannot tap #{name}: invalid syntax in tap!"
end end
rescue Interrupt, RuntimeError rescue Interrupt, RuntimeError
ignore_interrupts do ignore_interrupts do

View File

@ -192,9 +192,6 @@ describe BottleSpecification do
checksums.each_pair do |cat, digest| checksums.each_pair do |cat, digest|
subject.sha256(digest => cat) subject.sha256(digest => cat)
end
checksums.each_pair do |cat, digest|
checksum, = subject.checksum_for(cat) checksum, = subject.checksum_for(cat)
expect(Checksum.new(:sha256, digest)).to eq(checksum) expect(Checksum.new(:sha256, digest)).to eq(checksum)
end end

View File

@ -138,9 +138,8 @@ module Utils
else else
item["formula"] item["formula"]
end end
if filter.present? next if filter.present? && key != filter && !key.start_with?("#{filter} ")
next if key != filter && !key.start_with?("#{filter} ")
end
results[key] = item["count"].tr(",", "").to_i results[key] = item["count"].tr(",", "").to_i
end end
@ -163,12 +162,8 @@ module Utils
value.each do |days, results| value.each do |days, results|
days = days.to_i days = days.to_i
if full_analytics if full_analytics
if args.days.present? next if args.days.present? && args.days&.to_i != days
next if args.days&.to_i != days next if args.category.present? && args.category != category
end
if args.category.present?
next if args.category != category
end
table_output(category, days, results) table_output(category, days, results)
else else