diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index d741c7e09c29e46260010db6e36a408007ec4be0..0c51ee15673b78efa9450e1ab39c357fa4316573 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -212,6 +212,10 @@ Style/GuardClause: Style/HashSyntax: EnforcedStyle: ruby19 +# so many of these in formulae and can't be autocorrected +Style/StringConcatenation: + Enabled: false + # ruby style guide favorite Style/StringLiterals: EnforcedStyle: double_quotes diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index 1259bdd8bca8d511c3b830f584e52f40bab0c8d7..6799841ae13197e5c19ab140779892f57e49584d 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -63,7 +63,7 @@ Metrics/ModuleLength: Max: 600 Metrics/PerceivedComplexity: Enabled: true - Max: 80 + Max: 90 # we won't change backward compatible predicate names Naming/PredicateName: @@ -139,3 +139,7 @@ Style/FrozenStringLiteralComment: # so many of these in formulae but none in here Style/GuardClause: Enabled: true + +# so many of these in formulae but none in here +Style/StringConcatenation: + Enabled: true diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index bdda5b6e77d47883428ba35f3c3039230bc9d39b..93301a09588f9d76af611fd55086949d19ccbfcc 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -98,11 +98,11 @@ module Cask @caskroom_path ||= Caskroom.path.join(token) end - def outdated?(greedy = false) - !outdated_versions(greedy).empty? + def outdated?(greedy: false) + !outdated_versions(greedy: greedy).empty? end - def outdated_versions(greedy = false) + def outdated_versions(greedy: false) # special case: tap version is not available return [] if version.nil? @@ -125,7 +125,7 @@ module Cask def outdated_info(greedy, verbose, json) return token if !verbose && !json - installed_versions = outdated_versions(greedy).join(", ") + installed_versions = outdated_versions(greedy: greedy).join(", ") if json { diff --git a/Library/Homebrew/cask/cask_loader.rb b/Library/Homebrew/cask/cask_loader.rb index 147bfefa530b6f931a0ef75bfe1f3e37dea510bf..3ffd79761b451552e65222e6eb7cab8d26e626f2 100644 --- a/Library/Homebrew/cask/cask_loader.rb +++ b/Library/Homebrew/cask/cask_loader.rb @@ -44,7 +44,7 @@ module Cask attr_reader :token, :path - def initialize(path) + def initialize(path) # rubocop:disable Lint/MissingSuper path = Pathname(path).expand_path @token = path.basename(".rb").to_s @@ -79,7 +79,7 @@ module Cask class FromURILoader < FromPathLoader def self.can_load?(ref) uri_regex = ::URI::DEFAULT_PARSER.make_regexp - return false unless ref.to_s.match?(Regexp.new('\A' + uri_regex.source + '\Z', uri_regex.options)) + return false unless ref.to_s.match?(Regexp.new("\\A#{uri_regex.source}\\Z", uri_regex.options)) uri = URI(ref) return false unless uri diff --git a/Library/Homebrew/cask/cmd.rb b/Library/Homebrew/cask/cmd.rb index 9de9fd7c9f9e5b85aa18fef706b0a66d3fdc6724..674f4f452edf362ccb7bf13b1d4dd30a0baa6830 100644 --- a/Library/Homebrew/cask/cmd.rb +++ b/Library/Homebrew/cask/cmd.rb @@ -58,20 +58,22 @@ module Cask }.freeze def self.description - max_command_len = Cmd.commands.map(&:length).max + max_command_length = Cmd.commands.map(&:length).max - <<~EOS + + command_lines = Cmd.command_classes + .select(&:visible?) + .map do |klass| + " - #{"`#{klass.command_name}`".ljust(max_command_length + 2)} #{klass.short_description}\n" + end + + <<~EOS Homebrew Cask provides a friendly CLI workflow for the administration of macOS applications distributed as binaries. Commands: + #{command_lines.join} + + See also: `man brew` EOS - Cmd.command_classes - .select(&:visible?) - .map do |klass| - " - #{"`#{klass.command_name}`".ljust(max_command_len + 2)} #{klass.short_description}\n" - end - .join + - "\nSee also: `man brew`" end def self.parser(&block) diff --git a/Library/Homebrew/cask/cmd/doctor.rb b/Library/Homebrew/cask/cmd/doctor.rb index c283724a733736edc183f34b699571e57ebac2b3..9feb0e111937b7b337f66cf83c078a05289573da 100644 --- a/Library/Homebrew/cask/cmd/doctor.rb +++ b/Library/Homebrew/cask/cmd/doctor.rb @@ -17,7 +17,7 @@ module Cask def run success = true - checks = Homebrew::Diagnostic::Checks.new true + checks = Homebrew::Diagnostic::Checks.new(verbose: true) checks.cask_checks.each do |check| out = checks.send(check) diff --git a/Library/Homebrew/cask/cmd/info.rb b/Library/Homebrew/cask/cmd/info.rb index 11efcf29761d5c40122e50cb67b30266cdfc8e15..bcb56348cb31ca26150b4a9303d0401c03872573 100644 --- a/Library/Homebrew/cask/cmd/info.rb +++ b/Library/Homebrew/cask/cmd/info.rb @@ -34,16 +34,16 @@ module Cask end def self.get_info(cask) - output = title_info(cask) + "\n" - output << Formatter.url(cask.homepage) + "\n" if cask.homepage + output = +"#{title_info(cask)}\n" + output << "#{Formatter.url(cask.homepage)}\n" if cask.homepage output << installation_info(cask) repo = repo_info(cask) - output << repo + "\n" if repo + output << "#{repo}\n" if repo output << name_info(cask) output << desc_info(cask) language = language_info(cask) output << language if language - output << artifact_info(cask) + "\n" + output << "#{artifact_info(cask)}\n" caveats = Installer.caveats(cask) output << caveats if caveats output diff --git a/Library/Homebrew/cask/cmd/outdated.rb b/Library/Homebrew/cask/cmd/outdated.rb index 33d989d84f9a73cf49f419305fb9a472f9e39a31..43675d5a101144797cbcc0bcca314b89dedb5788 100644 --- a/Library/Homebrew/cask/cmd/outdated.rb +++ b/Library/Homebrew/cask/cmd/outdated.rb @@ -19,7 +19,7 @@ module Cask def run outdated_casks = casks(alternative: -> { Caskroom.casks }).select do |cask| odebug "Checking update info of Cask #{cask}" - cask.outdated?(args.greedy?) + cask.outdated?(greedy: args.greedy?) end verbose = ($stdout.tty? || args.verbose?) && !args.quiet? diff --git a/Library/Homebrew/cask/cmd/upgrade.rb b/Library/Homebrew/cask/cmd/upgrade.rb index 92dafc317e5384f8b440c67295cf002973669db8..6edf182451a3383874000986e8a83826fe2f8f53 100644 --- a/Library/Homebrew/cask/cmd/upgrade.rb +++ b/Library/Homebrew/cask/cmd/upgrade.rb @@ -54,13 +54,13 @@ module Cask outdated_casks = if casks.empty? Caskroom.casks.select do |cask| - cask.outdated?(greedy) + cask.outdated?(greedy: greedy) end else casks.select do |cask| raise CaskNotInstalledError, cask unless cask.installed? || force - cask.outdated?(true) + cask.outdated?(greedy: true) end end diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index b1d5085e759abb3ffb18c25cceb7268cbc89b70d..4f69c2c5e0afaa7a970b5503647ea011fd9b26a2 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -292,7 +292,7 @@ module Cask end def respond_to_missing?(*) - true + super || true end def appdir diff --git a/Library/Homebrew/cask/dsl/base.rb b/Library/Homebrew/cask/dsl/base.rb index ac3c79c05049a1bab1ae53ecfcabea3d3d30aa3d..46325646a8112122a4cd0c9fa91f38854a02f69e 100644 --- a/Library/Homebrew/cask/dsl/base.rb +++ b/Library/Homebrew/cask/dsl/base.rb @@ -30,7 +30,7 @@ module Cask end def respond_to_missing?(*) - true + super || true end end end diff --git a/Library/Homebrew/cask/exceptions.rb b/Library/Homebrew/cask/exceptions.rb index b36df6a97ceb5dd35bf2a58328ed37f1c6606aca..48ba8cd6fc69b937c219571281ab905763d6bf5e 100644 --- a/Library/Homebrew/cask/exceptions.rb +++ b/Library/Homebrew/cask/exceptions.rb @@ -5,6 +5,8 @@ module Cask class MultipleCaskErrors < CaskError def initialize(errors) + super + @errors = errors end @@ -20,6 +22,8 @@ module Cask attr_reader :token, :reason def initialize(token, reason = nil) + super() + @token = token @reason = reason.to_s end @@ -168,6 +172,8 @@ module Cask attr_reader :path, :reason def initialize(path, reason) + super + @path = path @reason = reason end diff --git a/Library/Homebrew/cask/utils.rb b/Library/Homebrew/cask/utils.rb index a071c9c69374d9efb5f2a2f217a946f5ef37bee3..d13983e3bf21b4664d1646269a9859d16d962c54 100644 --- a/Library/Homebrew/cask/utils.rb +++ b/Library/Homebrew/cask/utils.rb @@ -85,7 +85,7 @@ module Cask poo << "during #{section}" if section poo << "on Cask #{token}." - opoo(poo.join(" ") + "\n" + error_message_with_suggestions) + opoo("#{poo.join(" ")}\n#{error_message_with_suggestions}") end end end diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 1b05d33ca9fd1020b14568036fd5e9985e6713de..1b4e96d5e6ed4a7863e68a46340d2a38a455c062 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -17,7 +17,7 @@ class Caveats build = f.build f.build = Tab.for_formula(f) s = f.caveats.to_s - caveats << s.chomp + "\n" unless s.empty? + caveats << "#{s.chomp}\n" unless s.empty? ensure f.build = build end diff --git a/Library/Homebrew/cleaner.rb b/Library/Homebrew/cleaner.rb index 651662a7c9027183e9326190259205fe54618e6e..d35ef9b7d11fdcdf3c37fa1a3c64c1843058dfba 100644 --- a/Library/Homebrew/cleaner.rb +++ b/Library/Homebrew/cleaner.rb @@ -28,7 +28,7 @@ class Cleaner [@f.bin, @f.sbin, @f.lib].each { |d| clean_dir(d) if d.exist? } # Get rid of any info 'dir' files, so they don't conflict at the link stage - info_dir_file = @f.info + "dir" + info_dir_file = @f.info/"dir" observe_file_removal info_dir_file if info_dir_file.file? && !@f.skip_clean?(info_dir_file) prune diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 97f08c0251e8521d0c26590eb6db7dc4ebdcf1ce..5a03ec590c722c8dcaf7ace0dd548feebc3d557f 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -48,7 +48,7 @@ module Homebrew mtime < days.days.ago && ctime < days.days.ago end - def stale?(scrub = false) + def stale?(scrub: false) return false unless resolved_path.file? if dirname.basename.to_s == "Cask" @@ -308,7 +308,7 @@ module Homebrew next end - next cleanup_path(path) { path.unlink } if path.stale?(scrub?) + next cleanup_path(path) { path.unlink } if path.stale?(scrub: scrub?) end cleanup_unreferenced_downloads diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index 84c621fd8be9563c0d274be578425fdcc5f1f37a..855f50a07b14fc8b61105cfe83b64183685d18e4 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -142,9 +142,9 @@ module Homebrew if @table[switch] == true || @table[flag] == true @cli_args << option elsif @table[flag].instance_of? String - @cli_args << option + "=" + @table[flag] + @cli_args << "#{option}=#{@table[flag]}" elsif @table[flag].instance_of? Array - @cli_args << option + "=" + @table[flag].join(",") + @cli_args << "#{option}=#{@table[flag].join(",")}" end end @cli_args.freeze diff --git a/Library/Homebrew/cli/named_args.rb b/Library/Homebrew/cli/named_args.rb index 67aa1271ad168d43a9ebdcf0d768678865f9af10..414595b2d68a8699ca1ddb1d4b95e1e301c007a1 100644 --- a/Library/Homebrew/cli/named_args.rb +++ b/Library/Homebrew/cli/named_args.rb @@ -11,7 +11,7 @@ module Homebrew @force_bottle = force_bottle @flags = flags - __setobj__(@args) + super(@args) end def to_formulae diff --git a/Library/Homebrew/cmd/deps.rb b/Library/Homebrew/cmd/deps.rb index 425e536e2cd74ad165b3b4cbbed1c75f2b7f3a09..34463eb14aca44deb6ba622d14e5f182c702b5ca 100644 --- a/Library/Homebrew/cmd/deps.rb +++ b/Library/Homebrew/cmd/deps.rb @@ -83,26 +83,26 @@ module Homebrew raise FormulaUnspecifiedError end - puts_deps_tree dependents, recursive, args: args + puts_deps_tree dependents, recursive: recursive, args: args return elsif args.all? - puts_deps sorted_dependents(Formula.to_a + Cask::Cask.to_a), recursive, args: args + puts_deps sorted_dependents(Formula.to_a + Cask::Cask.to_a), recursive: recursive, args: args return elsif !args.no_named? && args.for_each? - puts_deps sorted_dependents(args.formulae_and_casks), recursive, args: args + puts_deps sorted_dependents(args.formulae_and_casks), recursive: recursive, args: args return end if args.no_named? raise FormulaUnspecifiedError unless args.installed? - puts_deps sorted_dependents(Formula.installed + Cask::Caskroom.casks), recursive, args: args + puts_deps sorted_dependents(Formula.installed + Cask::Caskroom.casks), recursive: recursive, args: args return end dependents = dependents(args.formulae_and_casks) - all_deps = deps_for_dependents(dependents, recursive, args: args, &(args.union? ? :| : :&)) + all_deps = deps_for_dependents(dependents, recursive: recursive, args: args, &(args.union? ? :| : :&)) condense_requirements(all_deps, args: args) all_deps.map! { |d| dep_display_name(d, args: args) } all_deps.uniq! @@ -144,7 +144,7 @@ module Homebrew str end - def deps_for_dependent(d, recursive = false, args:) + def deps_for_dependent(d, recursive: false, args:) includes, ignores = args_includes_ignores(args) deps = d.runtime_dependencies if @use_runtime_dependencies @@ -160,13 +160,13 @@ module Homebrew deps + reqs.to_a end - def deps_for_dependents(dependents, recursive = false, args:, &block) - dependents.map { |d| deps_for_dependent(d, recursive, args: args) }.reduce(&block) + def deps_for_dependents(dependents, recursive: false, args:, &block) + dependents.map { |d| deps_for_dependent(d, recursive: recursive, args: args) }.reduce(&block) end - def puts_deps(dependents, recursive = false, args:) + def puts_deps(dependents, recursive: false, args:) dependents.each do |dependent| - deps = deps_for_dependent(dependent, recursive, args: args) + deps = deps_for_dependent(dependent, recursive: recursive, args: args) condense_requirements(deps, args: args) deps.sort_by!(&:name) deps.map! { |d| dep_display_name(d, args: args) } @@ -174,7 +174,7 @@ module Homebrew end end - def puts_deps_tree(dependents, recursive = false, args:) + def puts_deps_tree(dependents, recursive: false, args:) dependents.each do |d| puts d.full_name @dep_stack = [] diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index 24da404e6c55111ec21803502bd3e84b460c6177..43eb385c2cf410bd7fd0fd32bd532e8a3e05e01a 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -31,7 +31,7 @@ module Homebrew inject_dump_stats!(Diagnostic::Checks, /^check_*/) if args.audit_debug? - checks = Diagnostic::Checks.new args.verbose? + checks = Diagnostic::Checks.new(verbose: args.verbose?) if args.list_checks? puts checks.all.sort diff --git a/Library/Homebrew/commands.rb b/Library/Homebrew/commands.rb index d68feffe5b7eb439eeb7aa4297ea8c4bd165ff85..fe279bb7778aa62465d645971333044cda12baf2 100644 --- a/Library/Homebrew/commands.rb +++ b/Library/Homebrew/commands.rb @@ -179,7 +179,7 @@ module Commands cmds = internal_commands + internal_developer_commands + internal_commands_aliases file = HOMEBREW_REPOSITORY/"completions/internal_commands_list.txt" - file.atomic_write(cmds.sort.join("\n") + "\n") + file.atomic_write("#{cmds.sort.join("\n")}\n") end def rebuild_commands_completion_list @@ -187,6 +187,6 @@ module Commands HOMEBREW_CACHE.mkpath file = HOMEBREW_CACHE/"all_commands_list.txt" - file.atomic_write(commands(aliases: true).sort.join("\n") + "\n") + file.atomic_write("#{commands(aliases: true).sort.join("\n")}\n") end end diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 461649cc10317ed8c8b6f434505efa2425f05e35..ea1188d085e7d921e9c9573f14928e03b2d0f9f8 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -544,7 +544,7 @@ module Homebrew )\n+ # multiple empty lines )+ /mx - string = s.sub!(pattern, '\0' + output + "\n") + string = s.sub!(pattern, "\\0#{output}\n") odie "Bottle block addition failed!" unless string end end diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 5cdd52714ac3b748b490c461da03eabd5cce756f..7ecb4f75f222c49562a468aafba923dbf6e70324 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -378,7 +378,8 @@ module Homebrew EOS user_message = args.message if user_message - pr_message += "\n" + <<~EOS + pr_message += <<~EOS + --- #{user_message} diff --git a/Library/Homebrew/dev-cmd/bump-revision.rb b/Library/Homebrew/dev-cmd/bump-revision.rb index 094f362cb0e9447c20e1c4190021a2a66ccd9c65..da835ad67e24bdeddb0dcbfaea0e4c4cacce2c77 100644 --- a/Library/Homebrew/dev-cmd/bump-revision.rb +++ b/Library/Homebrew/dev-cmd/bump-revision.rb @@ -65,7 +65,7 @@ module Homebrew revision: "#{formula_spec.specs[:revision]}" EOS end - replacement = old + " revision 1\n" + replacement = "#{old} revision 1\n" else old = "revision #{current_revision}" diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index d35a42641a9ee36bc68e762a257f9a1959b89fff..5dcf691418bb0497d5bcb7183175f2ee1695fecc 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -205,7 +205,7 @@ module Homebrew def initialize(url, args, description = nil) @base_url = url # GitHub provides commits/pull-requests raw patches using this URL. - @patch_url = url + ".patch" + @patch_url = "#{url}.patch" @patchpath = HOMEBREW_CACHE + File.basename(patch_url) @description = description @args = args diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index e8309f30d115e7353284d0a2073db3f0430d9b5f..89778e869ab9e47c97be047f435e936089814229 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -30,7 +30,7 @@ module Homebrew # Diagnostic checks. class Checks - def initialize(verbose = true) + def initialize(verbose: true) @verbose = verbose end diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 8b70ec1b450f1ef1dcf5767dc3f1a6cc29a587b0..0c8de9b494dfb4c83292badf817b9aa0574c527f 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -345,7 +345,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy return @resolved_info_cache[url] if @resolved_info_cache.include?(url) if (domain = Homebrew::EnvConfig.artifact_domain) - url = url.sub(%r{^((ht|f)tps?://)?}, domain.chomp("/") + "/") + url = url.sub(%r{^((ht|f)tps?://)?}, "#{domain.chomp("/")}/") end out, _, status= curl_output("--location", "--silent", "--head", "--request", "GET", url.to_s) @@ -503,7 +503,7 @@ end # This strategy extracts local binary packages. class LocalBottleDownloadStrategy < AbstractFileDownloadStrategy - def initialize(path) + def initialize(path) # rubocop:disable Lint/MissingSuper @cached_location = path end end @@ -552,7 +552,7 @@ class SubversionDownloadStrategy < VCSDownloadStrategy end end - def fetch_repo(target, url, revision = nil, ignore_externals = false) + def fetch_repo(target, url, revision = nil, ignore_externals: false) # Use "svn update" when the repository already exists locally. # This saves on bandwidth and will have a similar effect to verifying the # cache as it will make any changes to get the right revision. @@ -593,10 +593,10 @@ class SubversionDownloadStrategy < VCSDownloadStrategy when :revisions # nil is OK for main_revision, as fetch_repo will then get latest main_revision = @ref[:trunk] - fetch_repo cached_location, @url, main_revision, true + fetch_repo cached_location, @url, main_revision, ignore_externals: true externals do |external_name, external_url| - fetch_repo cached_location/external_name, external_url, @ref[external_name], true + fetch_repo cached_location/external_name, external_url, @ref[external_name], ignore_externals: true end else fetch_repo cached_location, @url diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 7c6c862ad8573bf4e45e918b68942a7ee6f5276e..d0016cb1e27826b0c9f4e224b43d7dad449c8216 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -7,6 +7,8 @@ class UsageError < RuntimeError attr_reader :reason def initialize(reason = nil) + super + @reason = reason end @@ -63,6 +65,8 @@ class FormulaUnavailableError < RuntimeError attr_accessor :dependent def initialize(name) + super + @name = name end diff --git a/Library/Homebrew/extend/os/linux/hardware/cpu.rb b/Library/Homebrew/extend/os/linux/hardware/cpu.rb index b1fb08e2d224930b1df1fc2db84a43f2ffb85f98..e34507b55ebefc82b3b16ac142bb46d0539db14e 100644 --- a/Library/Homebrew/extend/os/linux/hardware/cpu.rb +++ b/Library/Homebrew/extend/os/linux/hardware/cpu.rb @@ -84,7 +84,7 @@ module Hardware end %w[aes altivec avx avx2 lm ssse3 sse4_2].each do |flag| - define_method(flag + "?") { flags.include? flag } + define_method("#{flag}?") { flags.include? flag } end def sse3? diff --git a/Library/Homebrew/extend/os/linux/requirements/osxfuse_requirement.rb b/Library/Homebrew/extend/os/linux/requirements/osxfuse_requirement.rb index ab94db30ddf3132cdea1921f9ed0f46a30fa863a..518a7ce645ee4118bed2631b296b23493b9cb2ad 100644 --- a/Library/Homebrew/extend/os/linux/requirements/osxfuse_requirement.rb +++ b/Library/Homebrew/extend/os/linux/requirements/osxfuse_requirement.rb @@ -22,8 +22,8 @@ class OsxfuseRequirement < Requirement def message msg = "libfuse is required to install this formula.\n" if libfuse_formula_exists? - msg + <<~EOS - Run `brew install libfuse` to install it. + <<~EOS + #{msg}Run `brew install libfuse` to install it. EOS else msg + super diff --git a/Library/Homebrew/extend/os/mac/caveats.rb b/Library/Homebrew/extend/os/mac/caveats.rb index da0b32b627930ffacc3b7ccbd6cefb1fee8a90a8..dae8d90b07c9e89058f6b81b16ba8fee3df8c9b0 100644 --- a/Library/Homebrew/extend/os/mac/caveats.rb +++ b/Library/Homebrew/extend/os/mac/caveats.rb @@ -44,6 +44,6 @@ class Caveats s << "" << "WARNING: brew services will fail when run under tmux." end end - s.join("\n") + "\n" unless s.empty? + "#{s.join("\n")}\n" unless s.empty? end end diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index 90f3134f9d41e158a95682b4ebcd818d1314aad6..32d403e21d8f19aa4a7c566c103b5c3c7c00def7 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -22,7 +22,7 @@ class StringInreplaceExtension end # Warn if nothing was replaced - def gsub!(before, after, audit_result = true) + def gsub!(before, after, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter result = inreplace_string.gsub!(before, after) errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil? result diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index ddc6ec671ad2eafeb26f1cab0bbf77169c981c59..9cdf6324b1276c48ff366fcbdd996edab9cf24a3 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -944,12 +944,12 @@ class Formula # The generated launchd {.plist} service name. def plist_name - "homebrew.mxcl." + name + "homebrew.mxcl.#{name}" end # The generated launchd {.plist} file path. def plist_path - prefix + (plist_name + ".plist") + prefix/"#{plist_name}.plist" end # @private @@ -1137,7 +1137,7 @@ class Formula to_check = path.relative_path_from(HOMEBREW_PREFIX).to_s self.class.link_overwrite_paths.any? do |p| p == to_check || - to_check.start_with?(p.chomp("/") + "/") || + to_check.start_with?("#{p.chomp("/")}/") || to_check =~ /^#{Regexp.escape(p).gsub('\*', ".*?")}$/ end end @@ -2070,21 +2070,17 @@ class Formula # recursively delete the temporary directory. Passing `opts[:retain]` # or calling `do |staging| ... staging.retain!` in the block will skip # the deletion and retain the temporary directory's contents. - def mktemp(prefix = name, opts = {}) - Mktemp.new(prefix, opts).run do |staging| - yield staging - end + def mktemp(prefix = name, opts = {}, &block) + Mktemp.new(prefix, opts).run(&block) end # A version of `FileUtils.mkdir` that also changes to that folder in # a block. - def mkdir(name) + def mkdir(name, &block) result = FileUtils.mkdir_p(name) return result unless block_given? - FileUtils.chdir name do - yield - end + FileUtils.chdir(name, &block) end # Run `xcodebuild` without Homebrew's compiler environment variables set. @@ -2184,6 +2180,8 @@ class Formula include BuildEnvironment::DSL def method_added(method) + super + case method when :brew raise "You cannot override Formula#brew in class #{name}" diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index fc15f005468dfa9c1ad5fd3ed589dba3515381be..4698dcfa0c52c06bb1e539ca9d20f042636862fd 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -362,10 +362,10 @@ class Keg ObserverPathnameExtension.n end - def lock + def lock(&block) FormulaLock.new(name).with_lock do if oldname_opt_record - FormulaLock.new(oldname_opt_record.basename.to_s).with_lock { yield } + FormulaLock.new(oldname_opt_record.basename.to_s).with_lock(&block) else yield end diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 5a96adccce2e8e3f333f9127b7e73e728f212947..693c749a0d444f28fd1e7462d0ba5d4d499fa9b7 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -126,10 +126,8 @@ class Requirement name end - def mktemp - Mktemp.new(name).run do |staging| - yield staging - end + def mktemp(&block) + Mktemp.new(name).run(&block) end private diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index b76bd703fa137e1efd97a7797367ed754fd91451..e498069eaefe919163d915b22180977ab5d4e442 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -193,10 +193,8 @@ class Resource protected - def mktemp(prefix) - Mktemp.new(prefix).run do |staging| - yield staging - end + def mktemp(prefix, &block) + Mktemp.new(prefix).run(&block) end private diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index 7996601dea88f7e6e145ec238ec794b76800e4ba..66d601e9b0f1c5732c9107e6df70632b4907090b 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -467,7 +467,7 @@ module RuboCop fileutils_methods = Regexp.new( FileUtils.singleton_methods(false) - .map { |m| "(?-mix:^" + Regexp.escape(m) + "$)" } + .map { |m| "(?-mix:^#{Regexp.escape(m)}$)" } .join("|"), ) find_every_method_call_by_name(body_node, :system).each do |method| diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index c0e91059a1e3590534d896c34973c2e48a82e61a..b507ec1434f9d02e2289b55ee9338b1fb841d5d1 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -71,7 +71,9 @@ class SystemCommand @options = options @env = env - @env.keys.grep_v(/^[\w&&\D]\w*$/) do |name| + @env.each_key do |name| + next if /^[\w&&\D]\w*$/.match?(name) + raise ArgumentError, "Invalid variable name: '#{name}'" end end diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index 791c74254c2953900a18f479526e5c6a120a65b2..b0ca9658f543ea1450df3d395ebb9c98b67a8864 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -134,7 +134,7 @@ describe Cask::Cask, :cask do expectations.each do |installed_version, expected_output| context "when versions #{installed_version} are installed and the " \ "tap version is #{tap_version}, #{"not" unless greedy} greedy" do - subject { cask.outdated_versions greedy } + subject { cask.outdated_versions(greedy: greedy) } it { allow(cask).to receive(:versions).and_return(installed_version) diff --git a/Library/Homebrew/test/cask/cmd/outdated_spec.rb b/Library/Homebrew/test/cask/cmd/outdated_spec.rb index 18aa70a01de5012912520af8fdd36adc6ba4e071..2ae1624b35b340fdbc2f97acda38d00b0d21a275 100644 --- a/Library/Homebrew/test/cask/cmd/outdated_spec.rb +++ b/Library/Homebrew/test/cask/cmd/outdated_spec.rb @@ -111,7 +111,7 @@ describe Cask::Cmd::Outdated, :cask do expect { described_class.run("--json") - }.to output(result + "\n").to_stdout + }.to output("#{result}\n").to_stdout end end @@ -132,7 +132,7 @@ describe Cask::Cmd::Outdated, :cask do expect { described_class.run("--json", "--quiet") - }.to output(result + "\n").to_stdout + }.to output("#{result}\n").to_stdout end end @@ -163,7 +163,7 @@ describe Cask::Cmd::Outdated, :cask do expect { described_class.run("--json", "--greedy") - }.to output(result + "\n").to_stdout + }.to output("#{result}\n").to_stdout end it 'does not include the Casks with "auto_updates true" with no version change in JSON format' do @@ -190,7 +190,7 @@ describe Cask::Cmd::Outdated, :cask do expect { described_class.run("--json", "--greedy") - }.to output(result + "\n").to_stdout + }.to output("#{result}\n").to_stdout end end end diff --git a/Library/Homebrew/test/cask/installer_spec.rb b/Library/Homebrew/test/cask/installer_spec.rb index f162fa843ea8c797f3fa74e0f3259ee351d537dd..bb13ec00504ebcea4289ae8eae415f827fc4e5ac 100644 --- a/Library/Homebrew/test/cask/installer_spec.rb +++ b/Library/Homebrew/test/cask/installer_spec.rb @@ -233,7 +233,7 @@ describe Cask::Installer, :cask do it "uninstalls all versions if force is set" do caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) - mutated_version = caffeine.version + ".1" + mutated_version = "#{caffeine.version}.1" described_class.new(caffeine).install diff --git a/Library/Homebrew/test/cli/parser_spec.rb b/Library/Homebrew/test/cli/parser_spec.rb index 97ac930d4daeefa503f06a01e188fe9d6c408b5a..4ab19143bf53c3bbd8a1e209c3208812a1352ac2 100644 --- a/Library/Homebrew/test/cli/parser_spec.rb +++ b/Library/Homebrew/test/cli/parser_spec.rb @@ -287,7 +287,7 @@ describe Homebrew::CLI::Parser do context "kegs" do before do - keg = HOMEBREW_CELLAR + "mxcl/10.0" + keg = HOMEBREW_CELLAR/"mxcl/10.0" keg.mkpath end diff --git a/Library/Homebrew/test/cmd/outdated_spec.rb b/Library/Homebrew/test/cmd/outdated_spec.rb index bb594a1aae1a4ed0ca7677629c9610d6c364659d..61e329981fff71c900c961e9f998156a267d53ac 100644 --- a/Library/Homebrew/test/cmd/outdated_spec.rb +++ b/Library/Homebrew/test/cmd/outdated_spec.rb @@ -22,7 +22,7 @@ describe "brew outdated", :integration_test do ].to_json expect { brew "outdated", "--json=v1" } - .to output(expected_json + "\n").to_stdout + .to output("#{expected_json}\n").to_stdout .and be_a_success end end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 0c4068c89e3c9f1b2a1c7d916f6fe3f26b243e80..3293696c5e9c5eec6d5a81b590802ca18dd1c5c5 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -266,16 +266,12 @@ module Kernel raise $CHILD_STATUS.inspect end - def with_homebrew_path - with_env(PATH: PATH.new(ENV["HOMEBREW_PATH"])) do - yield - end + def with_homebrew_path(&block) + with_env(PATH: PATH.new(ENV["HOMEBREW_PATH"]), &block) end - def with_custom_locale(locale) - with_env(LC_ALL: locale) do - yield - end + def with_custom_locale(locale, &block) + with_env(LC_ALL: locale, &block) end # Kernel.system but with exceptions diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index dcebbde184163aa428e8f7fde52f0c8dde9d073d..61cdc06b87acee03ef2834459e57d7dd0a554ac4 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -47,8 +47,8 @@ module Formatter indent = width - desc s.gsub(/(?<=\S) *\n(?=\S)/, " ") .gsub(/([`>)\]]:) /, "\\1\n ") - .gsub(/^( +-.+ +(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n" + " " * indent) - .gsub(/^( {#{indent}}(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n" + " " * indent) + .gsub(/^( +-.+ +(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n#{" " * indent}") + .gsub(/^( {#{indent}}(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n#{" " * indent}") .gsub(/(.{1,#{width}})( +|$)\n?/, "\\1\n") end diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index fb3f355bf5c56643ce6759c3ad1974d4b42eb80d..3eab88b08e63a1b303d5db531777bd5c3bfdfd19 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -21,7 +21,7 @@ module Utils # # `inreplace` supports regular expressions: # <pre>inreplace "somefile.cfg", /look[for]what?/, "replace by #{bin}/tool"</pre> - def inreplace(paths, before = nil, after = nil, audit_result = true) + def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter errors = {} errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.blank? diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index 32f187afca10376fb75481faa7cf989b3878d817..d8e77a8dd906d63e76bde569ae726d53665ce32d 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -92,7 +92,7 @@ module Utils str = str.dup # anything that isn't a known safe character is padded - str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") + str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") # rubocop:disable Style/StringConcatenation # newlines have to be specially quoted in csh str.gsub!(/\n/, "'\\\n'") str @@ -105,7 +105,7 @@ module Utils str = str.dup # anything that isn't a known safe character is padded - str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") + str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") # rubocop:disable Style/StringConcatenation str.gsub!(/\n/, "'\n'") str end diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index 589bb7a30468924c74a44ce8567e5b18a71c893f..ae2aec8bb1bc61cf33436a2de4654cafeb537611 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -102,6 +102,8 @@ class Version PATTERN = /[a-z]+/i.freeze def initialize(value) + super + @value = value.to_s end @@ -121,6 +123,8 @@ class Version PATTERN = /[0-9]+/i.freeze def initialize(value) + super + @value = value.to_i end