Skip to content

Commit

Permalink
Fix style violations under newer RuboCop
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo98 committed Dec 14, 2023
1 parent 2e9d7fb commit 843eb8c
Show file tree
Hide file tree
Showing 55 changed files with 195 additions and 229 deletions.
8 changes: 8 additions & 0 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ RSpec/DescribeClass:
Enabled: false
RSpec/FilePath:
Enabled: false
# RSpec/SpecFilePathFormat:
# Enabled: false
RSpec/StubbedMock:
Enabled: false
RSpec/SubjectStub:
Expand Down Expand Up @@ -381,6 +383,8 @@ Style/InvertibleUnlessCondition:
:==: :!=
# Unset this (prefer `unless a.zero?` over `if a.nonzero?`)
:zero?:
# Don't require non-standard `exclude?` (for now at least) - it's not available in every file
:include?:

# would rather freeze too much than too little
Style/MutableConstant:
Expand Down Expand Up @@ -436,6 +440,10 @@ Style/StringLiteralsInInterpolation:
Style/StringMethods:
Enabled: true

# Treating this the same as Style/MethodCallWithArgsParentheses
# Style/SuperWithArgsParentheses:
# Enabled: false

# An array of symbols is more readable than a symbol array
# and also allows for easier grepping.
Style/SymbolArray:
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/artifact/abstract_artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.dsl_key
end

def self.dirmethod
@dirmethod ||= "#{dsl_key}dir".to_sym
@dirmethod ||= :"#{dsl_key}dir"
end

sig { abstract.returns(String) }
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/caskroom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.paths
# Return all tokens for installed casks.
sig { returns(T::Array[String]) }
def self.tokens
paths.map(&:basename).map(&:to_s)
paths.map { |path| path.basename.to_s }
end

sig { returns(T::Boolean) }
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/dsl/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Version < ::String
"_" => :underscores,
}.freeze

DIVIDER_REGEX = /(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})/.freeze
DIVIDER_REGEX = /(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join("|")})/.freeze

MAJOR_MINOR_PATCH_REGEX = /^([^.,:]+)(?:.([^.,:]+)(?:.([^.,:]+))?)?/.freeze

Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/cli/args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def context

def only_formula_or_cask
return :formula if formula? && !cask?
return :cask if cask? && !formula?

:cask if cask? && !formula?
end

