Skip to content

Commit 4c9de7d

Browse files
authored
Merge pull request #19084 from Homebrew/add-comments-to-rubocop-disables
Add clarifying comments to `rubocop:disable`s
2 parents 730c93e + 9c8ff4c commit 4c9de7d

27 files changed

+43
-4
lines changed

Library/Homebrew/brew.rb

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@
200200
end
201201

202202
exit 1
203+
# Catch any other types of exceptions.
203204
rescue Exception => e # rubocop:disable Lint/RescueException
204205
onoe e
205206

Library/Homebrew/build.rb

+2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ def fixopt(formula)
230230
options = Options.create(args.flags_only)
231231
build = Build.new(formula, options, args:)
232232
build.install
233+
# Any exception means the build did not complete.
234+
# The `case` for what to do per-exception class is further down.
233235
rescue Exception => e # rubocop:disable Lint/RescueException
234236
error_hash = JSON.parse e.to_json
235237

Library/Homebrew/cask/dsl/depends_on.rb

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def macos=(*args)
6363
MacOSRequirement.new([T.must(md[:version]).to_sym], comparator: md[:comparator])
6464
elsif (md = /^\s*(?<comparator><|>|[=<>]=)\s*(?<version>\S+)\s*$/.match(first_arg))
6565
MacOSRequirement.new([md[:version]], comparator: md[:comparator])
66+
# This is not duplicate of the first case: see `args.first` and a different comparator.
6667
else # rubocop:disable Lint/DuplicateBranch
6768
MacOSRequirement.new([args.first], comparator: "==")
6869
end

Library/Homebrew/cmd/update-report.rb

+1
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ def migrate_tap_migration
626626
unless Formulary.factory(new_full_name).keg_only?
627627
system HOMEBREW_BREW_FILE, "link", new_full_name, "--overwrite"
628628
end
629+
# Rescue any possible exception types.
629630
rescue Exception => e # rubocop:disable Lint/RescueException
630631
if Homebrew::EnvConfig.developer?
631632
require "utils/backtrace"

Library/Homebrew/dev-cmd/test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def run
9999
exec(*exec_args)
100100
end
101101
end
102+
# Rescue any possible exception types.
102103
rescue Exception => e # rubocop:disable Lint/RescueException
103104
retry if retry_test?(f)
104105

Library/Homebrew/download_queue.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize(size = 1)
1919
sig { params(downloadable: Downloadable, force: T::Boolean).returns(Concurrent::Promises::Future) }
2020
def enqueue(downloadable, force: false)
2121
quiet = pool.max_length > 1
22-
# Passing in arguments from outside into the future is a common `concurrent-ruby` pattern.
22+
# Passing in arguments from outside into the future is a common `concurrent-ruby` pattern.
2323
# rubocop:disable Lint/ShadowingOuterLocalVariable
2424
Concurrent::Promises.future_on(pool, downloadable, force, quiet) do |downloadable, force, quiet|
2525
downloadable.clear_cache if force

Library/Homebrew/download_strategy.rbi

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# typed: strict
22

3-
# This is a third-party implementation
3+
# This is a third-party implementation.
44
# rubocop:disable Lint/StructNewOverride
55
class Mechanize::HTTP
66
ContentDisposition = Struct.new :type, :filename, :creation_date,
77
:modification_date, :read_date, :size, :parameters
88
end
99
# rubocop:enable Lint/StructNewOverride
1010

