diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index 3c6e03b77a..a35001a936 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -70,6 +70,11 @@ Style/Documentation: - version.rb - tap.rb +Homebrew/NegateInclude: + Exclude: + # YARD runs stand-alone. + - yard/docstring_parser.rb + Style/DocumentationMethod: Include: - "formula.rb" diff --git a/Library/Homebrew/Gemfile b/Library/Homebrew/Gemfile index d8c898284f..a01e6a7da9 100644 --- a/Library/Homebrew/Gemfile +++ b/Library/Homebrew/Gemfile @@ -18,6 +18,7 @@ end group :doc, optional: true do gem "yard", require: false gem "yard-sorbet", require: false + gem "redcarpet", require: false end group :ast, optional: true do gem "rubocop-ast", require: false diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index 474bd2f0c1..577bdc8ab9 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -60,7 +60,6 @@ class PATH @paths.join(File::PATH_SEPARATOR) end - # @!visibility private sig { returns(String) } def to_s = to_str diff --git a/Library/Homebrew/attestation.rb b/Library/Homebrew/attestation.rb index 2dc57ad57a..9f40bf1fe9 100644 --- a/Library/Homebrew/attestation.rb +++ b/Library/Homebrew/attestation.rb @@ -39,8 +39,8 @@ module Homebrew sig { returns(Pathname) } def self.gh_executable # NOTE: We disable HOMEBREW_VERIFY_ATTESTATIONS when installing `gh` itself, - # to prevent a cycle during bootstrapping. This can eventually be resolved - # by vendoring a pure-Ruby Sigstore verifier client. + # to prevent a cycle during bootstrapping. This can eventually be resolved + # by vendoring a pure-Ruby Sigstore verifier client. @gh_executable ||= T.let(with_env("HOMEBREW_VERIFY_ATTESTATIONS" => nil) do ensure_executable!("gh") end, T.nilable(Pathname)) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 3ff4e3e928..e2303765d3 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -265,7 +265,7 @@ EOS fi } -# NOTE: the members of the array in the second arg must not have spaces! +# NOTE: The members of the array in the second arg must not have spaces! check-array-membership() { local item=$1 shift diff --git a/Library/Homebrew/brew_irbrc b/Library/Homebrew/brew_irbrc index b31faa3525..00217d3fdd 100644 --- a/Library/Homebrew/brew_irbrc +++ b/Library/Homebrew/brew_irbrc @@ -1,6 +1,6 @@ -# Note: that we use a non-standard config file name to reduce -# name clashes with other IRB config files like `.irbrc`. -# Note #2: This doesn't work with system Ruby for some reason. +# NOTE: We use a non-standard config file name to reduce name clashes with +# other IRB config files like `.irbrc`. +# NOTE: This doesn't work with system Ruby for some reason. require 'irb/completion' diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb index 75f39c3193..ccc3117386 100644 --- a/Library/Homebrew/build_options.rb +++ b/Library/Homebrew/build_options.rb @@ -9,16 +9,26 @@ class BuildOptions end # True if a {Formula} is being built with a specific option. - #
args << "--i-want-spam" if build.with? "spam" # + # ### Examples + # + # ```ruby + # args << "--i-want-spam" if build.with? "spam" + # ``` + # + # ```ruby # args << "--qt-gui" if build.with? "qt" # "--with-qt" ==> build.with? "qt" + # ``` # - # # If a formula presents a user with a choice, but the choice must be fulfilled: + # If a formula presents a user with a choice, but the choice must be fulfilled: + # + # ```ruby # if build.with? "example2" # args << "--with-example2" # else # args << "--with-example1" - # end+ # end + # ``` def with?(val) option_names = val.respond_to?(:option_names) ? val.option_names : [val] @@ -34,7 +44,12 @@ class BuildOptions end # True if a {Formula} is being built without a specific option. - #
args << "--no-spam-plz" if build.without? "spam"+ # + # ### Example + # + # ```ruby + # args << "--no-spam-plz" if build.without? "spam" + # ``` def without?(val) !with?(val) end @@ -45,19 +60,33 @@ class BuildOptions end # True if a {Formula} is being built with {Formula.head} instead of {Formula.stable}. - #
args << "--some-new-stuff" if build.head?- #
# If there are multiple conditional arguments use a block instead of lines. + # + # ### Examples + # + # ```ruby + # args << "--some-new-stuff" if build.head? + # ``` + # + # If there are multiple conditional arguments use a block instead of lines. + # + # ```ruby # if build.head? # args << "--i-want-pizza" # args << "--and-a-cold-beer" if build.with? "cold-beer" - # end+ # end + # ``` def head? include? "HEAD" end # True if a {Formula} is being built with {Formula.stable} instead of {Formula.head}. # This is the default. - #
args << "--some-beta" if build.head?+ # + # ### Example + # + # ```ruby + # args << "--some-beta" if build.head? + # ``` def stable? !head? end diff --git a/Library/Homebrew/cask/artifact/abstract_artifact.rb b/Library/Homebrew/cask/artifact/abstract_artifact.rb index a202cad6b4..e722d0bc0f 100644 --- a/Library/Homebrew/cask/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/artifact/abstract_artifact.rb @@ -147,7 +147,6 @@ module Cask cask.config end - # @!visibility private sig { returns(String) } def to_s "#{summarize} (#{self.class.english_name})" diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index e7856806ce..5ffd9fb797 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -78,7 +78,8 @@ module Cask @allow_reassignment = allow_reassignment @loaded_from_api = loaded_from_api @loader = loader - # Sorbet has trouble with bound procs assigned to ivars: https://github.com/sorbet/sorbet/issues/6843 + # Sorbet has trouble with bound procs assigned to instance variables: + # https://github.com/sorbet/sorbet/issues/6843 instance_variable_set(:@block, block) @default_config = config || Config.new @@ -323,11 +324,9 @@ module Cask end # @api public - # @!visibility private sig { returns(String) } def to_s = token - # @!visibility private sig { returns(String) } def inspect "#
with_env(PATH: "/bin") do - # system "echo $PATH" - # end+ # added to `ENV`, then restores `ENV` afterwards. + # + # NOTE: This method is **not** thread-safe – other threads + # which happen to be scheduled during the block will also + # see these environment variables. + # + # ### Example + # + # ```ruby + # with_env(PATH: "/bin") do + # system "echo $PATH" + # end + # ``` # - # @note This method is *not* thread-safe - other threads - # which happen to be scheduled during the block will also - # see these environment variables. # @api public def with_env(hash) old_values = {} diff --git a/Library/Homebrew/extend/object/duplicable.rb b/Library/Homebrew/extend/object/duplicable.rb index d5f566cb52..a0f0462084 100644 --- a/Library/Homebrew/extend/object/duplicable.rb +++ b/Library/Homebrew/extend/object/duplicable.rb @@ -1,24 +1,30 @@ # typed: strict # frozen_string_literal: true -#-- # Most objects are cloneable, but not all. For example you can't dup methods: # -# method(:puts).dup # => TypeError: allocator undefined for Method +# ```ruby +# method(:puts).dup # => TypeError: allocator undefined for Method +# ``` # # Classes may signal their instances are not duplicable removing +dup+/+clone+ # or raising exceptions from them. So, to dup an arbitrary object you normally # use an optimistic approach and are ready to catch an exception, say: # -# arbitrary_object.dup rescue object +# ```ruby +# arbitrary_object.dup rescue object +# ``` # # Rails dups objects in a few critical spots where they are not that arbitrary. -# That rescue is very expensive (like 40 times slower than a predicate), and it +# That `rescue` is very expensive (like 40 times slower than a predicate) and it # is often triggered. # # That's why we hardcode the following cases and check duplicable? instead of # using that rescue idiom. -#++ +# rubocop:disable Layout/EmptyLines + + +# rubocop:enable Layout/EmptyLines class Object # Can you safely dup this object? # @@ -31,8 +37,10 @@ end class Method # Methods are not duplicable: # - # method(:puts).duplicable? # => false - # method(:puts).dup # => TypeError: allocator undefined for Method + # ```ruby + # method(:puts).duplicable? # => false + # method(:puts).dup # => TypeError: allocator undefined for Method + # ``` sig { returns(FalseClass) } def duplicable? = false end @@ -40,8 +48,10 @@ end class UnboundMethod # Unbound methods are not duplicable: # - # method(:puts).unbind.duplicable? # => false - # method(:puts).unbind.dup # => TypeError: allocator undefined for UnboundMethod + # ```ruby + # method(:puts).unbind.duplicable? # => false + # method(:puts).unbind.dup # => TypeError: allocator undefined for UnboundMethod + # ``` sig { returns(FalseClass) } def duplicable? = false end @@ -51,7 +61,9 @@ require "singleton" module Singleton # Singleton instances are not duplicable: # - # Class.new.include(Singleton).instance.dup # TypeError (can't dup instance of singleton + # ```ruby + # Class.new.include(Singleton).instance.dup # TypeError (can't dup instance of singleton + # ``` sig { returns(FalseClass) } def duplicable? = false end diff --git a/Library/Homebrew/extend/os/linux/parser.rb b/Library/Homebrew/extend/os/linux/parser.rb index fcbeb67f0b..9d76e9c9b3 100644 --- a/Library/Homebrew/extend/os/linux/parser.rb +++ b/Library/Homebrew/extend/os/linux/parser.rb @@ -16,7 +16,7 @@ module Homebrew return unless @args.cask? # NOTE: We don't raise an error here because we don't want - # to print the help page or a stack trace. + # to print the help page or a stack trace. odie "Invalid `--cask` usage: Casks do not work on Linux" end end diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb index c963cf4742..37a3a335fd 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb @@ -27,12 +27,11 @@ module Stdenv append "LDFLAGS", "-Wl,-headerpad_max_install_names" - # sed is strict, and errors out when it encounters files with - # mixed character sets + # `sed` is strict and errors out when it encounters files with mixed character sets. delete("LC_ALL") self["LC_CTYPE"] = "C" - # Add lib and include etc. from the current macosxsdk to compiler flags: + # Add `lib` and `include` etc. from the current `macosxsdk` to compiler flags: macosxsdk(formula: @formula, testing_formula:) return unless MacOS::Xcode.without_clt? @@ -42,8 +41,8 @@ module Stdenv end def remove_macosxsdk(version = nil) - # Clear all lib and include dirs from CFLAGS, CPPFLAGS, LDFLAGS that were - # previously added by macosxsdk + # Clear all `lib` and `include` dirs from `CFLAGS`, `CPPFLAGS`, `LDFLAGS` that were + # previously added by `macosxsdk`. remove_from_cflags(/ ?-mmacosx-version-min=\d+\.\d+/) delete("CPATH") remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib" @@ -58,14 +57,14 @@ module Stdenv if HOMEBREW_PREFIX.to_s == "/usr/local" delete("CMAKE_PREFIX_PATH") else - # It was set in setup_build_environment, so we have to restore it here. + # It was set in `setup_build_environment`, so we have to restore it here. self["CMAKE_PREFIX_PATH"] = HOMEBREW_PREFIX.to_s end remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" end def macosxsdk(version = nil, formula: nil, testing_formula: false) - # Sets all needed lib and include dirs to CFLAGS, CPPFLAGS, LDFLAGS. + # Sets all needed `lib` and `include` dirs to `CFLAGS`, `CPPFLAGS`, `LDFLAGS`. remove_macosxsdk min_version = version || MacOS.version append_to_cflags("-mmacosx-version-min=#{min_version}") diff --git a/Library/Homebrew/extend/os/mac/hardware/cpu.rb b/Library/Homebrew/extend/os/mac/hardware/cpu.rb index 72df60a253..0bcd281b2c 100644 --- a/Library/Homebrew/extend/os/mac/hardware/cpu.rb +++ b/Library/Homebrew/extend/os/mac/hardware/cpu.rb @@ -83,8 +83,8 @@ module Hardware sysctl_bool("hw.optional.sse4_2") end - # NOTE: this is more reliable than checking uname. - # `sysctl` returns the right answer even when running in Rosetta 2. + # NOTE: This is more reliable than checking `uname`. `sysctl` returns + # the right answer even when running in Rosetta 2. def physical_cpu_arm64? sysctl_bool("hw.optional.arm64") end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index d2c19de115..8b0c072d4c 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -126,10 +126,11 @@ class Pathname mkpath - # Use FileUtils.mv over File.rename to handle filesystem boundaries. If src - # is a symlink, and its target is moved first, FileUtils.mv will fail: - # https://bugs.ruby-lang.org/issues/7707 - # In that case, use the system "mv" command. + # Use `FileUtils.mv` over `File.rename` to handle filesystem boundaries. If `src` + # is a symlink and its target is moved first, `FileUtils.mv` will fail + # (https://bugs.ruby-lang.org/issues/7707). + # + # In that case, use the system `mv` command. if src.symlink? raise unless Kernel.system "mv", src.to_s, dst else @@ -178,7 +179,9 @@ class Pathname T.unsafe(self).open("a", **open_args) { |f| f.puts(content) } end - # @note This always overwrites. + # Write to a file atomically. + # + # NOTE: This always overwrites. # # @api public sig { params(content: String).void } @@ -201,6 +204,7 @@ class Pathname # Changing file ownership failed, moving on. nil end + begin # This operation will affect filesystem ACL's chmod(old_stat.mode) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 0d2c5a5508..6175f9abc9 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -48,7 +48,10 @@ require "extend/api_hashable" # @see https://docs.brew.sh/Formula-Cookbook Formula Cookbook # @see https://rubystyle.guide Ruby Style Guide # -#
class Wget < Formula +# ### Example +# +# ```ruby +# class Wget < Formula # homepage "https://www.gnu.org/software/wget/" # url "https://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz" # sha256 "52126be8cf1bddd7536886e74c053ad7d0ed2aa89b4b630f76785bac21695fcd" @@ -57,7 +60,8 @@ require "extend/api_hashable" # system "./configure", "--prefix=#{prefix}" # system "make", "install" # end -# end+# end +# ``` class Formula include FileUtils include Utils::Shebang @@ -543,15 +547,20 @@ class Formula # A named {Resource} for the currently active {SoftwareSpec}. # Additional downloads can be defined as {#resource}s. # {Resource#stage} will create a temporary directory and yield to a block. - #
resource("additional_files").stage { bin.install "my/extra/tool" }- # @!method resource - delegate resource: :active_spec + # + # ### Example + # + # ```ruby + # resource("additional_files").stage { bin.install "my/extra/tool" } + # ``` + def resource(name) + active_spec.resource(name) + end # An old name for the formula. - # @deprecated Use {#oldnames} instead. sig { returns(T.nilable(String)) } def oldname - odisabled "Formula#oldname", "Formula#oldnames" + odisabled "`Formula#oldname`", "`Formula#oldnames`" @oldname ||= oldnames.first end @@ -589,12 +598,14 @@ class Formula delegate declared_deps: :active_spec # Dependencies provided by macOS for the currently active {SoftwareSpec}. - # @deprecated - delegate uses_from_macos_elements: :active_spec + def uses_from_macos_elements + odisabled "`Formula#uses_from_macos_elements`", "`Formula#declared_deps`" + end # Dependency names provided by macOS for the currently active {SoftwareSpec}. - # @deprecated - delegate uses_from_macos_names: :active_spec + def uses_from_macos_names + odisabled "`Formula#uses_from_macos_names`", "`Formula#declared_deps`" + end # The {Requirement}s for the currently active {SoftwareSpec}. delegate requirements: :active_spec @@ -760,11 +771,19 @@ class Formula # This is symlinked into `HOMEBREW_PREFIX` after installation or with # `brew link` for formulae that are not keg-only. # + # ### Examples + # # Need to install into the {.bin} but the makefile doesn't `mkdir -p prefix/bin`? - #
bin.mkpath+ # + # ```ruby + # bin.mkpath + # ``` # # No `make install` available? - #
bin.install "binary1"+ # + # ```ruby + # bin.install "binary1" + # ``` # # @api public sig { returns(Pathname) } @@ -786,8 +805,13 @@ class Formula # This is symlinked into `HOMEBREW_PREFIX` after installation or with # `brew link` for formulae that are not keg-only. # + # ### Example + # # No `make install` available? - #
include.install "example.h"+ # + # ```ruby + # include.install "example.h" + # ``` # # @api public sig { returns(Pathname) } @@ -809,8 +833,13 @@ class Formula # This is symlinked into `HOMEBREW_PREFIX` after installation or with # `brew link` for formulae that are not keg-only. # + # ### Example + # # No `make install` available? - #
lib.install "example.dylib"+ # + # ```ruby + # lib.install "example.dylib" + # ``` # # @api public sig { returns(Pathname) } @@ -823,9 +852,13 @@ class Formula # It is commonly used to install files that we do not wish to be # symlinked into `HOMEBREW_PREFIX` from one of the other directories and # instead manually create symlinks or wrapper scripts into e.g. {#bin}. - #
libexec.install "foo.jar" + # + # ### Example + # + # ```ruby + # libexec.install "foo.jar" # bin.write_jar_script libexec/"foo.jar", "foo" - #+ # ``` # # @api public sig { returns(Pathname) } @@ -849,8 +882,13 @@ class Formula # This is symlinked into `HOMEBREW_PREFIX` after installation or with # `brew link` for formulae that are not keg-only. # + # ### Example + # # No `make install` available? - #
man1.install "example.1"+ # + # ```ruby + # man1.install "example.1" + # ``` # # @api public sig { returns(Pathname) } @@ -872,8 +910,13 @@ class Formula # This is symlinked into `HOMEBREW_PREFIX` after installation or with # `brew link` for formulae that are not keg-only. # + # ### Example + # # No `make install` available? - #
man3.install "man.3"+ # + # ```ruby + # man3.install "man.3" + # ``` # # @api public sig { returns(Pathname) } @@ -946,17 +989,31 @@ class Formula # This is symlinked into `HOMEBREW_PREFIX` after installation or with # `brew link` for formulae that are not keg-only. # + # ### Examples + # # Need a custom directory? - #
(share/"concept").mkpath+ # + # ```ruby + # (share/"concept").mkpath + # ``` # # Installing something into another custom directory? - #
(share/"concept2").install "ducks.txt"+ # + # ```ruby + # (share/"concept2").install "ducks.txt" + # ``` # # Install `./example_code/simple/ones` to `share/demos`: - #
(share/"demos").install "example_code/simple/ones"+ # + # ```ruby + # (share/"demos").install "example_code/simple/ones" + # ``` # # Install `./example_code/simple/ones` to `share/demos/examples`: - #
(share/"demos").install "example_code/simple/ones" => "examples"+ # + # ```ruby + # (share/"demos").install "example_code/simple/ones" => "examples" + # ``` # # @api public sig { returns(Pathname) } @@ -969,8 +1026,13 @@ class Formula # This is symlinked into `HOMEBREW_PREFIX` after installation or with # `brew link` for formulae that are not keg-only. # + # ### Example + # # No `make install` available? - #
pkgshare.install "examples"+ # + # ```ruby + # pkgshare.install "examples" + # ``` # # @api public sig { returns(Pathname) } @@ -981,8 +1043,13 @@ class Formula # The directory where Emacs Lisp files should be installed, with the # formula name appended to avoid linking conflicts. # + # ### Example + # # To install an Emacs mode included with a software package: - #
elisp.install "contrib/emacs/example-mode.el"+ # + # ```ruby + # elisp.install "contrib/emacs/example-mode.el" + # ``` # # @api public sig { returns(Pathname) } @@ -1134,8 +1201,11 @@ class Formula end # This method can be overridden to provide a plist. - # @see https://www.unix.com/man-page/all/5/plist/ Apple's plist(5) man page - #
def plist; <<~EOS + # + # ### Example + # + # ```ruby + # def plist; <<~EOS # # #+ # end + # ``` # - # @deprecated Please use {Homebrew::Service} instead. + # @see https://www.unix.com/man-page/all/5/plist/@@ -1158,11 +1228,13 @@ class Formula # # # EOS - # end
plist(5)
man page
def plist
# odeprecated: consider removing entirely in 4.3.0
+ # odeprecated "`Formula#plist`", "`Homebrew::Service`"
nil
end
@@ -1207,7 +1279,12 @@ class Formula
#
# This is the preferred way to refer to a formula in plists or from another
# formula, as the path is stable even when the software is updated.
- # args << "--with-readline=#{Formula["readline"].opt_prefix}" if build.with? "readline"+ # + # ### Example + # + # ```ruby + # args << "--with-readline=#{Formula["readline"].opt_prefix}" if build.with? "readline" + # ``` # # @api public sig { returns(Pathname) } @@ -1353,14 +1430,19 @@ class Formula # Warn the user about any Homebrew-specific issues or quirks for this package. # These should not contain setup instructions that would apply to installation # through a different package manager on a different OS. - # @return [String] - #
def caveats + # + # ### Example + # + # ```ruby + # def caveats # <<~EOS # Are optional. Something the user must be warned about? # EOS - # end+ # end + # ``` # - #
def caveats + # ```ruby + # def caveats # s = <<~EOS # Print some important notice to the user when `brew info [formula]` is # called or when brewing a formula. @@ -1368,7 +1450,8 @@ class Formula # EOS # s += "Some issue only on older systems" if MacOS.version < :el_capitan # s - # end+ # end + # ``` sig { overridable.returns(T.nilable(String)) } def caveats nil @@ -1656,6 +1739,7 @@ class Formula delegate pinnable?: :@pin + # !attr[r] pinned? # @api internal delegate pinned?: :@pin @@ -1687,11 +1771,9 @@ class Formula end # @api public - # @!visibility private sig { returns(String) } def to_s = name - # @!visibility private sig { returns(String) } def inspect "#
shared_library("foo") #=> foo.dylib + # ### Example + # + # ```ruby + # shared_library("foo") #=> foo.dylib # shared_library("foo", 1) #=> foo.1.dylib # shared_library("foo", "*") #=> foo.2.dylib, foo.1.dylib, foo.dylib # shared_library("*") #=> foo.dylib, bar.dylib - #+ # ``` sig { params(name: String, version: T.nilable(T.any(String, Integer))).returns(String) } def shared_library(name, version = nil) return "*.dylib" if name == "*" && (version.blank? || version == "*") @@ -1815,10 +1900,13 @@ class Formula # Optionally specify a `source` or `target` depending on the location # of the file containing the RPATH command and where its target is located. # - #
rpath #=> "@loader_path/../lib" + # ### Example + # + # ```ruby + # rpath #=> "@loader_path/../lib" # rpath(target: frameworks) #=> "@loader_path/../Frameworks" # rpath(source: libexec/"bin") #=> "@loader_path/../../lib" - #+ # ``` sig { params(source: Pathname, target: Pathname).returns(String) } def rpath(source: bin, target: lib) unless target.to_s.start_with?(HOMEBREW_PREFIX) @@ -1880,68 +1968,96 @@ class Formula end private :extract_macho_slice_from - # Generate shell completions for a formula for bash, zsh, and fish, using the formula's executable. + # Generate shell completions for a formula for `bash`, `zsh` and `fish`, using the formula's executable. # - # @param commands [Pathname, String] the path to the executable and any passed subcommand(s) - # to use for generating the completion scripts. - # @param base_name [String] the base name of the generated completion script. Defaults to the formula name. - # @param shells [Array
def install + # + # ### Example + # + # ```ruby + # def install # system "./configure", "--prefix=#{prefix}" # system "make", "install" - # end+ # end + # ``` def install; end # Sometimes we have to change a bit before we install. Mostly we @@ -2713,14 +2836,21 @@ class Formula # defined by the formula, as only `HOMEBREW_PREFIX` is available # in the {DATAPatch embedded patch}. # + # ### Examples + # # `inreplace` supports regular expressions: - #
inreplace "somefile.cfg", /look[for]what?/, "replace by #{bin}/tool"+ # + # ```ruby + # inreplace "somefile.cfg", /look[for]what?/, "replace by #{bin}/tool" + # ``` # # `inreplace` supports blocks: - #
inreplace "Makefile" do |s| + # + # ```ruby + # inreplace "Makefile" do |s| # s.gsub! "/usr/local", HOMEBREW_PREFIX.to_s # end - #+ # ``` # # @see Utils::Inreplace.inreplace # @api public @@ -2780,26 +2910,43 @@ class Formula # To call out to the system, we use the `system` method and we prefer # you give the args separately as in the line below, otherwise a subshell # has to be opened first. - #
system "./bootstrap.sh", "--arg1", "--prefix=#{prefix}"+ # + # ### Examples + # + # ```ruby + # system "./bootstrap.sh", "--arg1", "--prefix=#{prefix}" + # ``` # # For CMake and other build systems we have some necessary defaults in e.g. # {#std_cmake_args}: - #
system "cmake", ".", *std_cmake_args+ # + # ```ruby + # system "cmake", ".", *std_cmake_args + # ``` # # If the arguments given to `configure` (or `make` or `cmake`) are depending # on options defined above, we usually make a list first and then # use the `args << if
args = ["--with-option1", "--with-option2"] - # args << "--without-gcc" if ENV.compiler == :clang # - # # Most software still uses `configure` and `make`. - # # Check with `./configure --help` for what our options are. + # ```ruby + # args = ["--with-option1", "--with-option2"] + # args << "--without-gcc" if ENV.compiler == :clang + # ``` + # + # Most software still uses `configure` and `make`. + # Check with `./configure --help` for what our options are. + # + # ```ruby # system "./configure", "--disable-debug", "--disable-dependency-tracking", # "--disable-silent-rules", "--prefix=#{prefix}", # *args # our custom arg list (needs `*` to unpack) + # ``` # - # # If there is a "make install" available, please use it! - # system "make", "install"+ # If there is a "make install" available, please use it! + # + # ```ruby + # system "make", "install" + # ``` sig { params(cmd: T.any(String, Pathname), args: T.any(String, Integer, Pathname, Symbol)).void } def system(cmd, *args) verbose_using_dots = Homebrew::EnvConfig.verbose_using_dots? @@ -3138,36 +3285,65 @@ class Formula # of the software and Homebrew maintainers. # Shows when running `brew info`. # - #
desc "Example formula"+ # ### Example + # + # ```ruby + # desc "Example formula" + # ``` # # @!attribute [w] desc # @api public attr_rw :desc - # @!attribute [w] license # The SPDX ID of the open-source license that the formula uses. # Shows when running `brew info`. + # # Use `:any_of`, `:all_of` or `:with` to describe complex license expressions. # `:any_of` should be used when the user can choose which license to use. # `:all_of` should be used when the user must use all licenses. # `:with` should be used to specify a valid SPDX exception. + # # Add `+` to an identifier to indicate that the formulae can be # licensed under later versions of the same license. - # @see https://docs.brew.sh/License-Guidelines Homebrew License Guidelines - # @see https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/ SPDX license expression guide - #
license "BSD-2-Clause"- #
license "EPL-1.0+"- #
license any_of: ["MIT", "GPL-2.0-only"]- #
license all_of: ["MIT", "GPL-2.0-only"]- #
license "GPL-2.0-only" => { with: "LLVM-exception" }- #
license :public_domain- #
license any_of: [ + # + # ### Examples + # + # ```ruby + # license "BSD-2-Clause" + # ``` + # + # ```ruby + # license "EPL-1.0+" + # ``` + # + # ```ruby + # license any_of: ["MIT", "GPL-2.0-only"] + # ``` + # + # ```ruby + # license all_of: ["MIT", "GPL-2.0-only"] + # ``` + # + # ```ruby + # license "GPL-2.0-only" => { with: "LLVM-exception" } + # ``` + # + # ```ruby + # license :public_domain + # ``` + # + # ```ruby + # license any_of: [ # "MIT", # :public_domain, # all_of: ["0BSD", "Zlib", "Artistic-1.0+"], # "Apache-2.0" => { with: "LLVM-exception" }, - # ]+ # ] + # ``` # + # @!attribute [w] license + # @see https://docs.brew.sh/License-Guidelines Homebrew License Guidelines + # @see https://spdx.github.io/spdx-spec/appendix-IV-SPDX-license-expressions/ SPDX license expression guide # @api public def license(args = nil) if args.nil? @@ -3177,14 +3353,26 @@ class Formula end end - # @!attribute [w] allow_network_access! # The phases for which network access is allowed. By default, network # access is allowed for all phases. Valid phases are `:build`, `:test`, # and `:postinstall`. When no argument is passed, network access will be # allowed for all phases. - #
allow_network_access!- #
allow_network_access! :build- #
allow_network_access! [:build, :test]+ # + # ### Examples + # + # ```ruby + # allow_network_access! + # ``` + # + # ```ruby + # allow_network_access! :build + # ``` + # + # ```ruby + # allow_network_access! [:build, :test] + # ``` + # + # @!attribute [w] allow_network_access! sig { params(phases: T.any(Symbol, T::Array[Symbol])).void } def allow_network_access!(phases = []) phases_array = Array(phases) @@ -3199,14 +3387,26 @@ class Formula end end - # @!attribute [w] deny_network_access! # The phases for which network access is denied. By default, network # access is allowed for all phases. Valid phases are `:build`, `:test`, # and `:postinstall`. When no argument is passed, network access will be # denied for all phases. - #
deny_network_access!- #
deny_network_access! :build- #
deny_network_access! [:build, :test]+ # + # ### Examples + # + # ```ruby + # deny_network_access! + # ``` + # + # ```ruby + # deny_network_access! :build + # ``` + # + # ```ruby + # deny_network_access! [:build, :test] + # ``` + # + # @!attribute [w] deny_network_access! sig { params(phases: T.any(Symbol, T::Array[Symbol])).void } def deny_network_access!(phases = []) phases_array = Array(phases) @@ -3230,35 +3430,43 @@ class Formula env_var.nil? ? @network_access_allowed[phase] : env_var == "allow" end - # @!attribute [w] homepage # The homepage for the software. Used by users to get more information # about the software and Homebrew maintainers as a point of contact for # e.g. submitting patches. # Can be opened with running `brew home`. # - #
homepage "https://www.example.com"+ # ### Example + # + # ```ruby + # homepage "https://www.example.com" + # ``` # # @!attribute [w] homepage # @api public attr_rw :homepage - # Whether a livecheck specification is defined or not. - # It returns true when a livecheck block is present in the {Formula} and - # false otherwise, and is used by livecheck. + # Checks whether a `livecheck` specification is defined or not. + # + # It returns `true` when a `livecheck` block is present in the {Formula} + # and `false` otherwise. sig { returns(T::Boolean) } def livecheckable? @livecheckable == true end - # Whether a service specification is defined or not. - # It returns true when a service block is present in the {Formula} and - # false otherwise, and is used by service. + # Checks whether a service specification is defined or not. + # + # It returns `true` when a service block is present in the {Formula} + # and `false` otherwise. sig { returns(T::Boolean) } def service? @service_block.present? end - attr_reader :conflicts, :skip_clean_paths, :link_overwrite_paths, :pour_bottle_only_if + sig { returns(T::Array[FormulaConflict]) } + attr_reader :conflicts + + attr_reader :skip_clean_paths, :link_overwrite_paths, :pour_bottle_only_if # If `pour_bottle?` returns `false` the user-visible reason to display for # why they cannot use the bottle. @@ -3271,7 +3479,11 @@ class Formula # {Formula} to install a new version linked against the new library version. # `0` if unset. # - #
revision 1+ # ### Example + # + # ```ruby + # revision 1 + # ``` # # @api public attr_rw :revision @@ -3285,7 +3497,11 @@ class Formula # higher version. # `0` if unset. # - #
version_scheme 1+ # ### Example + # + # ```ruby + # version_scheme 1 + # ``` # # @api public attr_rw :version_scheme @@ -3301,7 +3517,6 @@ class Formula end.freeze end - # @!attribute [w] url # The URL used to download the source for the {.stable} version of the formula. # We prefer `https` for security and proxy reasons. # If not inferable, specify the download strategy with `using: ...`. @@ -3311,12 +3526,20 @@ class Formula # - `:nounzip` (without extracting) # - `:post` (download via an HTTP POST) # - #
url "https://packed.sources.and.we.prefer.https.example.com/archive-1.2.3.tar.bz2"- #
url "https://some.dont.provide.archives.example.com", + # ### Examples + # + # ```ruby + # url "https://packed.sources.and.we.prefer.https.example.com/archive-1.2.3.tar.bz2" + # ``` + # + # ```ruby + # url "https://some.dont.provide.archives.example.com", # using: :git, # tag: "1.2.3", - # revision: "db8e4de5b2d6653f66aea53094624468caad15d2"+ # revision: "db8e4de5b2d6653f66aea53094624468caad15d2" + # ``` # + # @!attribute [w] url # @api public def url(val, specs = {}) stable.url(val, specs) @@ -3327,7 +3550,11 @@ class Formula # The version is autodetected from the URL and/or tag so only needs to be # declared if it cannot be autodetected correctly. # - #
version "1.2-final"+ # ### Example + # + # ```ruby + # version "1.2-final" + # ``` # # @api public def version(val = nil) @@ -3341,8 +3568,12 @@ class Formula # is unreliable. If {.url} is really unreliable then we may swap the # {.mirror} and {.url}. # - #
mirror "https://in.case.the.host.is.down.example.com" - # mirror "https://in.case.the.mirror.is.down.example.com+ # ### Example + # + # ```ruby + # mirror "https://in.case.the.host.is.down.example.com" + # mirror "https://in.case.the.mirror.is.down.example.com + # ``` # # @api public def mirror(val) @@ -3356,14 +3587,17 @@ class Formula # this value you can leave it blank and run `brew fetch --force` and it'll # tell you the currently valid value. # - #
sha256 "2a2ba417eebaadcb4418ee7b12fe2998f26d6e6f7fda7983412ff66a741ab6f7"+ # ### Example + # + # ```ruby + # sha256 "2a2ba417eebaadcb4418ee7b12fe2998f26d6e6f7fda7983412ff66a741ab6f7" + # ``` # # @api public def sha256(val) stable.sha256(val) end - # @!attribute [w] bottle # Adds a {.bottle} {SoftwareSpec}. # This provides a pre-built binary package built by the Homebrew maintainers for you. # It will be installed automatically if there is a binary package for your platform @@ -3374,14 +3608,16 @@ class Formula # You can ignore this block entirely if submitting to Homebrew/homebrew-core. # It'll be handled for you by the Brew Test Bot. # - #
bottle do + # ```ruby + # bottle do # root_url "https://example.com" # Optional root to calculate bottle URLs. # rebuild 1 # Marks the old bottle as outdated without bumping the version/revision of the formula. # # Optionally specify the HOMEBREW_CELLAR in which the bottles were built. # sha256 cellar: "/brew/Cellar", catalina: "ef65c759c5097a36323fa9c77756468649e8d1980a3a4e05695c05e39568967c" # sha256 cellar: :any, mojave: "28f4090610946a4eb207df102d841de23ced0d06ba31cb79e040d883906dcd4f" # sha256 high_sierra: "91dd0caca9bd3f38c439d5a7b6f68440c4274945615fae035ff0a369264b8a2f" - # end+ # end + # ``` # # Homebrew maintainers aim to bottle all formulae. # @@ -3409,13 +3645,17 @@ class Formula # This is required instead of using a conditional. # It is preferable to also pull the {url} and {sha256= sha256} into the block if one is added. # - #
stable do + # ### Example + # + # ```ruby + # stable do # url "https://example.com/foo-1.0.tar.gz" # sha256 "2a2ba417eebaadcb4418ee7b12fe2998f26d6e6f7fda7983412ff66a741ab6f7" # # depends_on "libxml2" # depends_on "libffi" - # end+ # end + # ``` # # @api public def stable(&block) @@ -3432,10 +3672,22 @@ class Formula # If a block is provided you can also add {.depends_on} and {Patch}es just to the {.head} {SoftwareSpec}. # The download strategies (e.g. `:using =>`) are the same as for {url}. # `master` is the default branch and doesn't need stating with a `branch:` parameter. - #
head "https://we.prefer.https.over.git.example.com/.git"- #
head "https://example.com/.git", branch: "name_of_branch"+ # + # ### Example + # + # ```ruby + # head "https://we.prefer.https.over.git.example.com/.git" + # ``` + # + # ```ruby + # head "https://example.com/.git", branch: "name_of_branch" + # ``` + # # or (if autodetect fails): - #
head "https://hg.is.awesome.but.git.has.won.example.com/", using: :hg+ # + # ```ruby + # head "https://hg.is.awesome.but.git.has.won.example.com/", using: :hg + # ``` def head(val = nil, specs = {}, &block) if block @head.instance_eval(&block) @@ -3449,10 +3701,15 @@ class Formula # Additional downloads can be defined as {resource}s and accessed in the # install method. Resources can also be defined inside a {.stable} or # {.head} block. This mechanism replaces ad-hoc "subformula" classes. - #
resource "additional_files" do + # + # ### Example + # + # ```ruby + # resource "additional_files" do # url "https://example.com/additional-stuff.tar.gz" # sha256 "c6bc3f48ce8e797854c4b865f6a8ff969867bbcaebd648ae6fd825683e59fef2" - # end+ # end + # ``` # # @api public def resource(name, klass = Resource, &block) @@ -3461,9 +3718,11 @@ class Formula end end + # Specify a Go resource. + # # @api public def go_resource(name, &block) - # odeprecated "Formula#go_resource", "Go modules" + # odeprecated "`Formula.go_resource`", "Go modules" specs.each { |spec| spec.go_resource(name, &block) } end @@ -3472,37 +3731,62 @@ class Formula # that needs extra handling (often changing some ENV vars or # deciding whether to use the system provided version). # + # ### Examples + # # `:build` means this dependency is only needed during build. - #
depends_on "cmake" => :build+ # + # ```ruby + # depends_on "cmake" => :build + # ``` # # `:test` means this dependency is only needed during testing. - #
depends_on "node" => :test+ # + # ```ruby + # depends_on "node" => :test + # ``` # # `:recommended` dependencies are built by default. # But a `--without-...` option is generated to opt-out. - #
depends_on "readline" => :recommended+ # + # ```ruby + # depends_on "readline" => :recommended + # ``` # # `:optional` dependencies are NOT built by default unless the # auto-generated `--with-...` option is passed. - #
depends_on "glib" => :optional+ # + # ```ruby + # depends_on "glib" => :optional + # ``` # # If you need to specify that another formula has to be built with/out # certain options (note, no `--` needed before the option): - #
depends_on "zeromq" => "with-pgm" - # depends_on "qt" => ["with-qtdbus", "developer"] # Multiple options.+ # + # ```ruby + # depends_on "zeromq" => "with-pgm" + # depends_on "qt" => ["with-qtdbus", "developer"] # Multiple options. + # ``` # # Optional and enforce that "boost" is built using `--with-c++11`. - #
depends_on "boost" => [:optional, "with-c++11"]+ # + # ```ruby + # depends_on "boost" => [:optional, "with-c++11"] + # ``` # # If a dependency is only needed in certain cases: - #
depends_on "sqlite" if MacOS.version >= :catalina + # + # ```ruby + # depends_on "sqlite" if MacOS.version >= :catalina # depends_on xcode: :build # If the formula really needs full Xcode to compile. # depends_on macos: :mojave # Needs at least macOS Mojave (10.14) to run. - #+ # ``` # # It is possible to only depend on something if # `build.with?` or `build.without? "another_formula"`: - #
depends_on "postgresql" if build.without? "sqlite"+ # + # ```ruby + # depends_on "postgresql" if build.without? "sqlite" + # ``` # # @api public def depends_on(dep) @@ -3536,9 +3820,20 @@ class Formula # # - `:universal`: build a universal binary/library (e.g. on newer Intel Macs # this means a combined x86_64/x86 binary/library). - #
option "with-spam", "The description goes here without a dot at the end"- #
option "with-qt", "Text here overwrites what's autogenerated by 'depends_on "qt" => :optional'"- #
option :universal+ # + # ### Examples + # + # ```ruby + # option "with-spam", "The description goes here without a dot at the end" + # ``` + # + # ```ruby + # option "with-qt", "Text here overwrites what's autogenerated by 'depends_on "qt" => :optional'" + # ``` + # + # ```ruby + # option :universal + # ``` # # @api public def option(name, description = "") @@ -3549,7 +3844,12 @@ class Formula # Deprecated options are used to rename options and migrate users who used # them to newer ones. They are mostly used for migrating non-`with` options # (e.g. `enable-debug`) to `with` options (e.g. `with-debug`). - #
deprecated_option "enable-debug" => "with-debug"+ # + # ### Example + # + # ```ruby + # deprecated_option "enable-debug" => "with-debug" + # ``` # # @api public def deprecated_option(hash) @@ -3557,44 +3857,66 @@ class Formula end # External patches can be declared using resource-style blocks. - #
patch do + # + # ### Examples + # + # ```ruby + # patch do # url "https://example.com/example_patch.diff" # sha256 "c6bc3f48ce8e797854c4b865f6a8ff969867bbcaebd648ae6fd825683e59fef2" - # end+ # end + # ``` # # A strip level of `-p1` is assumed. It can be overridden using a symbol # argument: - #
patch :p0 do + # + # ```ruby + # patch :p0 do # url "https://example.com/example_patch.diff" # sha256 "c6bc3f48ce8e797854c4b865f6a8ff969867bbcaebd648ae6fd825683e59fef2" - # end+ # end + # ``` # # Patches can be declared in stable and head blocks. This form is # preferred over using conditionals. - #
stable do + # + # ```ruby + # stable do # patch do # url "https://example.com/example_patch.diff" # sha256 "c6bc3f48ce8e797854c4b865f6a8ff969867bbcaebd648ae6fd825683e59fef2" # end - # end+ # end + # ``` # # Embedded (`__END__`) patches are declared like so: - #
patch :DATA - # patch :p0, :DATA+ # + # ```ruby + # patch :DATA + # patch :p0, :DATA + # ``` # # Patches can also be embedded by passing a string. This makes it possible # to provide multiple embedded patches while making only some of them # conditional. - #
patch :p0, "..."- # @see https://docs.brew.sh/Formula-Cookbook#patches Patches # + # ```ruby + # patch :p0, "..." + # ``` + # + # @see https://docs.brew.sh/Formula-Cookbook#patches Patches # @api public def patch(strip = :p1, src = nil, &block) specs.each { |spec| spec.patch(strip, src, &block) } end # One or more formulae that conflict with this one and why. - #
conflicts_with "imagemagick", because: "both install `convert` binaries"+ # + # ### Example + # + # ```ruby + # conflicts_with "imagemagick", because: "both install `convert` binaries" + # ``` # # @api public def conflicts_with(*names) @@ -3605,10 +3927,20 @@ class Formula # Skip cleaning paths in a formula. # # Sometimes the formula {Cleaner cleaner} breaks things. + # + # ### Examples + # # Preserve cleaned paths with: - #
skip_clean "bin/foo", "lib/bar"+ # + # ```ruby + # skip_clean "bin/foo", "lib/bar" + # ``` + # # Keep .la files with: - #
skip_clean :la+ # + # ```ruby + # skip_clean :la + # ``` # # @api public def skip_clean(*paths) @@ -3619,15 +3951,26 @@ class Formula # Software that will not be symlinked into the `brew --prefix` and will # only live in its Cellar. Other formulae can depend on it and Homebrew - # will add the necessary includes, libraries, and other paths while + # will add the necessary includes, libraries and other paths while # building that other formula. # # Keg-only formulae are not in your PATH and are not seen by compilers # if you build your own software outside of Homebrew. This way, we # don't shadow software provided by macOS. - #
keg_only :provided_by_macos- #
keg_only :versioned_formulae- #
keg_only "because I want it so"+ # + # ### Examples + # + # ```ruby + # keg_only :provided_by_macos + # ``` + # + # ```ruby + # keg_only :versioned_formulae + # ``` + # + # ```ruby + # keg_only "because I want it so" + # ``` # # @api public def keg_only(reason, explanation = "") @@ -3642,13 +3985,19 @@ class Formula end # Marks the {Formula} as failing with a particular compiler so it will fall back to others. + # + # ### Examples + # # For Apple compilers, this should be in the format: - #
fails_with :clang do + # + # ```ruby + # fails_with :clang do # build 600 # cause "multiple configure and compile errors" - # end+ # end + # ``` # - # The block may be omitted, and if present the build may be omitted; + # The block may be omitted and if present, the build may be omitted; # if so, then the compiler will not be allowed for *all* versions. # # `major_version` should be the major release number only, for instance @@ -3659,9 +4008,11 @@ class Formula # For example, if a bug is only triggered on GCC 7.1 but is not # encountered on 7.2: # - #
fails_with :gcc => '7' do + # ```ruby + # fails_with :gcc => '7' do # version '7.1' - # end+ # end + # ``` # # @api public def fails_with(compiler, &block) @@ -3684,7 +4035,6 @@ class Formula end # A test is required for new formulae and makes us happy. - # @return [Boolean] # # The block will create, run in and delete a temporary directory. # @@ -3694,42 +4044,53 @@ class Formula # and `foo --version` or `foo --help` are bad tests. # However, a bad test is better than no test at all. # - # @see https://docs.brew.sh/Formula-Cookbook#add-a-test-to-the-formula Tests + # ### Examples # - #
(testpath/"test.file").write <<~EOS + # ```ruby + # (testpath/"test.file").write <<~EOS # writing some test file, if you need to # EOS - # assert_equal "OK", shell_output("test_command test.file").strip+ # assert_equal "OK", shell_output("test_command test.file").strip + # ``` # # Need complete control over stdin, stdout? - #
require "open3" + # + # ```ruby + # require "open3" # Open3.popen3("#{bin}/example", "argument") do |stdin, stdout, _| # stdin.write("some text") # stdin.close # assert_equal "result", stdout.read - # end+ # end + # ``` # # The test will fail if it returns false, or if an exception is raised. # Failed assertions and failed `system` commands will raise exceptions. # + # @see https://docs.brew.sh/Formula-Cookbook#add-a-test-to-the-formula Tests + # @return [Boolean] # @api public def test(&block) define_method(:test, &block) end - # @!attribute [w] livecheck # {Livecheck} can be used to check for newer versions of the software. # This method evaluates the DSL specified in the livecheck block of the # {Formula} (if it exists) and sets the instance variables of a {Livecheck} # object accordingly. This is used by `brew livecheck` to check for newer # versions of the software. # - #
livecheck do + # ### Example + # + # ```ruby + # livecheck do # skip "Not maintained" # url "https://example.com/foo/releases" # regex /foo-(\d+(?:\.\d+)+)\.tar/ - # end+ # end + # ``` # + # @!attribute [w] livecheck # @api public def livecheck(&block) return @livecheck unless block @@ -3738,16 +4099,20 @@ class Formula @livecheck.instance_eval(&block) end - # @!attribute [w] service # Service can be used to define services. # This method evaluates the DSL specified in the service block of the # {Formula} (if it exists) and sets the instance variables of a Service # object accordingly. This is used by `brew install` to generate a service file. # - #
service do - # run [opt_bin/"foo"] - # end+ # ### Example # + # ```ruby + # service do + # run [opt_bin/"foo"] + # end + # ``` + # + # @!attribute [w] service # @api public def service(&block) return @service_block unless block @@ -3758,18 +4123,26 @@ class Formula # Defines whether the {Formula}'s bottle can be used on the given Homebrew # installation. # - # For example, if the bottle requires the Xcode CLT to be installed a + # ### Examples + # + # If the bottle requires the Xcode CLT to be installed a # {Formula} would declare: - #
pour_bottle? do + # + # ```ruby + # pour_bottle? do # reason "The bottle needs the Xcode CLT to be installed." # satisfy { MacOS::CLT.installed? } - # end+ # end + # ``` # # If `satisfy` returns `false` then a bottle will not be used and instead # the {Formula} will be built from source and `reason` will be printed. # # Alternatively, a preset reason can be passed as a symbol: - #
pour_bottle? only_if: :clt_installed+ # + # ```ruby + # pour_bottle? only_if: :clt_installed + # ``` # # @api public def pour_bottle?(only_if: nil, &block) @@ -3811,11 +4184,19 @@ class Formula # Deprecates a {Formula} (on the given date) so a warning is # shown on each installation. If the date has not yet passed the formula # will not be deprecated. - #
deprecate! date: "2020-08-27", because: :unmaintained- #
deprecate! date: "2020-08-27", because: "has been replaced by foo"+ # + # ### Examples + # + # ```ruby + # deprecate! date: "2020-08-27", because: :unmaintained + # ``` + # + # ```ruby + # deprecate! date: "2020-08-27", because: "has been replaced by foo" + # ``` + # # @see https://docs.brew.sh/Deprecating-Disabling-and-Removing-Formulae # @see DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS - # # @api public def deprecate!(date:, because:) @deprecation_date = Date.parse(date) @@ -3835,11 +4216,13 @@ class Formula # The date that this {Formula} was or becomes deprecated. # Returns `nil` if no date is specified. + # # @return Date # @see .deprecate! attr_reader :deprecation_date # The reason for deprecation of a {Formula}. + # # @return [nil] if no reason was provided or the formula is not deprecated. # @return [String, Symbol] # @see .deprecate! @@ -3848,11 +4231,19 @@ class Formula # Disables a {Formula} (on the given date) so it cannot be # installed. If the date has not yet passed the formula # will be deprecated instead of disabled. - #
disable! date: "2020-08-27", because: :does_not_build- #
disable! date: "2020-08-27", because: "has been replaced by foo"+ # + # ### Examples + # + # ```ruby + # disable! date: "2020-08-27", because: :does_not_build + # ``` + # + # ```ruby + # disable! date: "2020-08-27", because: "has been replaced by foo" + # ``` + # # @see https://docs.brew.sh/Deprecating-Disabling-and-Removing-Formulae # @see DeprecateDisable::FORMULA_DEPRECATE_DISABLE_REASONS - # # @api public def disable!(date:, because:) @disable_date = Date.parse(date) @@ -3869,6 +4260,7 @@ class Formula # Whether this {Formula} is disabled (i.e. cannot be installed). # Defaults to false. + # # @see .disable! sig { returns(T::Boolean) } def disabled? @@ -3877,22 +4269,32 @@ class Formula # The date that this {Formula} was or becomes disabled. # Returns `nil` if no date is specified. + # # @return Date # @see .disable! attr_reader :disable_date # The reason this {Formula} is disabled. # Returns `nil` if no reason was provided or the formula is not disabled. + # # @return [String, Symbol] # @see .disable! attr_reader :disable_reason # Permit overwriting certain files while linking. # - # Sometimes we accidentally install files outside prefix. Once we fix that, + # ### Examples + # + # Sometimes we accidentally install files outside the prefix. Once we fix that, # users will get a link conflict error. Overwrite those files with: - #
link_overwrite "bin/foo", "lib/bar"- #
link_overwrite "share/man/man1/baz-*"+ # + # ```ruby + # link_overwrite "bin/foo", "lib/bar" + # ``` + # + # ```ruby + # link_overwrite "share/man/man1/baz-*" + # ``` def link_overwrite(*paths) paths.flatten! link_overwrite_paths.merge(paths) diff --git a/Library/Homebrew/formula_support.rb b/Library/Homebrew/formula_support.rb index 838fa97434..77c3a84056 100644 --- a/Library/Homebrew/formula_support.rb +++ b/Library/Homebrew/formula_support.rb @@ -37,7 +37,6 @@ class KegOnlyReason !by_macos? end - # @!visibility private sig { returns(String) } def to_s return @explanation unless @explanation.empty? diff --git a/Library/Homebrew/formula_text_auditor.rb b/Library/Homebrew/formula_text_auditor.rb index 052b811d0b..5600b037bf 100644 --- a/Library/Homebrew/formula_text_auditor.rb +++ b/Library/Homebrew/formula_text_auditor.rb @@ -25,7 +25,6 @@ module Homebrew @text.include? string end - # @!visibility private sig { returns(String) } def to_s @text diff --git a/Library/Homebrew/git_repository.rb b/Library/Homebrew/git_repository.rb index 2f17b2d0f6..5e03a72c1e 100644 --- a/Library/Homebrew/git_repository.rb +++ b/Library/Homebrew/git_repository.rb @@ -106,7 +106,6 @@ class GitRepository popen_git("log", "-1", "--pretty=%B", commit, "--", safe:, err: :out)&.strip end - # @!visibility private sig { returns(String) } def to_s = pathname.to_s diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index f0b8f79623..d1ab5b375a 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -48,7 +48,6 @@ class Keg EOS end - # @!visibility private sig { returns(String) } def to_s s = [] @@ -67,7 +66,6 @@ class Keg # Error for when a directory is not writable. class DirectoryNotWritableError < LinkError - # @!visibility private sig { returns(String) } def to_s <<~EOS @@ -176,11 +174,9 @@ class Keg path.parent end - # @!visibility private sig { returns(String) } def to_s = path.to_s - # @!visibility private sig { returns(String) } def inspect "#<#{self.class.name}:#{path}>" diff --git a/Library/Homebrew/language/go.rb b/Library/Homebrew/language/go.rb index f66836ae53..c5344e92b2 100644 --- a/Library/Homebrew/language/go.rb +++ b/Library/Homebrew/language/go.rb @@ -14,7 +14,7 @@ module Language # e.g. `resource "github.com/foo/bar"`. sig { params(resources: T::Array[Resource], target: T.any(String, Pathname)).void } def self.stage_deps(resources, target) - # odeprecated "Language::Go::stage_deps", "Go modules" + # odeprecated "`Language::Go.stage_deps`", "Go modules" if resources.empty? if Homebrew::EnvConfig.developer? odie "Tried to stage empty Language::Go resources array" diff --git a/Library/Homebrew/language/python.rb b/Library/Homebrew/language/python.rb index 71ef9e9bc3..8aaa4c4c0b 100644 --- a/Library/Homebrew/language/python.rb +++ b/Library/Homebrew/language/python.rb @@ -150,8 +150,8 @@ module Language # # @param venv_root [Pathname, String] the path to the root of the virtualenv # (often `libexec/"venv"`) - # @param python [String, Pathname] which interpreter to use (e.g. "python3" - # or "python3.x") + # @param python [String, Pathname] which interpreter to use (e.g. `"python3"` + # or `"python3.x"`) # @param formula [Formula] the active {Formula} # @return [Virtualenv] a {Virtualenv} instance sig { @@ -166,7 +166,7 @@ module Language def virtualenv_create(venv_root, python = "python", formula = T.cast(self, Formula), system_site_packages: true, without_pip: true) # Limit deprecation to 3.12+ for now (or if we can't determine the version). - # Some used this argument for setuptools, which we no longer bundle since 3.12. + # Some used this argument for `setuptools`, which we no longer bundle since 3.12. unless without_pip python_version = Language::Python.major_minor_version(python) if python_version.nil? || python_version.null? || python_version >= "3.12" @@ -198,8 +198,8 @@ module Language # Returns true if a formula option for the specified python is currently # active or if the specified python is required by the formula. Valid - # inputs are "python", "python2", and :python3. Note that - # "with-python", "without-python", "with-python@2", and "without-python@2" + # inputs are `"python"`, `"python2"` and `:python3`. Note that + # `"with-python"`, `"without-python"`, `"with-python@2"` and `"without-python@2"` # formula options are handled correctly even if not associated with any # corresponding depends_on statement. sig { params(python: String).returns(T::Boolean) } diff --git a/Library/Homebrew/lazy_object.rb b/Library/Homebrew/lazy_object.rb index 7f702977ee..364b10f872 100644 --- a/Library/Homebrew/lazy_object.rb +++ b/Library/Homebrew/lazy_object.rb @@ -16,15 +16,20 @@ class LazyObject < Delegator @__delegate__ = @__callable__.call # rubocop:enable Naming/MemoizedInstanceVariableName end + private :__getobj__ def __setobj__(callable) @__callable__ = callable end + private :__setobj__ # Forward to the inner object to make lazy objects type-checkable. + # + # @!visibility private def is_a?(klass) # see https://sorbet.org/docs/faq#how-can-i-fix-type-errors-that-arise-from-super T.bind(self, T.untyped) + __getobj__.is_a?(klass) || super end end diff --git a/Library/Homebrew/livecheck/strategy/extract_plist.rb b/Library/Homebrew/livecheck/strategy/extract_plist.rb index c59d848abd..ba79b24a39 100644 --- a/Library/Homebrew/livecheck/strategy/extract_plist.rb +++ b/Library/Homebrew/livecheck/strategy/extract_plist.rb @@ -39,9 +39,11 @@ module Homebrew ) do extend Forwardable + # @!attribute [r] version # @api public delegate version: :bundle_version + # @!attribute [r] short_version # @api public delegate short_version: :bundle_version end diff --git a/Library/Homebrew/livecheck/strategy/sparkle.rb b/Library/Homebrew/livecheck/strategy/sparkle.rb index c875ec4414..4bae8e669c 100644 --- a/Library/Homebrew/livecheck/strategy/sparkle.rb +++ b/Library/Homebrew/livecheck/strategy/sparkle.rb @@ -54,12 +54,15 @@ module Homebrew ) do extend Forwardable + # @!attribute [r] version # @api public delegate version: :bundle_version + # @!attribute [r] short_version # @api public delegate short_version: :bundle_version + # @!attribute [r] nice_version # @api public delegate nice_version: :bundle_version end diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb index a4c2d5e695..b6cda9a6e7 100644 --- a/Library/Homebrew/locale.rb +++ b/Library/Homebrew/locale.rb @@ -106,7 +106,6 @@ class Locale locale_groups.find { |locales| locales.any? { |locale| include?(locale) } } end - # @!visibility private sig { returns(String) } def to_s [@language, @script, @region].compact.join("-") diff --git a/Library/Homebrew/macos_version.rb b/Library/Homebrew/macos_version.rb index c03c7d46b7..a8ca466404 100644 --- a/Library/Homebrew/macos_version.rb +++ b/Library/Homebrew/macos_version.rb @@ -132,6 +132,7 @@ class MacOSVersion < Version alias requires_popcnt? requires_nehalem_cpu? # Represents the absence of a version. + # # NOTE: Constructor needs to called with an arbitrary macOS-like version which is then set to `nil`. NULL = MacOSVersion.new("10.0").tap { |v| v.instance_variable_set(:@version, nil) }.freeze end @@ -141,7 +142,7 @@ require "lazy_object" module MacOSVersionErrorCompat def const_missing(name) if name == :MacOSVersionError - odisabled "MacOSVersionError", "MacOSVersion::Error" + odisabled "`MacOSVersionError`", "`MacOSVersion::Error`" return MacOSVersion::Error end @@ -158,7 +159,7 @@ end module MacOSVersions SYMBOLS = LazyObject.new do # rubocop:disable Style/MutableConstant - odisabled "MacOSVersions::SYMBOLS", "MacOSVersion::SYMBOLS" + odisabled "`MacOSVersions::SYMBOLS`", "`MacOSVersion::SYMBOLS`" MacOSVersion::SYMBOLS end end @@ -167,7 +168,7 @@ module OS module Mac # TODO: Replace `::Version` with `Version` when this is removed. Version = LazyObject.new do # rubocop:disable Style/MutableConstant - odisabled "OS::Mac::Version", "MacOSVersion" + odisabled "`OS::Mac::Version`", "`MacOSVersion`" MacOSVersion end end diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index a5465581b3..9da558d5f9 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -287,17 +287,18 @@ class Migrator def repin return unless pinned? - # old_pin_record is a relative symlink and when we try to to read it + # `old_pin_record` is a relative symlink and when we try to to read it # from
livecheck do + # ### Example + # + # ```ruby + # livecheck do # url "https://example.com/foo/releases" # regex /foo-(\d+(?:\.\d+)+)\.tar/ - # end+ # end + # ``` + # + # @!attribute [w] livecheck def livecheck(&block) return @livecheck unless block @@ -302,7 +307,6 @@ class ResourceStageContext @staging = staging end - # @!visibility private sig { returns(String) } def to_s "<#{self.class}: resource=#{resource} staging=#{staging}>" diff --git a/Library/Homebrew/rubocops/blank.rb b/Library/Homebrew/rubocops/blank.rb index e6a22cb890..b32f1f9412 100644 --- a/Library/Homebrew/rubocops/blank.rb +++ b/Library/Homebrew/rubocops/blank.rb @@ -4,27 +4,26 @@ module RuboCop module Cop module Homebrew - # Checks for code that can be written with simpler conditionals - # using `Object#blank?`. + # Checks for code that can be simplified using `Object#blank?`. # - # @note - # This cop is unsafe autocorrection, because `' '.empty?` returns false, - # but `' '.blank?` returns true. Therefore, autocorrection is not compatible - # if the receiver is a non-empty blank string, tab, or newline meta characters. + # NOTE: Auto-correction for this cop is unsafe because `' '.empty?` returns `false`, + # but `' '.blank?` returns `true`. Therefore, auto-correction is not compatible + # if the receiver is a non-empty blank string. # - # @example - # # Converts usages of `nil? || empty?` to `blank?` + # ### Example # - # # bad - # foo.nil? || foo.empty? - # foo == nil || foo.empty? + # ```ruby + # # bad + # foo.nil? || foo.empty? + # foo == nil || foo.empty? # - # # good - # foo.blank? + # # good + # foo.blank? + # ``` class Blank < Base extend AutoCorrector - MSG_NIL_OR_EMPTY = "Use `%