sig { returns(T::Array[[Symbol, Symbol]]) }
Expand Down Expand Up @@ -149,7 +150,7 @@ def cli_args
@cli_args = []
@processed_options.each do |short, long|
option = long || short
switch = "#{option_to_name(option)}?".to_sym
switch = :"#{option_to_name(option)}?"
flag = option_to_name(option).to_sym
if @table[switch] == true || @table[flag] == true
@cli_args << option
Expand Down
7 changes: 4 additions & 3 deletions Library/Homebrew/cli/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ def switch(*names, description: nil, replacement: nil, env: nil, depends_on: nil
set_constraints(name, depends_on: depends_on)
end

env_value = env?(env)
env_value = value_for_env(env)
set_switch(*names, value: env_value, from: :env) unless env_value.nil?
end
alias switch_option switch

def env?(env)
def value_for_env(env)
return if env.blank?

method_name = :"#{env}?"
Expand All @@ -193,6 +193,7 @@ def env?(env)
ENV.fetch("HOMEBREW_#{env.upcase}", nil)
end
end
private :value_for_env

def description(text = nil)
return @description if text.blank?
Expand Down Expand Up @@ -527,7 +528,7 @@ def disable_switch(*args)
end

def option_passed?(name)
@args[name.to_sym] || @args["#{name}?".to_sym]
@args[name.to_sym] || @args[:"#{name}?"]
end

def wrap_option_desc(desc)
Expand Down
12 changes: 6 additions & 6 deletions Library/Homebrew/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def self.method_name(cmd)
def self.args_method_name(cmd_path)
cmd_path_basename = basename_without_extension(cmd_path)
cmd_method_prefix = method_name(cmd_path_basename)
"#{cmd_method_prefix}_args".to_sym
:"#{cmd_method_prefix}_args"
end

def self.internal_cmd_path(cmd)
Expand Down Expand Up @@ -217,12 +217,12 @@ def self.command_description(command, short: false)
# skip the comment's initial usage summary lines
comment_lines.slice(2..-1)&.each do |line|
match_data = /^#: (?<desc>\w.*+)$/.match(line)
if match_data
desc = match_data[:desc]
return T.must(desc).split(DESCRIPTION_SPLITTING_PATTERN).first if short
next unless match_data

return desc
end
desc = match_data[:desc]
return T.must(desc).split(DESCRIPTION_SPLITTING_PATTERN).first if short

return desc
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dependable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def options
end

def prune_from_option?(build)
return if !optional? && !recommended?
return false if !optional? && !recommended?

build.without?(self)
end
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/dev-cmd/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ def self.audit
# For switches, we add `|| nil` so that `nil` will be passed
# instead of `false` if they aren't set.
# This way, we can distinguish between "not set" and "set to false".
audit_online: (args.online? || nil),
audit_strict: (args.strict? || nil),
audit_online: args.online? || nil,
audit_strict: args.strict? || nil,

# No need for `|| nil` for `--[no-]signing`
# because boolean switches are already `nil` if not passed
audit_signing: args.signing?,
audit_new_cask: (new_cask || nil),
audit_token_conflicts: (args.token_conflicts? || nil),
audit_new_cask: new_cask || nil,
audit_token_conflicts: args.token_conflicts? || nil,
quarantine: true,
any_named_args: !no_named_args,
only: args.only,
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def self.keg_contain?(string, keg, ignores, formula_and_runtime_deps_names = nil

@put_filenames ||= []

return if @put_filenames.include?(filename)
return false if @put_filenames.include?(filename)

puts Formatter.error(filename.to_s)
@put_filenames << filename
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/contributions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def contributions
contribution_types = [:author, :committer, :coauthorship, :review]

users = args.user.presence || GitHub.members_by_team("Homebrew", "maintainers")
users.each do |username, _|
users.each_key do |username|
# TODO: Using the GitHub username to scan the `git log` undercounts some
# contributions as people might not always have configured their Git
# committer details to match the ones on GitHub.
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/dev-cmd/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def formula
formula_paths = args.named.to_paths(only: :formula).select(&:exist?)
if formula_paths.blank? && args.named
.to_paths(only: :cask)
.select(&:exist?)
.present?
.any?(&:exist?)
odie "Found casks but did not find formulae!"
end
formula_paths.each(&method(:puts))
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/pr-pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def self.cherry_pick_pr!(user, repo, pull_request, args:, path: ".")
end

def self.formulae_need_bottles?(tap, original_commit, labels, args:)
return if args.dry_run?
return false if args.dry_run?

return false if labels.include?("CI-syntax-only") || labels.include?("CI-no-bottles")

Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/extend/on_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def self.setup_arch_methods(base)
@on_system_blocks_exist = true

return arm if OnSystem.arch_condition_met? :arm
return intel if OnSystem.arch_condition_met? :intel

intel if OnSystem.arch_condition_met? :intel
end
end

Expand Down Expand Up @@ -111,7 +112,8 @@ def self.setup_base_os_methods(base)
@on_system_blocks_exist = true

return macos if OnSystem.os_condition_met?(:macos) && macos.present?
return linux if OnSystem.os_condition_met?(:linux) && linux.present?

linux if OnSystem.os_condition_met?(:linux) && linux.present?
end
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ def self.racks
# @private
sig { returns(T::Array[String]) }
def self.installed_formula_names
racks.map(&:basename).map(&:to_s)
racks.map { |rack| rack.basename.to_s }
end

# An array of all installed {Formula}
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def audit_text
[formula.bin, formula.sbin].each do |dir|
next unless dir.exist?

bin_names += dir.children.map(&:basename).map(&:to_s)
bin_names += dir.children.map { |child| child.basename.to_s }
end
shell_commands = ["system", "shell_output", "pipe_output"]
bin_names.each do |name|
Expand Down
11 changes: 5 additions & 6 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class FormulaInstaller
include FormulaCellarChecks
extend Predicable

attr_reader :formula
attr_reader :bottle_tab_runtime_dependencies
attr_reader :formula, :bottle_tab_runtime_dependencies

attr_accessor :options, :link_keg

Expand Down Expand Up @@ -530,7 +529,7 @@ def compute_dependencies(use_cache: true)
end

def unbottled_dependencies(deps)
deps.map(&:first).map(&:to_formula).reject do |dep_f|
deps.map { |(dep, _options)| dep.to_formula }.reject do |dep_f|
next false unless dep_f.pour_bottle?

dep_f.bottled?
Expand Down Expand Up @@ -1184,7 +1183,7 @@ def fetch_dependencies
return if ignore_deps?

# Don't output dependencies if we're explicitly installing them.
deps = compute_dependencies.reject do |dep, _options|
deps = compute_dependencies.reject do |(dep, _options)|
self.class.fetched.include?(dep.to_formula)
end

Expand All @@ -1194,7 +1193,7 @@ def fetch_dependencies
"#{deps.map(&:first).map(&Formatter.method(:identifier)).to_sentence}",
truncate: false

deps.each { |dep, _options| fetch_dependency(dep) }
deps.each { |(dep, _options)| fetch_dependency(dep) }
end

sig { returns(T.nilable(Formula)) }
Expand Down Expand Up @@ -1369,7 +1368,7 @@ def forbidden_license_check
return if forbidden_licenses.blank?
return if ignore_deps?

compute_dependencies.each do |dep, _|
compute_dependencies.each do |(dep, _options)|
dep_f = dep.to_formula
next unless SPDX.licenses_forbid_installation? dep_f.license, forbidden_licenses

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ def install_formulae(
end
end

def print_dry_run_dependencies(formula, dependencies, &block)
def print_dry_run_dependencies(formula, dependencies)
return if dependencies.empty?

ohai "Would install #{Utils.pluralize("dependenc", dependencies.count, plural: "ies", singular: "y",
include_count: true)} for #{formula.name}:"
formula_names = dependencies.map(&:first).map(&:to_formula).map(&block)
formula_names = dependencies.map { |(dep, _options)| yield dep.to_formula }
puts formula_names.join(" ")
end

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/language/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def self.each_python(build, &block)
end

def self.reads_brewed_pth_files?(python)
return unless homebrew_site_packages(python).directory?
return unless homebrew_site_packages(python).writable_real?
return false unless homebrew_site_packages(python).directory?
return false unless homebrew_site_packages(python).writable_real?

probe_file = homebrew_site_packages(python)/"homebrew-pth-probe.pth"
begin
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/livecheck/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,6 @@ def resource_version(
end
resource_version_info[:meta][:regex] = regex.inspect if regex.present?
resource_version_info[:meta][:cached] = true if strategy_data[:cached] == true

rescue => e
Homebrew.failed = true
if json
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def self.try_parse(string)
scanner = StringScanner.new(string)

if (language = scanner.scan(LANGUAGE_REGEX))
sep = scanner.scan(/-/)
sep = scanner.scan("-")
return if (sep && scanner.eos?) || (sep.nil? && !scanner.eos?)
end

if (script = scanner.scan(SCRIPT_REGEX))
sep = scanner.scan(/-/)
sep = scanner.scan("-")
return if (sep && scanner.eos?) || (sep.nil? && !scanner.eos?)
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/os/mac/mach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def change_install_name(old, new, **options)

def dynamically_linked_libraries(except: :none, resolve_variable_references: true)
lcs = macho.dylib_load_commands.reject { |lc| lc.type == except }
names = lcs.map(&:name).map(&:to_s).uniq
names = lcs.map { |lc| lc.name.to_s }.uniq
names.map!(&method(:resolve_variable_name)) if resolve_variable_references

names
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/rubocops/dependency_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def insert_after!(arr, idx1, idx2)

def build_with_dependency_name(node)
match_nodes = build_with_dependency_node(node)
match_nodes = match_nodes.to_a.delete_if(&:nil?)
match_nodes = match_nodes.to_a.compact
match_nodes.map { |n| string_content(n) } unless match_nodes.empty?
end

Expand Down
8 changes: 5 additions & 3 deletions Library/Homebrew/rubocops/extend/formula_cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,22 @@ def audit_urls(urls, regex)
end
end

# Returns nil if does not depend on dependency_name.
# Returns if the formula depends on dependency_name.
#
# @param dependency_name dependency's name
def depends_on?(dependency_name, *types)
return if @body.nil?
return false if @body.nil?

types = [:any] if types.empty?
dependency_nodes = find_every_method_call_by_name(@body, :depends_on)
idx = dependency_nodes.index do |n|
types.any? { |type| depends_on_name_type?(n, dependency_name, type) }
end
return if idx.nil?
return false if idx.nil?

@offensive_node = dependency_nodes[idx]

true
end

# Returns true if given dependency name and dependency type exist in given dependency method call node.
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/standalone/sorbet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def sig(arg0 = nil, &blk); end
end

# For any cases the above doesn't handle: make sure we don't let TypeError slip through.
T::Configuration.call_validation_error_handler = ->(signature, opts) do end
T::Configuration.inline_type_error_handler = ->(error, opts) do end
T::Configuration.call_validation_error_handler = ->(signature, opts) {}
T::Configuration.inline_type_error_handler = ->(error, opts) {}
end

0 comments on commit 843eb8c

Please sign in to comment.