11+
# This is a third-party implementation.
1112
# rubocop:disable Style/OptionalBooleanParameter
1213
class Mechanize::HTTP::ContentDispositionParser
1314
sig {

Library/Homebrew/extend/os/mac/readall.rb

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def valid_casks?(tap, os_name: nil, arch: ::Hardware::CPU.type)
3131
raise "Missing URL" if cask.url.nil?
3232
rescue Interrupt
3333
raise
34+
# Handle all possible exceptions reading Casks.
3435
rescue Exception => e # rubocop:disable Lint/RescueException
3536
os_and_arch = "macOS #{current_macos_version} on #{arch}"
3637
onoe "Invalid cask (#{os_and_arch}): #{file}"

Library/Homebrew/formula.rb

+1
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,7 @@ def run_test(keep_tmp: false)
29032903
test
29042904
end
29052905
end
2906+
# Handle all possible exceptions running formula tests.
29062907
rescue Exception # rubocop:disable Lint/RescueException
29072908
staging.retain! if debug?
29082909
raise

Library/Homebrew/formula_installer.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ def install
484484
if pour_bottle?
485485
begin
486486
pour
487+
# Catch any other types of exceptions as they leave us with nothing installed.
487488
rescue Exception # rubocop:disable Lint/RescueException
488-
# any exceptions must leave us with nothing installed
489489
ignore_interrupts do
490490
begin
491491
FileUtils.rm_r(formula.prefix) if formula.prefix.directory?
@@ -825,6 +825,7 @@ def install_dependency(dep, inherited_options)
825825
oh1 "Installing #{formula.full_name} dependency: #{Formatter.identifier(dep.name)}"
826826
fi.install
827827
fi.finish
828+
# Handle all possible exceptions installing deps.
828829
rescue Exception => e # rubocop:disable Lint/RescueException
829830
ignore_interrupts do
830831
tmp_keg.rename(installed_keg.to_path) if tmp_keg && !installed_keg.directory?
@@ -1022,6 +1023,7 @@ def build
10221023
formula.update_head_version
10231024

10241025
raise "Empty installation" if !formula.prefix.directory? || Keg.new(formula.prefix).empty_installation?
1026+
# Handle all possible exceptions when building.
10251027
rescue Exception => e # rubocop:disable Lint/RescueException
10261028
if e.is_a? BuildError
10271029
e.formula = formula
@@ -1099,6 +1101,7 @@ def link(keg)
10991101
puts "You can try again using:"
11001102
puts " brew link #{formula.name}"
11011103
@show_summary_heading = true
1104+
# Handle all other possible exceptions when linking.
11021105
rescue Exception => e # rubocop:disable Lint/RescueException
11031106
ofail "An unexpected error occurred during the `brew link` step"
11041107
puts "The formula built, but is not symlinked into #{HOMEBREW_PREFIX}"
@@ -1151,6 +1154,7 @@ def install_service
11511154
launchd_service_path.chmod 0644
11521155
log = formula.var/"log"
11531156
log.mkpath if service.include? log.to_s
1157+
# Handle all possible exceptions when installing service files.
11541158
rescue Exception => e # rubocop:disable Lint/RescueException
11551159
puts e
11561160
ofail "Failed to install service files"
@@ -1162,6 +1166,7 @@ def install_service
11621166
sig { params(keg: Keg).void }
11631167
def fix_dynamic_linkage(keg)
11641168
keg.fix_dynamic_linkage
1169+
# Rescue all possible exceptions when fixing linkage.
11651170
rescue Exception => e # rubocop:disable Lint/RescueException
11661171
ofail "Failed to fix install linkage"
11671172
puts "The formula built, but you may encounter issues using it or linking other"
@@ -1177,6 +1182,7 @@ def fix_dynamic_linkage(keg)
11771182
def clean
11781183
ohai "Cleaning" if verbose?
11791184
Cleaner.new(formula).clean
1185+
# Handle all possible exceptions when cleaning does not complete.
11801186
rescue Exception => e # rubocop:disable Lint/RescueException
11811187
opoo "The cleaning step did not complete successfully"
11821188
puts "Still, the installation was successful, so we will link it into your prefix."
@@ -1249,6 +1255,7 @@ def post_install
12491255
exec(*args)
12501256
end
12511257
end
1258+
# Handle all possible exceptions when postinstall does not complete.
12521259
rescue Exception => e # rubocop:disable Lint/RescueException
12531260
opoo "The post-install step did not complete successfully"
12541261
puts "You can try again using:"

Library/Homebrew/ignorable.rb

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def self.hook_raise
2525
def raise(*)
2626
callcc do |continuation|
2727
super
28+
# Handle all possible exceptions.
2829
rescue Exception => e # rubocop:disable Lint/RescueException
2930
unless e.is_a?(ScriptError)
3031
e.extend(ExceptionMixin)

Library/Homebrew/migrator.rb

+2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def migrate
223223
EOS
224224
rescue Interrupt
225225
ignore_interrupts { backup_oldname }
226+
# Any exception means the migration did not complete.
226227
rescue Exception => e # rubocop:disable Lint/RescueException
227228
onoe "The migration did not complete successfully."
228229
puts e
@@ -357,6 +358,7 @@ def link_newname
357358
puts
358359
puts "You can try again using:"
359360
puts " brew link #{formula.name}"
361+
# Any exception means the `brew link` step did not complete.
360362
rescue Exception => e # rubocop:disable Lint/RescueException
361363
onoe "An unexpected error occurred during linking"
362364
puts e

Library/Homebrew/postinstall.rb

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
formula.extend(Debrew::Formula)
2828
end
2929
formula.run_post_install
30+
# Handle all possible exceptions.
3031
rescue Exception => e # rubocop:disable Lint/RescueException
3132
error_pipe.puts e.to_json
3233
error_pipe.close

Library/Homebrew/readall.rb

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def self.valid_formulae?(tap, bottle_tag: nil)
7474
end
7575
rescue Interrupt
7676
raise
77+
# Handle all possible exceptions reading formulae.
7778
rescue Exception => e # rubocop:disable Lint/RescueException
7879
onoe "Invalid formula (#{bottle_tag}): #{file}"
7980
$stderr.puts e

Library/Homebrew/reinstall.rb

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def self.reinstall_formula(
7070
fi.finish
7171
rescue FormulaInstallationAlreadyAttemptedError
7272
nil
73+
# Any other exceptions we want to restore the previous keg and report the error.
7374
rescue Exception # rubocop:disable Lint/RescueException
7475
ignore_interrupts { restore_backup(keg, link_keg, verbose:) }
7576
raise

Library/Homebrew/resource_auditor.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def audit_download_strategy
9191

9292
def audit_checksum
9393
return if spec_name == :head
94-
# rubocop:disable Style/InvertibleUnlessCondition (non-invertible)
94+
# This condition is non-invertible.
95+
# rubocop:disable Style/InvertibleUnlessCondition
9596
return unless DownloadStrategyDetector.detect(url, using) <= CurlDownloadStrategy
9697
# rubocop:enable Style/InvertibleUnlessCondition
9798

Library/Homebrew/tap.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ def self.all
10611061
cache[:all] ||= begin
10621062
core_taps = [
10631063
CoreTap.instance,
1064+
# The conditional is valid here because we only want the cask tap on macOS.
10641065
(CoreCaskTap.instance if OS.mac?), # rubocop:disable Homebrew/MoveToExtendOS
10651066
].compact
10661067

Library/Homebrew/test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
timeout = ENV["HOMEBREW_TEST_TIMEOUT_SECS"]&.to_i || DEFAULT_TEST_TIMEOUT_SECONDS
5454
Timeout.timeout(timeout, &run_test)
5555
end
56+
# Any exceptions during the test run are reported.
5657
rescue Exception => e # rubocop:disable Lint/RescueException
5758
error_pipe.puts e.to_json
5859
error_pipe.close

Library/Homebrew/test/commands_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "commands"
44

5+
# These shared contexts starting with `when` don't make sense.
56
RSpec.shared_context "custom internal commands" do # rubocop:disable RSpec/ContextWording
67
let(:cmds) do
78
[

Library/Homebrew/test/macos_version_spec.rb

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
specify "comparison with Symbol" do
2323
expect(version).to be > :high_sierra
2424
expect(version).to eq :mojave
25+
# We're explicitly testing the `===` operator results here.
2526
expect(version).to be === :mojave # rubocop:disable Style/CaseEquality
2627
expect(version).to be < :catalina
2728
end
@@ -34,13 +35,15 @@
3435
specify "comparison with String" do
3536
expect(version).to be > "10.3"
3637
expect(version).to eq "10.14"
38+
# We're explicitly testing the `===` operator results here.
3739
expect(version).to be === "10.14" # rubocop:disable Style/CaseEquality
3840
expect(version).to be < "10.15"
3941
end
4042

4143
specify "comparison with Version" do
4244
expect(version).to be > Version.new("10.3")
4345
expect(version).to eq Version.new("10.14")
46+
# We're explicitly testing the `===` operator results here.
4447
expect(version).to be === Version.new("10.14") # rubocop:disable Style/CaseEquality
4548
expect(version).to be < Version.new("10.15")
4649
end

Library/Homebrew/test/rubocops/patches_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def patches
6767
expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 4, source:)
6868
FormulaAudit/Patches: Patches from Debian should be https://, not http: #{patch_url}
6969
EOS
70+
# GitHub patch diff regexps can't be any shorter.
7071
# rubocop:disable Layout/LineLength
7172
elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)})
7273
# rubocop:enable Layout/LineLength
@@ -232,6 +233,7 @@ class Foo < Formula
232233
expect_offense_hash(message: <<~EOS.chomp, severity: :convention, line: 5, column: 8, source:)
233234
FormulaAudit/Patches: GitLab patches should end with .diff, not .patch: #{patch_url}
234235
EOS
236+
# GitHub patch diff regexps can't be any shorter.
235237
# rubocop:disable Layout/LineLength
236238
elsif patch_url.match?(%r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)})
237239
# rubocop:enable Layout/LineLength

