diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index b5cdb52bf7..ff63f835f1 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -7,10 +7,6 @@ Layout/MultilineMethodCallIndentation: Exclude: - "**/*_spec.rb" -# TODO: add parentheses for these and remove -Lint/AssignmentInCondition: - Enabled: false - # `formula do` uses nested method definitions Lint/NestedMethodDefinition: Exclude: diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 897ba8a535..a514a073b7 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -696,7 +696,7 @@ module Cask def check_denylist return unless cask.tap return unless cask.tap.official? - return unless reason = Denylist.reason(cask.token) + return unless (reason = Denylist.reason(cask.token)) add_error "#{cask.token} is not allowed: #{reason}" end diff --git a/Library/Homebrew/cask/caskroom.rb b/Library/Homebrew/cask/caskroom.rb index c65d5649ac..ded8b2e81c 100644 --- a/Library/Homebrew/cask/caskroom.rb +++ b/Library/Homebrew/cask/caskroom.rb @@ -39,9 +39,9 @@ module Cask Pathname.glob(path.join("*")).sort.select(&:directory?).map do |path| token = path.basename.to_s - if tap_path = CaskLoader.tap_paths(token).first + if (tap_path = CaskLoader.tap_paths(token).first) CaskLoader::FromTapPathLoader.new(tap_path).load(config: config) - elsif caskroom_path = Pathname.glob(path.join(".metadata/*/*/*/*.rb")).first + elsif (caskroom_path = Pathname.glob(path.join(".metadata/*/*/*/*.rb")).first) CaskLoader::FromPathLoader.new(caskroom_path).load(config: config) else CaskLoader.load(token, config: config) diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 0f1467862d..9cf507aa71 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -191,7 +191,7 @@ module Cask basename = downloader.basename - if nested_container = @cask.container&.nested + if (nested_container = @cask.container&.nested) Dir.mktmpdir do |tmpdir| tmpdir = Pathname(tmpdir) primary_container.extract(to: tmpdir, basename: basename, verbose: verbose?) diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 47ef774cdc..687c94518e 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -80,7 +80,7 @@ module Homebrew version = Version.new(version) - return false unless formula_name = basename.to_s[/\A(.*?)(?:--.*?)*--?(?:#{Regexp.escape(version)})/, 1] + return false unless (formula_name = basename.to_s[/\A(.*?)(?:--.*?)*--?(?:#{Regexp.escape(version)})/, 1]) formula = begin Formulary.from_rack(HOMEBREW_CELLAR/formula_name) @@ -95,7 +95,7 @@ module Homebrew if resource_name == "patch" patch_hashes = formula.stable&.patches&.select(&:external?)&.map(&:resource)&.map(&:version) return true unless patch_hashes&.include?(Checksum.new(version.to_s)) - elsif resource_name && resource_version = formula.stable&.resources&.dig(resource_name)&.version + elsif resource_name && (resource_version = formula.stable&.resources&.dig(resource_name)&.version) return true if resource_version != version elsif version.is_a?(PkgVersion) return true if formula.pkg_version > version @@ -111,7 +111,7 @@ module Homebrew end def stale_cask?(scrub) - return false unless name = basename.to_s[/\A(.*?)--/, 1] + return false unless (name = basename.to_s[/\A(.*?)--/, 1]) cask = begin Cask::CaskLoader.load(name) diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index ed43646664..b00e0aed3f 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -623,7 +623,7 @@ module Homebrew end def split_non_options(argv) - if sep = argv.index("--") + if (sep = argv.index("--")) [argv.take(sep), argv.drop(sep + 1)] else [argv, []] diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 7d5b1f8f04..091e563fea 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -227,7 +227,7 @@ module Homebrew def info_formula(f, args:) specs = [] - if stable = f.stable + if (stable = f.stable) s = "stable #{stable.version}" s += " (bottled)" if stable.bottled? && f.pour_bottle? specs << s diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 25fbee9de6..b02fca771b 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -264,7 +264,7 @@ module Homebrew end end opoo msg if msg - elsif !f.any_version_installed? && old_formula = f.old_installed_formulae.first + elsif !f.any_version_installed? && (old_formula = f.old_installed_formulae.first) msg = "#{old_formula.full_name} #{old_formula.any_installed_version} already installed" msg = if !old_formula.linked? && !old_formula.keg_only? <<~EOS diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 66ca2764cf..755458f636 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -73,7 +73,7 @@ module Homebrew def search args = search_args.parse - if package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] } + if (package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] }) _, url = package_manager exec_browser url.call(URI.encode_www_form_component(args.named.join(" "))) return diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index 23ebde0cfc..4004392fd6 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -175,7 +175,7 @@ module Commands path = self.path(command) return if path.blank? - if cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path) + if (cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path)) cmd_parser.processed_options.map do |short, long, _, desc| [long || short, desc] end @@ -198,7 +198,7 @@ module Commands path = self.path(command) return if path.blank? - if cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path) + if (cmd_parser = Homebrew::CLI::Parser.from_cmd_path(path)) if short cmd_parser.description.split(".").first else diff --git a/Library/Homebrew/completions.rb b/Library/Homebrew/completions.rb index 583d5cef6c..f0d04baf97 100644 --- a/Library/Homebrew/completions.rb +++ b/Library/Homebrew/completions.rb @@ -167,7 +167,7 @@ module Homebrew return unless command_gets_completions? command named_completion_string = "" - if types = Commands.named_args_type(command) + if (types = Commands.named_args_type(command)) named_args_strings, named_args_types = types.partition { |type| type.is_a? String } named_args_types.each do |type| @@ -221,7 +221,7 @@ module Homebrew conflicts = generate_zsh_option_exclusions(command, opt) "#{conflicts}#{opt}[#{format_description desc}]" end - if types = Commands.named_args_type(command) + if (types = Commands.named_args_type(command)) named_args_strings, named_args_types = types.partition { |type| type.is_a? String } named_args_types.each do |type| @@ -291,7 +291,7 @@ module Homebrew subcommands = [] named_args = [] - if types = Commands.named_args_type(command) + if (types = Commands.named_args_type(command)) named_args_strings, named_args_types = types.partition { |type| type.is_a? String } named_args_types.each do |type| diff --git a/Library/Homebrew/context.rb b/Library/Homebrew/context.rb index 7655c8eaa7..5a9c410bcc 100644 --- a/Library/Homebrew/context.rb +++ b/Library/Homebrew/context.rb @@ -16,7 +16,7 @@ module Context end def self.current - if current_context = Thread.current[:context] + if (current_context = Thread.current[:context]) return current_context end diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 5d4af842d9..032552a218 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -254,7 +254,7 @@ module Homebrew def bottle_formula(f, args:) return ofail "Formula not installed or up-to-date: #{f.full_name}" unless f.latest_version_installed? - unless tap = f.tap + unless (tap = f.tap) return ofail "Formula not from core or any installed taps: #{f.full_name}" unless args.force_core_tap? tap = CoreTap.instance diff --git a/Library/Homebrew/dev-cmd/create.rb b/Library/Homebrew/dev-cmd/create.rb index 23f9b7bdbc..0d4e4b6ccd 100644 --- a/Library/Homebrew/dev-cmd/create.rb +++ b/Library/Homebrew/dev-cmd/create.rb @@ -179,7 +179,7 @@ module Homebrew # Check for disallowed formula, or names that shadow aliases, # unless --force is specified. unless args.force? - if reason = MissingFormula.disallowed_reason(fc.name) + if (reason = MissingFormula.disallowed_reason(fc.name)) odie <<~EOS The formula '#{fc.name}' is not allowed to be created. #{reason} diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index 2d375eaa6a..096f0bb645 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -164,7 +164,7 @@ module Homebrew # preserve existing manpage order cmd_paths.sort_by(&method(:sort_key_for_path)) .each do |cmd_path| - cmd_man_page_lines = if cmd_parser = CLI::Parser.from_cmd_path(cmd_path) + cmd_man_page_lines = if (cmd_parser = CLI::Parser.from_cmd_path(cmd_path)) next if cmd_parser.hide_from_man_page cmd_parser_manpage_lines(cmd_parser).join diff --git a/Library/Homebrew/dev-cmd/unpack.rb b/Library/Homebrew/dev-cmd/unpack.rb index 011b87b224..1cc12aa895 100644 --- a/Library/Homebrew/dev-cmd/unpack.rb +++ b/Library/Homebrew/dev-cmd/unpack.rb @@ -38,7 +38,7 @@ module Homebrew formulae = args.named.to_formulae - if dir = args.destdir + if (dir = args.destdir) unpack_dir = Pathname.new(dir).expand_path unpack_dir.mkpath else diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index 55e4a41082..a7b798d49e 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -54,9 +54,9 @@ module Homebrew start_commit, end_commit = nil cd HOMEBREW_REPOSITORY do - start_commit = if commit = args.commit + start_commit = if (commit = args.commit) commit - elsif date = args.before + elsif (date = args.before) Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp elsif args.to_tag? tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") diff --git a/Library/Homebrew/development_tools.rb b/Library/Homebrew/development_tools.rb index 99704ec69f..55171f73c8 100644 --- a/Library/Homebrew/development_tools.rb +++ b/Library/Homebrew/development_tools.rb @@ -43,7 +43,7 @@ class DevelopmentTools def clang_version @clang_version ||= begin if (path = locate("clang")) && - build_version = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d)/, 1] + (build_version = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d)/, 1]) Version.new build_version else Version::NULL @@ -54,7 +54,7 @@ class DevelopmentTools def clang_build_version @clang_build_version ||= begin if (path = locate("clang")) && - build_version = `#{path} --version`[%r{clang(-| version [^ ]+ \(tags/RELEASE_)(\d{2,})}, 2] + (build_version = `#{path} --version`[%r{clang(-| version [^ ]+ \(tags/RELEASE_)(\d{2,})}, 2]) Version.new build_version else Version::NULL @@ -66,7 +66,7 @@ class DevelopmentTools @llvm_clang_build_version ||= begin path = Formulary.factory("llvm").opt_prefix/"bin/clang" if path.executable? && - build_version = `#{path} --version`[/clang version (\d\.\d\.\d)/, 1] + (build_version = `#{path} --version`[/clang version (\d\.\d\.\d)/, 1]) Version.new build_version else Version::NULL @@ -79,7 +79,7 @@ class DevelopmentTools path = HOMEBREW_PREFIX/"opt/#{CompilerSelector.preferred_gcc}/bin"/cc path = locate(cc) unless path.exist? version = if path && - build_version = `#{path} --version`[/gcc(?:(?:-\d+(?:\.\d)?)? \(.+\))? (\d+\.\d\.\d)/, 1] + (build_version = `#{path} --version`[/gcc(?:(?:-\d+(?:\.\d)?)? \(.+\))? (\d+\.\d\.\d)/, 1]) Version.new build_version else Version::NULL diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 80c31d5210..7251eda288 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -441,11 +441,11 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy content_disposition_parser = Mechanize::HTTP::ContentDispositionParser.new parse_content_disposition = lambda do |line| - next unless content_disposition = content_disposition_parser.parse(line.sub(/; *$/, ""), true) + next unless (content_disposition = content_disposition_parser.parse(line.sub(/; *$/, ""), true)) filename = nil - if filename_with_encoding = content_disposition.parameters["filename*"] + if (filename_with_encoding = content_disposition.parameters["filename*"]) encoding, encoded_filename = filename_with_encoding.split("''", 2) filename = URI.decode_www_form_component(encoded_filename).encode(encoding) if encoding && encoded_filename end diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 3c277e20c4..1a8d0abee2 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -453,7 +453,7 @@ class BuildError < RuntimeError if formula.tap && defined?(OS::ISSUES_URL) if formula.tap.official? puts Formatter.error(Formatter.url(OS::ISSUES_URL), label: "READ THIS") - elsif issues_url = formula.tap.issues_url + elsif (issues_url = formula.tap.issues_url) puts <<~EOS If reporting this issue please do so at (not Homebrew/brew or Homebrew/core): #{Formatter.url(issues_url)} diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 9ffd65f6f9..71f79ce207 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2061,7 +2061,7 @@ class Formula if verbose_using_dots last_dot = Time.at(0) - while buf = rd.gets + while (buf = rd.gets) log.puts buf # make sure dots printed with interval of at least 1 min. next unless (Time.now - last_dot) > 60 @@ -2072,7 +2072,7 @@ class Formula end puts else - while buf = rd.gets + while (buf = rd.gets) log.puts buf puts buf end diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index 761d921710..9d4a691144 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -133,7 +133,7 @@ module Homebrew return end - if oldname = CoreTap.instance.formula_renames[name] + if (oldname = CoreTap.instance.formula_renames[name]) problem "'#{name}' is reserved as the old name of #{oldname} in homebrew/core." return end @@ -367,10 +367,10 @@ module Homebrew return unless DevelopmentTools.curl_handles_most_https_certificates? - if http_content_problem = curl_check_http_content(homepage, - user_agents: [:browser, :default], - check_content: true, - strict: @strict) + if (http_content_problem = curl_check_http_content(homepage, + user_agents: [:browser, :default], + check_content: true, + strict: @strict)) problem http_content_problem end end @@ -472,7 +472,7 @@ module Homebrew %w[Stable HEAD].each do |name| spec_name = name.downcase.to_sym - next unless spec = formula.send(spec_name) + next unless (spec = formula.send(spec_name)) ra = ResourceAuditor.new(spec, spec_name, online: @online, strict: @strict).audit ra.problems.each do |message| @@ -497,7 +497,7 @@ module Homebrew ) end - if stable = formula.stable + if (stable = formula.stable) version = stable.version problem "Stable: version (#{version}) is set to a string without a digit" if version.to_s !~ /\d/ if version.to_s.start_with?("HEAD") diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 8c04ac78f3..e0e8d47f7b 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -575,7 +575,7 @@ class FormulaInstaller formula_deps_map = Dependency.expand(formula) .index_by(&:name) - while f = formulae.pop + while (f = formulae.pop) runtime_requirements = runtime_requirements(f) f.recursive_requirements do |dependent, req| build = effective_build_options_for(dependent) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 52f18dbef7..6cf9826174 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -467,14 +467,14 @@ module Formulary return FormulaLoader.new(name, path) end - if newref = CoreTap.instance.formula_renames[ref] + if (newref = CoreTap.instance.formula_renames[ref]) formula_with_that_oldname = core_path(newref) return FormulaLoader.new(newref, formula_with_that_oldname) if formula_with_that_oldname.file? end possible_tap_newname_formulae = [] Tap.each do |tap| - if newref = tap.formula_renames[ref] + if (newref = tap.formula_renames[ref]) possible_tap_newname_formulae << "#{tap.name}/#{newref}" end end diff --git a/Library/Homebrew/livecheck/skip_conditions.rb b/Library/Homebrew/livecheck/skip_conditions.rb index 2fc284f3eb..cf2c7b6a12 100644 --- a/Library/Homebrew/livecheck/skip_conditions.rb +++ b/Library/Homebrew/livecheck/skip_conditions.rb @@ -25,7 +25,7 @@ module Homebrew def formula_or_cask_skip(formula_or_cask, livecheckable, full_name: false, verbose: false) formula = formula_or_cask if formula_or_cask.is_a?(Formula) - if stable_url = formula&.stable&.url + if (stable_url = formula&.stable&.url) stable_is_gist = stable_url.match?(%r{https?://gist\.github(?:usercontent)?\.com/}i) stable_from_google_code_archive = stable_url.match?( %r{https?://storage\.googleapis\.com/google-code-archive-downloads/}i, diff --git a/Library/Homebrew/livecheck/strategy/sparkle.rb b/Library/Homebrew/livecheck/strategy/sparkle.rb index 97dbbcd2c8..eaa3660637 100644 --- a/Library/Homebrew/livecheck/strategy/sparkle.rb +++ b/Library/Homebrew/livecheck/strategy/sparkle.rb @@ -61,7 +61,7 @@ module Homebrew title = (item > "title").first&.text&.strip - if match = title&.match(/(\d+(?:\.\d+)*)\s*(\([^)]+\))?\Z/) + if (match = title&.match(/(\d+(?:\.\d+)*)\s*(\([^)]+\))?\Z/)) short_version ||= match[1] version ||= match[2] end diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb index fcfa56f80f..eefbc464f8 100644 --- a/Library/Homebrew/locale.rb +++ b/Library/Homebrew/locale.rb @@ -29,7 +29,7 @@ class Locale private_constant :LOCALE_REGEX def self.parse(string) - if locale = try_parse(string) + if (locale = try_parse(string)) return locale end @@ -42,12 +42,12 @@ class Locale scanner = StringScanner.new(string) - if language = scanner.scan(LANGUAGE_REGEX) + if (language = scanner.scan(LANGUAGE_REGEX)) sep = scanner.scan(/-/) return if (sep && scanner.eos?) || (sep.nil? && !scanner.eos?) end - if region = scanner.scan(REGION_REGEX) + if (region = scanner.scan(REGION_REGEX)) sep = scanner.scan(/-/) return if (sep && scanner.eos?) || (sep.nil? && !scanner.eos?) end diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 67bff176ad..53d7742ede 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -138,7 +138,7 @@ class Migrator @new_cellar = HOMEBREW_CELLAR/formula.name @new_cellar_existed = @new_cellar.exist? - if @old_linked_keg = linked_old_linked_keg + if (@old_linked_keg = linked_old_linked_keg) @old_linked_keg_record = old_linked_keg.linked_keg_record if old_linked_keg.linked? @old_opt_record = old_linked_keg.opt_record if old_linked_keg.optlinked? @new_linked_keg_record = HOMEBREW_CELLAR/"#{newname}/#{File.basename(old_linked_keg)}" @@ -165,7 +165,7 @@ class Migrator new_tap = if old_tap old_tap_user, = old_tap.user - if migrate_tap = old_tap.tap_migrations[formula.oldname] + if (migrate_tap = old_tap.tap_migrations[formula.oldname]) new_tap_user, new_tap_repo = migrate_tap.split("/") "#{new_tap_user}/#{new_tap_repo}" end diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb index cb242aa0c7..01cae78d8e 100644 --- a/Library/Homebrew/patch.rb +++ b/Library/Homebrew/patch.rb @@ -84,7 +84,7 @@ class DATAPatch < EmbeddedPatch line = f.gets break if line.nil? || line =~ /^__END__$/ end - while line = f.gets + while (line = f.gets) data << line end end diff --git a/Library/Homebrew/requirements/x11_requirement.rb b/Library/Homebrew/requirements/x11_requirement.rb index f33946f3ec..64c1057650 100644 --- a/Library/Homebrew/requirements/x11_requirement.rb +++ b/Library/Homebrew/requirements/x11_requirement.rb @@ -31,12 +31,12 @@ class X11Requirement < Requirement end satisfy build_env: false do - if which_xorg = which("Xorg") + if (which_xorg = which("Xorg")) version = Utils.popen_read(which_xorg, "-version", err: :out)[/X Server (\d+\.\d+\.\d+)/, 1] next true if $CHILD_STATUS.success? && version && Version.new(version) >= min_version end - if which_xdpyinfo = which("xdpyinfo") + if (which_xdpyinfo = which("xdpyinfo")) version = Utils.popen_read(which_xdpyinfo, "-version")[/^xdpyinfo (\d+\.\d+\.\d+)/, 1] next true if $CHILD_STATUS.success? && version && Version.new(version) >= min_xdpyinfo_version end diff --git a/Library/Homebrew/resource_auditor.rb b/Library/Homebrew/resource_auditor.rb index 187d1a2065..87fc4d2688 100644 --- a/Library/Homebrew/resource_auditor.rb +++ b/Library/Homebrew/resource_auditor.rb @@ -105,7 +105,7 @@ module Homebrew # pull request. next if url.match?(%r{^https://dl.bintray.com/homebrew/mirror/}) - if http_content_problem = curl_check_http_content(url, specs: specs) + if (http_content_problem = curl_check_http_content(url, specs: specs)) problem http_content_problem end elsif strategy <= GitDownloadStrategy diff --git a/Library/Homebrew/rubocops/class.rb b/Library/Homebrew/rubocops/class.rb index 5e1fa9ddf7..bea3bc055f 100644 --- a/Library/Homebrew/rubocops/class.rb +++ b/Library/Homebrew/rubocops/class.rb @@ -47,7 +47,7 @@ module RuboCop test_calls(test) do |node, params| p1, p2 = params - if match = string_content(p1).match(%r{(/usr/local/(s?bin))}) + if (match = string_content(p1).match(%r{(/usr/local/(s?bin))})) offending_node(p1) problem "use \#{#{match[2]}} instead of #{match[1]} in #{node}" do |corrector| corrector.replace(p1.source_range, p1.source.sub(match[1], "\#{#{match[2]}}")) diff --git a/Library/Homebrew/rubocops/extend/formula.rb b/Library/Homebrew/rubocops/extend/formula.rb index bc52687969..9fa05c03cb 100644 --- a/Library/Homebrew/rubocops/extend/formula.rb +++ b/Library/Homebrew/rubocops/extend/formula.rb @@ -155,7 +155,7 @@ module RuboCop # Returns the formula tap. def formula_tap - return unless match_obj = @file_path.match(%r{/(homebrew-\w+)/}) + return unless (match_obj = @file_path.match(%r{/(homebrew-\w+)/})) match_obj[1] end diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index fba426055f..867bd74eee 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -162,7 +162,7 @@ module RuboCop find_instance_method_call(body_node, :build, :without?) do |method| arg = parameters(method).first - next unless match = regex_match_group(arg, /^-?-?without-(.*)/) + next unless (match = regex_match_group(arg, /^-?-?without-(.*)/)) problem "Don't duplicate 'without': " \ "Use `build.without? \"#{match[1]}\"` to check for \"--without-#{match[1]}\"" @@ -170,7 +170,7 @@ module RuboCop find_instance_method_call(body_node, :build, :with?) do |method| arg = parameters(method).first - next unless match = regex_match_group(arg, /^-?-?with-(.*)/) + next unless (match = regex_match_group(arg, /^-?-?with-(.*)/)) problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{match[1]}\"" end @@ -258,7 +258,7 @@ module RuboCop popen_commands.each do |command| find_instance_method_call(body_node, "Utils", command) do |method| - next unless match = regex_match_group(parameters(method).first, /^([^"' ]+)=([^"' ]+)(?: (.*))?$/) + next unless (match = regex_match_group(parameters(method).first, /^([^"' ]+)=([^"' ]+)(?: (.*))?$/)) good_args = "Utils.#{command}({ \"#{match[1]}\" => \"#{match[2]}\" }, \"#{match[3]}\")" @@ -329,7 +329,7 @@ module RuboCop find_strings(body_node).each do |str| content = string_content(str) - next unless match = content.match(/^python(@)?(\d\.\d+)$/) + next unless (match = content.match(/^python(@)?(\d\.\d+)$/)) next if python_version == match[2] fix = if match[1] @@ -385,7 +385,7 @@ module RuboCop end find_instance_method_call(body_node, :man, :+) do |method| - next unless match = regex_match_group(parameters(method).first, /^man[1-8]$/) + next unless (match = regex_match_group(parameters(method).first, /^man[1-8]$/)) problem "\"#{method.source}\" should be \"#{match[0]}\"" end @@ -393,37 +393,37 @@ module RuboCop # Avoid hard-coding compilers find_every_method_call_by_name(body_node, :system).each do |method| param = parameters(method).first - if match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|llvm-gcc|clang)(\s|$)}) + if (match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|llvm-gcc|clang)(\s|$)})) problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\"" - elsif match = regex_match_group(param, %r{^(/usr/bin/)?((g|llvm-g|clang)\+\+)(\s|$)}) + elsif (match = regex_match_group(param, %r{^(/usr/bin/)?((g|llvm-g|clang)\+\+)(\s|$)})) problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\"" end end find_instance_method_call(body_node, "ENV", :[]=) do |method| param = parameters(method)[1] - if match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|llvm-gcc|clang)(\s|$)}) + if (match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|llvm-gcc|clang)(\s|$)})) problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\"" - elsif match = regex_match_group(param, %r{^(/usr/bin/)?((g|llvm-g|clang)\+\+)(\s|$)}) + elsif (match = regex_match_group(param, %r{^(/usr/bin/)?((g|llvm-g|clang)\+\+)(\s|$)})) problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\"" end end # Prefer formula path shortcuts in strings formula_path_strings(body_node, :share) do |p| - next unless match = regex_match_group(p, %r{^(/(man))/?}) + next unless (match = regex_match_group(p, %r{^(/(man))/?})) problem "\"\#{share}#{match[1]}\" should be \"\#{#{match[2]}}\"" end formula_path_strings(body_node, :prefix) do |p| - if match = regex_match_group(p, %r{^(/share/(info|man))$}) + if (match = regex_match_group(p, %r{^(/share/(info|man))$})) problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\"" end - if match = regex_match_group(p, %r{^((/share/man/)(man[1-8]))}) + if (match = regex_match_group(p, %r{^((/share/man/)(man[1-8]))})) problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\"" end - if match = regex_match_group(p, %r{^(/(bin|include|libexec|lib|sbin|share|Frameworks))}i) + if (match = regex_match_group(p, %r{^(/(bin|include|libexec|lib|sbin|share|Frameworks))}i)) problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2].downcase}}\"" end end @@ -431,13 +431,13 @@ module RuboCop find_every_method_call_by_name(body_node, :depends_on).each do |method| key, value = destructure_hash(parameters(method).first) next if key.nil? || value.nil? - next unless match = regex_match_group(value, /^(lua|perl|python|ruby)(\d*)/) + next unless (match = regex_match_group(value, /^(lua|perl|python|ruby)(\d*)/)) problem "#{match[1]} modules should be vendored rather than use deprecated `#{method.source}`" end find_every_method_call_by_name(body_node, :system).each do |method| - next unless match = regex_match_group(parameters(method).first, /^(env|export)(\s+)?/) + next unless (match = regex_match_group(parameters(method).first, /^(env|export)(\s+)?/)) problem "Use ENV instead of invoking '#{match[1]}' to modify the environment" end @@ -449,7 +449,7 @@ module RuboCop option_child_nodes.each do |option| find_strings(option).each do |dependency| - next unless match = regex_match_group(dependency, /(with(out)?-\w+|c\+\+11)/) + next unless (match = regex_match_group(dependency, /(with(out)?-\w+|c\+\+11)/)) problem "Dependency #{string_content(dep)} should not use option #{match[0]}" end @@ -551,7 +551,7 @@ module RuboCop path = parameters(method).first next unless path.str_type? - next unless match = regex_match_group(path, /^[^*{},]+$/) + next unless (match = regex_match_group(path, /^[^*{},]+$/)) problem "Dir([\"#{string_content(path)}\"]) is unnecessary; just use \"#{match[0]}\"" end @@ -563,7 +563,7 @@ module RuboCop ) find_every_method_call_by_name(body_node, :system).each do |method| param = parameters(method).first - next unless match = regex_match_group(param, fileutils_methods) + next unless (match = regex_match_group(param, fileutils_methods)) problem "Use the `#{match}` Ruby method instead of `#{method.source}`" end @@ -663,7 +663,7 @@ module RuboCop # Only separate when no shell metacharacters are present next if shell_metacharacters.any? { |meta| string_content(parameters(method).first).include?(meta) } - next unless match = regex_match_group(parameters(method).first, shell_cmd_with_spaces_regex) + next unless (match = regex_match_group(parameters(method).first, shell_cmd_with_spaces_regex)) good_args = match[0].gsub(" ", "\", \"") offending_node(parameters(method).first) @@ -679,7 +679,7 @@ module RuboCop # Only separate when no shell metacharacters are present next if shell_metacharacters.any? { |meta| string_content(parameters(method)[index]).include?(meta) } - next unless match = regex_match_group(parameters(method)[index], shell_cmd_with_spaces_regex) + next unless (match = regex_match_group(parameters(method)[index], shell_cmd_with_spaces_regex)) good_args = match[0].gsub(" ", "\", \"") offending_node(parameters(method)[index]) diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index 5e14114b70..4ca9d5f9f1 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -44,7 +44,7 @@ module RuboCop desc_problem "Description shouldn't have trailing spaces." if regex_match_group(desc, /\s+$/) # Check if "command-line" is spelled incorrectly in the desc. - if match = regex_match_group(desc, /(command ?line)/i) + if (match = regex_match_group(desc, /(command ?line)/i)) c = match.to_s[0] desc_problem "Description should use \"#{c}ommand-line\" instead of \"#{match}\"." end diff --git a/Library/Homebrew/rubocops/text.rb b/Library/Homebrew/rubocops/text.rb index 82df0a41ab..b61f25010f 100644 --- a/Library/Homebrew/rubocops/text.rb +++ b/Library/Homebrew/rubocops/text.rb @@ -15,7 +15,7 @@ module RuboCop def audit_formula(node, _class_node, _parent_class_node, body_node) full_source_content = source_buffer(node).source - if match = full_source_content.match(/^require ['"]formula['"]$/) + if (match = full_source_content.match(/^require ['"]formula['"]$/)) range = source_range(source_buffer(node), match.pre_match.count("\n") + 1, 0, match[0].length) add_offense(range, message: "`#{match}` is now unnecessary") do |corrector| corrector.remove(range_with_surrounding_space(range: range)) @@ -95,7 +95,7 @@ module RuboCop end prefix_path(body_node) do |prefix_node, path| - next unless match = path.match(%r{^(bin|include|libexec|lib|sbin|share|Frameworks)(?:/| |$)}) + next unless (match = path.match(%r{^(bin|include|libexec|lib|sbin|share|Frameworks)(?:/| |$)})) offending_node(prefix_node) problem "Use `#{match[1].downcase}` instead of `prefix + \"#{match[1]}\"`" diff --git a/Library/Homebrew/search.rb b/Library/Homebrew/search.rb index fe37e97254..b278bccc60 100644 --- a/Library/Homebrew/search.rb +++ b/Library/Homebrew/search.rb @@ -10,7 +10,7 @@ module Homebrew # @api private module Search def query_regexp(query) - if m = query.match(%r{^/(.*)/$}) + if (m = query.match(%r{^/(.*)/$})) Regexp.new(m[1]) else query diff --git a/Library/Homebrew/uninstall.rb b/Library/Homebrew/uninstall.rb index aa1c5ed302..0e835b2013 100644 --- a/Library/Homebrew/uninstall.rb +++ b/Library/Homebrew/uninstall.rb @@ -108,7 +108,7 @@ module Homebrew end def check_for_dependents(kegs, casks: [], named_args: []) - return false unless result = InstalledDependents.find_some_installed_dependents(kegs, casks: casks) + return false unless (result = InstalledDependents.find_some_installed_dependents(kegs, casks: casks)) if Homebrew::EnvConfig.developer? DeveloperDependentsMessage.new(*result, named_args: named_args).output diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 2c7d7a9fe3..01fee6c88a 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -223,7 +223,7 @@ module Kernel tap_message = T.let(nil, T.nilable(String)) backtrace.each do |line| - next unless match = line.match(HOMEBREW_TAP_PATH_REGEX) + next unless (match = line.match(HOMEBREW_TAP_PATH_REGEX)) tap = Tap.fetch(match[:user], match[:repo]) tap_message = +"\nPlease report this issue to the #{tap} tap (not Homebrew/brew or Homebrew/core)" diff --git a/Library/Homebrew/utils/pypi.rb b/Library/Homebrew/utils/pypi.rb index 7408ac9988..ce3a0a8d16 100644 --- a/Library/Homebrew/utils/pypi.rb +++ b/Library/Homebrew/utils/pypi.rb @@ -42,7 +42,7 @@ module PyPI @name = package_string @name, @version = @name.split("==") if @name.include? "==" - return unless match = @name.match(/^(.*?)\[(.+)\]$/) + return unless (match = @name.match(/^(.*?)\[(.+)\]$/)) @name = match[1] @extras = match[2].split "," diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index ccde6b58c1..97de346cc0 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -115,7 +115,7 @@ class Version sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } def <=>(other) - return unless other = Token.from(other) + return unless (other = Token.from(other)) case other when NullToken @@ -158,7 +158,7 @@ class Version sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } def <=>(other) - return unless other = Token.from(other) + return unless (other = Token.from(other)) case other when StringToken @@ -184,7 +184,7 @@ class Version sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } def <=>(other) - return unless other = Token.from(other) + return unless (other = Token.from(other)) case other when NumericToken @@ -216,7 +216,7 @@ class Version sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } def <=>(other) - return unless other = Token.from(other) + return unless (other = Token.from(other)) case other when AlphaToken @@ -235,7 +235,7 @@ class Version sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } def <=>(other) - return unless other = Token.from(other) + return unless (other = Token.from(other)) case other when BetaToken @@ -256,7 +256,7 @@ class Version sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } def <=>(other) - return unless other = Token.from(other) + return unless (other = Token.from(other)) case other when PreToken @@ -277,7 +277,7 @@ class Version sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } def <=>(other) - return unless other = Token.from(other) + return unless (other = Token.from(other)) case other when RCToken @@ -298,7 +298,7 @@ class Version sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } def <=>(other) - return unless other = Token.from(other) + return unless (other = Token.from(other)) case other when PatchToken @@ -317,7 +317,7 @@ class Version sig { override.params(other: T.untyped).returns(T.nilable(Integer)) } def <=>(other) - return unless other = Token.from(other) + return unless (other = Token.from(other)) case other when PostToken