Library/Homebrew/test/support/helper/spec/shared_context/homebrew_cask.rb

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Config
3131
end
3232
end
3333

34+
# These shared contexts starting with `when` don't make sense.
3435
RSpec.shared_context "Homebrew Cask", :needs_macos do # rubocop:disable RSpec/ContextWording
3536
around do |example|
3637
third_party_tap = Tap.fetch("third-party", "tap")

Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
RSpec::Matchers.define_negated_matcher :be_a_failure, :be_a_success
88

9+
# These shared contexts starting with `when` don't make sense.
910
RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWording
1011
extend RSpec::Matchers::DSL
1112

Library/Homebrew/test/utils/inreplace_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
it "raises error if there is nothing to replace in block form" do
3434
expect do
3535
described_class.inreplace(file.path) do |s|
36+
# Using `gsub!` here is what we want, and it's only a test.
3637
s.gsub!("d", "f") # rubocop:disable Performance/StringReplacement
3738
end
3839
end.to raise_error(Utils::Inreplace::Error)

Library/Homebrew/test/utils/spdx_spec.rb

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
license_expression = { any_of: [
7676
"MIT",
7777
:public_domain,
78+
# The final array item is legitimately a hash in the case of license expressions.
7879
all_of: ["0BSD", "Zlib"], # rubocop:disable Style/HashAsLastArrayItem
7980
"curl" => { with: "LLVM-exception" },
8081
] }
@@ -195,6 +196,7 @@
195196
license_expression = { any_of: [
196197
"MIT",
197198
:public_domain,
199+
# The final array item is legitimately a hash in the case of license expressions.
198200
all_of: ["0BSD", "Zlib"], # rubocop:disable Style/HashAsLastArrayItem
199201
"curl" => { with: "LLVM-exception" },
200202
] }
@@ -235,6 +237,7 @@
235237
})
236238
end
237239

240+
# The final array item is legitimately a hash in the case of license expressions.
238241
# rubocop:disable Style/HashAsLastArrayItem
239242
it "handles nested brackets" do
240243
expect(described_class.string_to_license_expression("A AND (B OR (C AND D))")).to eq({

Library/Homebrew/test/utils/string_inreplace_extension_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269
let(:string) { "foo" }
270270

271271
it "replaces all occurrences" do
272+
# Using `gsub!` here is what we want, and it's only a test.
272273
string_extension.gsub!("o", "e") # rubocop:disable Performance/StringReplacement
273274
expect(string_extension.inreplace_string).to eq("fee")
274275
end

Library/Homebrew/utils/fork.rb

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def self.safe_fork(directory: nil, yield_parent: false)
5252
Process::UID.change_privilege(Process.euid) if Process.euid != Process.uid
5353

5454
yield(error_pipe)
55+
# This could be any type of exception, so rescue them all.
5556
rescue Exception => e # rubocop:disable Lint/RescueException
5657
error_hash = JSON.parse e.to_json
5758

0 commit comments

Comments
 (0)