diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 09af8ebef8..ff2c5e3577 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1 +1 @@ -# Please fill out one of the templates on: https://github.com/Homebrew/brew/issues/new/choose or we will close it without comment. +Please fill out one of the templates on https://github.com/Homebrew/brew/issues/new/choose or we will close your issue without comment. diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 30e4f549ce..1a62b3a1cb 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -25,9 +25,22 @@ jobs: - name: Install vale run: brew install vale - - name: Run vale for docs linting - working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}/docs - run: vale . + - name: Lint docs + working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} + run: | + set -euo pipefail + + # Avoid failing on broken symlinks. + rm Library/Homebrew/os/mac/pkgconfig/fuse/fuse.pc + rm Library/Homebrew/os/mac/pkgconfig/fuse/osxfuse.pc + + # No ignore support (https://github.com/errata-ai/vale/issues/131). + rm -r Library/Homebrew/vendor + + vale . + + # Restore removed files. + git reset --hard - name: Install Ruby uses: ruby/setup-ruby@1198b074305f9356bd56dd4b311757cc0dab2f1c # v1.175.1 diff --git a/.gitignore b/.gitignore index 55a5659a84..d34dee6a00 100644 --- a/.gitignore +++ b/.gitignore @@ -107,6 +107,7 @@ **/vendor/bundle/ruby/*/gems/rainbow-*/ **/vendor/bundle/ruby/*/gems/rbi-*/ **/vendor/bundle/ruby/*/gems/rdoc-*/ +**/vendor/bundle/ruby/*/gems/redcarpet-*/ **/vendor/bundle/ruby/*/gems/regexp_parser-*/ **/vendor/bundle/ruby/*/gems/rexml-*/ **/vendor/bundle/ruby/*/gems/rspec-*/ diff --git a/.vale.ini b/.vale.ini index 8aeb075101..13f035651a 100644 --- a/.vale.ini +++ b/.vale.ini @@ -1,4 +1,7 @@ StylesPath = ./docs/vale-styles -[*.md] +[formats] +rb = md + +[*.{md,rb}] BasedOnStyles = Homebrew 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..1933a098e4 100644 --- a/Library/Homebrew/Gemfile +++ b/Library/Homebrew/Gemfile @@ -16,6 +16,7 @@ end # installed gems (should all be require: false) # ALL gems that are not vendored should be in a group group :doc, optional: true do + gem "redcarpet", require: false gem "yard", require: false gem "yard-sorbet", require: false end diff --git a/Library/Homebrew/Gemfile.lock b/Library/Homebrew/Gemfile.lock index 3102788ac6..80af1b6fd3 100644 --- a/Library/Homebrew/Gemfile.lock +++ b/Library/Homebrew/Gemfile.lock @@ -53,6 +53,7 @@ GEM rbi (0.1.12) prism (>= 0.18.0, < 0.28) sorbet-runtime (>= 0.5.9204) + redcarpet (3.6.0) regexp_parser (2.9.0) rexml (3.2.6) rspec (3.13.0) @@ -175,6 +176,7 @@ DEPENDENCIES patchelf plist pry + redcarpet rexml rspec rspec-github 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/abstract_command.rb b/Library/Homebrew/abstract_command.rb index 9d11837cc1..e24c7ae719 100644 --- a/Library/Homebrew/abstract_command.rb +++ b/Library/Homebrew/abstract_command.rb @@ -6,9 +6,10 @@ require "cli/parser" module Homebrew # Subclass this to implement a `brew` command. This is preferred to declaring a named function in the `Homebrew` # module, because: + # # - Each Command lives in an isolated namespace. # - Each Command implements a defined interface. - # - `args` is available as an ivar, and thus does not need to be passed as an argument to helper methods. + # - `args` is available as an instance method and thus does not need to be passed as an argument to helper methods. # - Subclasses no longer need to reference `CLI::Parser` or parse args explicitly. # # To subclass, implement a `run` method and provide a `cmd_args` block to document the command and its allowed args. 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_environment.rb b/Library/Homebrew/build_environment.rb index a07db8e88b..d2028f2c62 100644 --- a/Library/Homebrew/build_environment.rb +++ b/Library/Homebrew/build_environment.rb @@ -28,7 +28,7 @@ class BuildEnvironment # DSL for specifying build environment settings. module DSL # Initialise @env for each class which may use this DSL (e.g. each formula subclass). - # `env` may never be called, and it needs to be initialised before the class is frozen. + # `env` may never be called and it needs to be initialised before the class is frozen. def inherited(child) super child.instance_eval do 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/audit.rb b/Library/Homebrew/cask/audit.rb index 067e775c9c..bb3de17d02 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -685,7 +685,7 @@ module Cask sig { void } def audit_github_repository_archived - # Deprecated/disabled casks may have an archived repo. + # Deprecated/disabled casks may have an archived repository. return if cask.discontinued? || cask.deprecated? || cask.disabled? user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if online? @@ -699,7 +699,7 @@ module Cask sig { void } def audit_gitlab_repository_archived - # Deprecated/disabled casks may have an archived repo. + # Deprecated/disabled casks may have an archived repository. return if cask.discontinued? || cask.deprecated? || cask.disabled? user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*}) if online? 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 "#
ENV core documentation
+# # @see Superenv
+# # @see Stdenv
+# class ENV; end
+#
+
module EnvActivation
sig { params(env: T.nilable(String)).void }
def activate_extensions!(env: nil)
diff --git a/Library/Homebrew/extend/ENV.rbi b/Library/Homebrew/extend/ENV.rbi
index 0c7c926da8..dca2af30b3 100644
--- a/Library/Homebrew/extend/ENV.rbi
+++ b/Library/Homebrew/extend/ENV.rbi
@@ -1,5 +1,6 @@
# typed: strict
+# @!visibility private
module EnvMethods
include Kernel
@@ -39,6 +40,7 @@ module EnvActivation
include Superenv
end
+# @!visibility private
class Sorbet
module Private
module Static
diff --git a/Library/Homebrew/extend/ENV/shared.rbi b/Library/Homebrew/extend/ENV/shared.rbi
index b1eac4cd3e..1a6b66af46 100644
--- a/Library/Homebrew/extend/ENV/shared.rbi
+++ b/Library/Homebrew/extend/ENV/shared.rbi
@@ -4,6 +4,7 @@ module SharedEnvExtension
include EnvMethods
end
+# @!visibility private
class Sorbet
module Private
module Static
diff --git a/Library/Homebrew/extend/array.rb b/Library/Homebrew/extend/array.rb
index 152033304b..e68b1277a1 100644
--- a/Library/Homebrew/extend/array.rb
+++ b/Library/Homebrew/extend/array.rb
@@ -2,59 +2,72 @@
# frozen_string_literal: true
class Array
- # Equal to self[1].
+ # Equal to `self[1]`.
#
- # %w( a b c d e ).second # => "b"
+ # ### Example
+ #
+ # ```ruby
+ # %w( a b c d e ).second # => "b"
+ # ```
def second = self[1]
- # Equal to self[2].
+ # Equal to `self[2]`.
#
- # %w( a b c d e ).third # => "c"
+ # ### Example
+ #
+ # ```ruby
+ # %w( a b c d e ).third # => "c"
+ # ```
def third = self[2]
- # Equal to self[3].
+ # Equal to `self[3]`.
#
- # %w( a b c d e ).fourth # => "d"
+ # ### Example
+ #
+ # ```ruby
+ # %w( a b c d e ).fourth # => "d"
+ # ```
def fourth = self[3]
- # Equal to self[4].
+ # Equal to `self[4]`.
#
- # %w( a b c d e ).fifth # => "e"
+ # ### Example
+ #
+ # ```ruby
+ # %w( a b c d e ).fifth # => "e"
+ # ```
def fifth = self[4]
# Converts the array to a comma-separated sentence where the last element is
# joined by the connector word.
#
- # You can pass the following kwargs to change the default behavior:
+ # ### Examples
#
- # * :words_connector - The sign or word used to join all but the last
- # element in arrays with three or more elements (default: ", ").
- # * :last_word_connector - The sign or word used to join the last element
- # in arrays with three or more elements (default: ", and ").
- # * :two_words_connector - The sign or word used to join the elements
- # in arrays with two elements (default: " and ").
+ # ```ruby
+ # [].to_sentence # => ""
+ # ['one'].to_sentence # => "one"
+ # ['one', 'two'].to_sentence # => "one and two"
+ # ['one', 'two', 'three'].to_sentence # => "one, two and three"
+ # ['one', 'two'].to_sentence(two_words_connector: '-')
+ # # => "one-two"
+ # ```
#
- # ==== Examples
+ # ```
+ # ['one', 'two', 'three'].to_sentence(words_connector: ' or ', last_word_connector: ' or at least ')
+ # # => "one or two or at least three"
+ # ```
#
- # [].to_sentence # => ""
- # ['one'].to_sentence # => "one"
- # ['one', 'two'].to_sentence # => "one and two"
- # ['one', 'two', 'three'].to_sentence # => "one, two, and three"
- # ['one', 'two'].to_sentence(two_words_connector: '-')
- # # => "one-two"
- #
- # ['one', 'two', 'three'].to_sentence(words_connector: ' or ', last_word_connector: ' or at least ')
- # # => "one or two or at least three"
# @see https://github.com/rails/rails/blob/v7.0.4.2/activesupport/lib/active_support/core_ext/array/conversions.rb#L8-L84
# ActiveSupport Array#to_sentence monkey-patch
#
+ #
# Copyright (c) David Heinemeier Hansson
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
- # distribute, sublicense, and/or sell copies of the Software, and to
+ # distribute, sublicense and/or sell copies of the Software and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
@@ -68,6 +81,14 @@ class Array
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ #
+ #
+ # @param [String] words_connector The sign or word used to join all but the last
+ # element in arrays with three or more elements (default: `", "`).
+ # @param [String] last_word_connector The sign or word used to join the last element
+ # in arrays with three or more elements (default: `" and "`).
+ # @param [String] two_words_connector The sign or word used to join the elements
+ # in arrays with two elements (default: `" and "`).
sig { params(words_connector: String, two_words_connector: String, last_word_connector: String).returns(String) }
def to_sentence(words_connector: ", ", two_words_connector: " and ", last_word_connector: " and ")
case length
diff --git a/Library/Homebrew/extend/blank.rb b/Library/Homebrew/extend/blank.rb
index 9eb738e69d..85c5ea55b4 100644
--- a/Library/Homebrew/extend/blank.rb
+++ b/Library/Homebrew/extend/blank.rb
@@ -3,15 +3,20 @@
class Object
# An object is blank if it's false, empty, or a whitespace string.
- # For example, +nil+, '', ' ', [], {}, and +false+ are all blank.
#
- # This simplifies
+ # For example, `nil`, `''`, `' '`, `[]`, `{}` and `false` are all blank.
#
- # !address || address.empty?
+ # ### Example
#
- # to
+ # ```ruby
+ # !address || address.empty?
+ # ```
#
- # address.blank?
+ # can be simplified to
+ #
+ # ```ruby
+ # address.blank?
+ # ```
sig { returns(T::Boolean) }
def blank?
respond_to?(:empty?) ? !!T.unsafe(self).empty? : false
@@ -21,20 +26,23 @@ class Object
sig { returns(T::Boolean) }
def present? = !blank?
- # Returns the receiver if it's present otherwise returns +nil+.
- # object.presence is equivalent to
+ # Returns the receiver if it's present, otherwise returns `nil`.
#
- # object.present? ? object : nil
+ # `object.presence` is equivalent to `object.present? ? object : nil`.
#
- # For example, something like
+ # ### Example
#
- # state = params[:state] if params[:state].present?
- # country = params[:country] if params[:country].present?
- # region = state || country || 'US'
+ # ```ruby
+ # state = params[:state] if params[:state].present?
+ # country = params[:country] if params[:country].present?
+ # region = state || country || 'US'
+ # ```
#
- # becomes
+ # can be simplified to
#
- # region = params[:state].presence || params[:country].presence || 'US'
+ # ```ruby
+ # region = params[:state].presence || params[:country].presence || 'US'
+ # ```
sig { returns(T.nilable(T.self_type)) }
def presence
self if present?
@@ -42,9 +50,11 @@ class Object
end
class NilClass
- # +nil+ is blank:
+ # `nil` is blank:
#
- # nil.blank? # => true
+ # ```ruby
+ # nil.blank? # => true
+ # ```
sig { returns(TrueClass) }
def blank? = true
@@ -53,9 +63,11 @@ class NilClass
end
class FalseClass
- # +false+ is blank:
+ # `false` is blank:
#
- # false.blank? # => true
+ # ```ruby
+ # false.blank? # => true
+ # ```
sig { returns(TrueClass) }
def blank? = true
@@ -64,9 +76,11 @@ class FalseClass
end
class TrueClass
- # +true+ is not blank:
+ # `true` is not blank:
#
- # true.blank? # => false
+ # ```ruby
+ # true.blank? # => false
+ # ```
sig { returns(FalseClass) }
def blank? = false
@@ -77,11 +91,12 @@ end
class Array
# An array is blank if it's empty:
#
- # [].blank? # => true
- # [1,2,3].blank? # => false
- #
- # @return [true, false]
- alias blank? empty?
+ # ```ruby
+ # [].blank? # => true
+ # [1,2,3].blank? # => false
+ # ```
+ sig { returns(T::Boolean) }
+ def blank? = empty?
sig { returns(T::Boolean) }
def present? = !empty? # :nodoc:
@@ -90,11 +105,13 @@ end
class Hash
# A hash is blank if it's empty:
#
- # {}.blank? # => true
- # { key: 'value' }.blank? # => false
#
- # @return [true, false]
- alias blank? empty?
+ # ```ruby
+ # {}.blank? # => true
+ # { key: 'value' }.blank? # => false
+ # ```
+ sig { returns(T::Boolean) }
+ def blank? = empty?
sig { returns(T::Boolean) }
def present? = !empty? # :nodoc:
@@ -103,9 +120,12 @@ end
class Symbol
# A Symbol is blank if it's empty:
#
- # :''.blank? # => true
- # :symbol.blank? # => false
- alias blank? empty?
+ # ```ruby
+ # :''.blank? # => true
+ # :symbol.blank? # => false
+ # ```
+ sig { returns(T::Boolean) }
+ def blank? = empty?
sig { returns(T::Boolean) }
def present? = !empty? # :nodoc:
@@ -122,14 +142,18 @@ class String
# A string is blank if it's empty or contains whitespaces only:
#
- # ''.blank? # => true
- # ' '.blank? # => true
- # "\t\n\r".blank? # => true
- # ' blah '.blank? # => false
+ # ```ruby
+ # ''.blank? # => true
+ # ' '.blank? # => true
+ # "\t\n\r".blank? # => true
+ # ' blah '.blank? # => false
+ # ```
#
# Unicode whitespace is supported:
#
- # "\u00a0".blank? # => true
+ # ```ruby
+ # "\u00a0".blank? # => true
+ # ```
sig { returns(T::Boolean) }
def blank?
# The regexp that matches blank strings is expensive. For the case of empty
@@ -150,8 +174,10 @@ end
class Numeric # :nodoc:
# No number is blank:
#
- # 1.blank? # => false
- # 0.blank? # => false
+ # ```ruby
+ # 1.blank? # => false
+ # 0.blank? # => false
+ # ```
sig { returns(FalseClass) }
def blank? = false
@@ -162,7 +188,9 @@ end
class Time # :nodoc:
# No Time is blank:
#
- # Time.now.blank? # => false
+ # ```ruby
+ # Time.now.blank? # => false
+ # ```
sig { returns(FalseClass) }
def blank? = false
diff --git a/Library/Homebrew/extend/enumerable.rb b/Library/Homebrew/extend/enumerable.rb
index 77b499b2dd..5f8ca22f17 100644
--- a/Library/Homebrew/extend/enumerable.rb
+++ b/Library/Homebrew/extend/enumerable.rb
@@ -2,7 +2,7 @@
# frozen_string_literal: true
module Enumerable
- # The negative of the Enumerable#include?. Returns +true+ if the
+ # The negative of the {Enumerable#include?}. Returns `true` if the
# collection does not include the object.
sig { params(object: T.untyped).returns(T::Boolean) }
def exclude?(object) = !include?(object)
@@ -10,21 +10,29 @@ module Enumerable
# Returns a new +Array+ without the blank items.
# Uses Object#blank? for determining if an item is blank.
#
- # [1, "", nil, 2, " ", [], {}, false, true].compact_blank
- # # => [1, 2, true]
+ # ### Examples
#
- # Set.new([nil, "", 1, false]).compact_blank
- # # => [1]
+ # ```
+ # [1, "", nil, 2, " ", [], {}, false, true].compact_blank
+ # # => [1, 2, true]
+ # ```
#
- # When called on a +Hash+, returns a new +Hash+ without the blank values.
+ # ```ruby
+ # Set.new([nil, "", 1, false]).compact_blank
+ # # => [1]
+ # ```
#
- # { a: "", b: 1, c: nil, d: [], e: false, f: true }.compact_blank
- # # => { b: 1, f: true }
+ # When called on a {Hash}, returns a new {Hash} without the blank values.
+ #
+ # ```ruby
+ # { a: "", b: 1, c: nil, d: [], e: false, f: true }.compact_blank
+ # # => { b: 1, f: true }
+ # ```
sig { returns(T.self_type) }
def compact_blank = T.unsafe(self).reject(&:blank?)
end
class Hash
- # Hash#reject has its own definition, so this needs one too.
+ # {Hash#reject} has its own definition, so this needs one too.
def compact_blank = reject { |_k, v| T.unsafe(v).blank? }
end
diff --git a/Library/Homebrew/extend/hash/deep_merge.rb b/Library/Homebrew/extend/hash/deep_merge.rb
index 01ecbe9260..527e36076b 100644
--- a/Library/Homebrew/extend/hash/deep_merge.rb
+++ b/Library/Homebrew/extend/hash/deep_merge.rb
@@ -2,25 +2,31 @@
# frozen_string_literal: true
class Hash
- # Returns a new hash with +self+ and +other_hash+ merged recursively.
+ # Returns a new hash with `self` and `other_hash` merged recursively.
#
- # h1 = { a: true, b: { c: [1, 2, 3] } }
- # h2 = { a: false, b: { x: [3, 4, 5] } }
+ # ### Examples
#
- # h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
+ # ```ruby
+ # h1 = { a: true, b: { c: [1, 2, 3] } }
+ # h2 = { a: false, b: { x: [3, 4, 5] } }
+ #
+ # h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
+ # ```
#
# Like with Hash#merge in the standard library, a block can be provided
# to merge values:
#
- # h1 = { a: 100, b: 200, c: { c1: 100 } }
- # h2 = { b: 250, c: { c1: 200 } }
- # h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
- # # => { a: 100, b: 450, c: { c1: 300 } }
+ # ```ruby
+ # h1 = { a: 100, b: 200, c: { c1: 100 } }
+ # h2 = { b: 250, c: { c1: 200 } }
+ # h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
+ # # => { a: 100, b: 450, c: { c1: 300 } }
+ # ```
def deep_merge(other_hash, &block)
dup.deep_merge!(other_hash, &block)
end
- # Same as +deep_merge+, but modifies +self+.
+ # Same as {#deep_merge}, but modifies `self`.
def deep_merge!(other_hash, &block)
merge!(other_hash) do |key, this_val, other_val|
if T.unsafe(this_val).is_a?(Hash) && other_val.is_a?(Hash)
diff --git a/Library/Homebrew/extend/hash/deep_transform_values.rb b/Library/Homebrew/extend/hash/deep_transform_values.rb
index 2787efc1f6..be366f1b14 100644
--- a/Library/Homebrew/extend/hash/deep_transform_values.rb
+++ b/Library/Homebrew/extend/hash/deep_transform_values.rb
@@ -6,11 +6,14 @@ class Hash
# This includes the values from the root hash and from all
# nested hashes and arrays.
#
- # @example
- # hash = { person: { name: 'Rob', age: '28' } }
+ # ### Example
#
- # hash.deep_transform_values{ |value| value.to_s.upcase }
- # # => {person: {name: "ROB", age: "28"}}
+ # ```ruby
+ # hash = { person: { name: 'Rob', age: '28' } }
+ #
+ # hash.deep_transform_values{ |value| value.to_s.upcase }
+ # # => {person: {name: "ROB", age: "28"}}
+ # ```
def deep_transform_values(&block) = _deep_transform_values_in_object(self, &block)
# Destructively converts all values by using the block operation.
diff --git a/Library/Homebrew/extend/hash/keys.rb b/Library/Homebrew/extend/hash/keys.rb
index 06878a4ce0..fc0cbfbe59 100644
--- a/Library/Homebrew/extend/hash/keys.rb
+++ b/Library/Homebrew/extend/hash/keys.rb
@@ -5,14 +5,18 @@ class Hash
# Validates all keys in a hash match `*valid_keys`, raising
# `ArgumentError` on a mismatch.
#
- # Note that keys are treated differently than HashWithIndifferentAccess,
+ # Note that keys are treated differently than `HashWithIndifferentAccess`,
# meaning that string and symbol keys will not match.
#
- # { name: 'Rob', years: '28' }.assert_valid_keys(:name, :age)
- # # => raises "ArgumentError: Unknown key: :years. Valid keys are: :name, :age"
- # { name: 'Rob', age: '28' }.assert_valid_keys('name', 'age')
- # # => raises "ArgumentError: Unknown key: :name. Valid keys are: 'name', 'age'"
- # { name: 'Rob', age: '28' }.assert_valid_keys(:name, :age) # => passes, raises nothing
+ # ### Example#
+ #
+ # ```ruby
+ # { name: 'Rob', years: '28' }.assert_valid_keys(:name, :age)
+ # # => raises "ArgumentError: Unknown key: :years. Valid keys are: :name, :age"
+ # { name: 'Rob', age: '28' }.assert_valid_keys('name', 'age')
+ # # => raises "ArgumentError: Unknown key: :name. Valid keys are: 'name', 'age'"
+ # { name: 'Rob', age: '28' }.assert_valid_keys(:name, :age) # => passes, raises nothing
+ # ```
sig { params(valid_keys: T.untyped).void }
def assert_valid_keys(*valid_keys)
valid_keys.flatten!
@@ -28,10 +32,14 @@ class Hash
# This includes the keys from the root hash and from all
# nested hashes and arrays.
#
- # hash = { person: { name: 'Rob', age: '28' } }
+ # ### Example
#
- # hash.deep_transform_keys{ |key| key.to_s.upcase }
- # # => {"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}}
+ # ```ruby
+ # hash = { person: { name: 'Rob', age: '28' } }
+ #
+ # hash.deep_transform_keys{ |key| key.to_s.upcase }
+ # # => {"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}}
+ # ```
def deep_transform_keys(&block) = _deep_transform_keys_in_object(self, &block)
# Destructively converts all keys by using the block operation.
@@ -43,10 +51,14 @@ class Hash
# This includes the keys from the root hash and from all
# nested hashes and arrays.
#
- # hash = { person: { name: 'Rob', age: '28' } }
+ # ### Example
#
- # hash.deep_stringify_keys
- # # => {"person"=>{"name"=>"Rob", "age"=>"28"}}
+ # ```ruby
+ # hash = { person: { name: 'Rob', age: '28' } }
+ #
+ # hash.deep_stringify_keys
+ # # => {"person"=>{"name"=>"Rob", "age"=>"28"}}
+ # ```
def deep_stringify_keys = T.unsafe(self).deep_transform_keys(&:to_s)
# Destructively converts all keys to strings.
@@ -55,13 +67,17 @@ class Hash
def deep_stringify_keys! = T.unsafe(self).deep_transform_keys!(&:to_s)
# Returns a new hash with all keys converted to symbols, as long as
- # they respond to +to_sym+. This includes the keys from the root hash
+ # they respond to `to_sym`. This includes the keys from the root hash
# and from all nested hashes and arrays.
#
- # hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
+ # ### Example
#
- # hash.deep_symbolize_keys
- # # => {:person=>{:name=>"Rob", :age=>"28"}}
+ # ```ruby
+ # hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
+ #
+ # hash.deep_symbolize_keys
+ # # => {:person=>{:name=>"Rob", :age=>"28"}}
+ # ```
def deep_symbolize_keys
deep_transform_keys do |key|
T.unsafe(key).to_sym
@@ -71,7 +87,7 @@ class Hash
end
# Destructively converts all keys to symbols, as long as they respond
- # to +to_sym+. This includes the keys from the root hash and from all
+ # to `to_sym`. This includes the keys from the root hash and from all
# nested hashes and arrays.
def deep_symbolize_keys!
deep_transform_keys! do |key|
@@ -102,7 +118,7 @@ class Hash
def _deep_transform_keys_in_object!(object, &block)
case object
when Hash
- # We can't use `each_key` here because we're updating the hash in-place
+ # We can't use `each_key` here because we're updating the hash in-place.
object.keys.each do |key| # rubocop:disable Style/HashEachMethods
value = object.delete(key)
object[yield(key)] = _deep_transform_keys_in_object!(value, &block)
diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb
index d9f0f2aa6f..8696c5cc6b 100644
--- a/Library/Homebrew/extend/kernel.rb
+++ b/Library/Homebrew/extend/kernel.rb
@@ -493,14 +493,20 @@ module Kernel
end
# Calls the given block with the passed environment variables
- # added to ENV, then restores ENV afterwards.
- # 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/install.rb b/Library/Homebrew/extend/os/linux/install.rb index 943ae7bea9..e4476a00b8 100644 --- a/Library/Homebrew/extend/os/linux/install.rb +++ b/Library/Homebrew/extend/os/linux/install.rb @@ -4,7 +4,7 @@ module Homebrew module Install # This is a list of known paths to the host dynamic linker on Linux if - # the host glibc is new enough. The symlink_ld_so method will fail if + # the host glibc is new enough. The symlink_ld_so method will fail if # the host linker cannot be found in this list. DYNAMIC_LINKERS = %w[ /lib64/ld-linux-x86-64.so.2 @@ -19,7 +19,7 @@ module Homebrew private_constant :DYNAMIC_LINKERS # We link GCC runtime libraries that are not specifically used for Fortran, - # which are linked by the GCC formula. We only use the versioned shared libraries + # which are linked by the GCC formula. We only use the versioned shared libraries # as the other shared and static libraries are only used at build time where # GCC can find its own libraries. GCC_RUNTIME_LIBS = %w[ 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/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index 98774d3a92..6733fc0b34 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -340,7 +340,7 @@ module Homebrew else inject_file_list @found, <<~EOS libiconv files detected at a system prefix other than /usr. - Homebrew doesn't provide a libiconv formula, and expects to link against + Homebrew doesn't provide a libiconv formula and expects to link against the system version in /usr. libiconv in other prefixes can cause compile or link failure, especially if compiled with improper architectures. macOS itself never installs anything to /usr/local so 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/formula_cellar_checks.rb b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb index e4ffde8f9f..e7188e670b 100644 --- a/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb +++ b/Library/Homebrew/extend/os/mac/formula_cellar_checks.rb @@ -112,7 +112,7 @@ module FormulaCellarChecks <<~EOS Libraries were compiled with a flat namespace. - This can cause linker errors due to name collisions, and + This can cause linker errors due to name collisions and is often due to a bug in detecting the macOS version. #{flat_namespace_files * "\n "} EOS 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/fetch.rb b/Library/Homebrew/fetch.rb index 587a17f4ed..9bbd8047e9 100644 --- a/Library/Homebrew/fetch.rb +++ b/Library/Homebrew/fetch.rb @@ -20,7 +20,7 @@ module Homebrew if os.present? return true elsif ENV["HOMEBREW_TEST_GENERIC_OS"].present? - # `:generic` bottles don't exist, and `--os` flag is not specified. + # `:generic` bottles don't exist and `--os` flag is not specified. return false end return true if arch.present? 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_assertions.rb b/Library/Homebrew/formula_assertions.rb index ad9c7ebcc7..a7d6d0dd77 100644 --- a/Library/Homebrew/formula_assertions.rb +++ b/Library/Homebrew/formula_assertions.rb @@ -16,7 +16,8 @@ module Homebrew @assertions ||= 0 end - # Returns the output of running cmd, and asserts the exit status. + # Returns the output of running cmd and asserts the exit status. + # # @api public def shell_output(cmd, result = 0) ohai cmd @@ -28,8 +29,9 @@ module Homebrew raise end - # Returns the output of running the cmd with the optional input, and + # Returns the output of running the cmd with the optional input and # optionally asserts the exit status. + # # @api public def pipe_output(cmd, input = nil, result = nil) ohai cmd diff --git a/Library/Homebrew/formula_creator.rb b/Library/Homebrew/formula_creator.rb index da833cf4eb..8f362a82f9 100644 --- a/Library/Homebrew/formula_creator.rb +++ b/Library/Homebrew/formula_creator.rb @@ -99,6 +99,8 @@ module Homebrew sig { returns(String) } def template + # FIXME: https://github.com/errata-ai/vale/issues/818 + # <<~ERB # Documentation: https://docs.brew.sh/Formula-Cookbook # https://rubydoc.brew.sh/Formula @@ -183,14 +185,14 @@ module Homebrew ENV.prepend_create_path "PERL5LIB", libexec/"lib/perl5" ENV.prepend_path "PERL5LIB", libexec/"lib" - # Stage additional dependency (Makefile.PL style) + # Stage additional dependency (`Makefile.PL` style). # resource("").stage do # system "perl", "Makefile.PL", "INSTALL_BASE=\#{libexec}" # system "make" # system "make", "install" # end - # Stage additional dependency (Build.PL style) + # Stage additional dependency (`Build.PL` style). # resource("").stage do # system "perl", "Build.PL", "--install_base", libexec # system "./Build" @@ -231,6 +233,7 @@ module Homebrew end end ERB + # end end end 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/formulary.rb b/Library/Homebrew/formulary.rb index dada7f3b0b..c479ddacdf 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -537,19 +537,19 @@ module Formulary class FormulaLoader include Context - # The formula's name + # The formula's name. sig { returns(String) } attr_reader :name - # The formula's ruby file's path or filename + # The formula file's path. sig { returns(Pathname) } attr_reader :path - # The name used to install the formula + # The name used to install the formula. sig { returns(T.nilable(Pathname)) } attr_reader :alias_path - # The formula's tap (nil if it should be implicitly determined) + # The formula's tap (`nil` if it should be implicitly determined). sig { returns(T.nilable(Tap)) } attr_reader :tap @@ -1019,8 +1019,8 @@ module Formulary # Return a {Formula} instance for the given rack. # # @param spec when nil, will auto resolve the formula's spec. - # @param :alias_path will be used if the formula is found not to be - # installed, and discarded if it is installed because the `alias_path` used + # @param alias_path will be used if the formula is found not to be + # installed and discarded if it is installed because the `alias_path` used # to install the formula will be set instead. sig { params( 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/github_packages.rb b/Library/Homebrew/github_packages.rb index 68f2f244ad..64aa192cc1 100644 --- a/Library/Homebrew/github_packages.rb +++ b/Library/Homebrew/github_packages.rb @@ -94,12 +94,12 @@ class GitHubPackages end def self.repo_without_prefix(repo) - # remove redundant repo prefix for a shorter name + # Remove redundant repository prefix for a shorter name. repo.delete_prefix("homebrew-") end def self.root_url(org, repo, prefix = URL_PREFIX) - # docker/skopeo insist on lowercase org ("repository name") + # `docker`/`skopeo` insist on lowercase organisation (“repository name”). org = org.downcase "#{prefix}#{org}/#{repo_without_prefix(repo)}" @@ -115,9 +115,9 @@ class GitHubPackages end def self.image_formula_name(formula_name) - # invalid docker name characters - # / makes sense because we already use it to separate repo/formula - # x makes sense because we already use it in Formulary + # Invalid docker name characters: + # - `/` makes sense because we already use it to separate repository/formula. + # - `x` makes sense because we already use it in `Formulary`. formula_name.tr("@", "/") .tr("+", "x") end @@ -231,9 +231,9 @@ class GitHubPackages inspect_args << "--creds=#{user}:#{token}" inspect_result = system_command(skopeo, print_stderr: false, args: inspect_args) - # Order here is important + # Order here is important. if !inspect_result.status.success? && !inspect_result.stderr.match?(/(name|manifest) unknown/) - # We got an error, and it was not about the tag or package being unknown. + # We got an error and it was not about the tag or package being unknown. if warn_on_error opoo "#{image_uri} inspection returned an error, skipping upload!\n#{inspect_result.stderr}" return @@ -241,11 +241,11 @@ class GitHubPackages odie "#{image_uri} inspection returned an error!\n#{inspect_result.stderr}" end elsif keep_old - # If the tag doesn't exist, ignore --keep-old. + # If the tag doesn't exist, ignore `--keep-old`. keep_old = false unless inspect_result.status.success? # Otherwise, do nothing - the tag already existing is expected behaviour for --keep-old. elsif inspect_result.status.success? - # The tag already exists, and we are not passing --keep-old. + # The tag already exists and we are not passing `--keep-old`. if warn_on_error opoo "#{image_uri} already exists, skipping upload!" return diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index f0b8f79623..e418ce9d48 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}>" @@ -556,8 +552,8 @@ class Keg src = dst.resolved_path - # src itself may be a symlink, so check lstat to ensure we are dealing with - # a directory, and not a symlink pointing at a directory (which needs to be + # `src` itself may be a symlink, so check lstat to ensure we are dealing with + # a directory and not a symlink pointing to a directory (which needs to be # treated as a file). In other words, we only want to resolve one symlink. begin 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..a8006ac5ea 100644 --- a/Library/Homebrew/language/python.rb +++ b/Library/Homebrew/language/python.rb @@ -144,14 +144,14 @@ module Language # Mixin module for {Formula} adding virtualenv support features. module Virtualenv - # Instantiates, creates, and yields a {Virtualenv} object for use from + # Instantiates, creates and yields a {Virtualenv} object for use from # {Formula#install}, which provides helper methods for instantiating and # installing packages into a Python virtualenv. # # @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) } @@ -211,7 +211,7 @@ module Language # Helper method for the common case of installing a Python application. # Creates a virtualenv in `libexec`, installs all `resource`s defined - # on the formula, and then installs the formula. An options hash may be + # on the formula and then installs the formula. An options hash may be # passed (e.g. `:using => "python"`) to override the default, guessed # formula preference for python or python@x.y, or to resolve an ambiguous # case where it's not clear whether python or python@x.y should be the 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/git.rb b/Library/Homebrew/livecheck/strategy/git.rb index 7b5eeee405..ad9ce2526a 100644 --- a/Library/Homebrew/livecheck/strategy/git.rb +++ b/Library/Homebrew/livecheck/strategy/git.rb @@ -13,7 +13,7 @@ module Homebrew # Livecheck has historically prioritized the {Git} strategy over others # and this behavior was continued when the priority setup was created. # This is partly related to Livecheck checking formula URLs in order of - # `head`, `stable`, and then `homepage`. The higher priority here may + # `head`, `stable` and then `homepage`. The higher priority here may # be removed (or altered) in the future if we reevaluate this particular # behavior. # diff --git a/Library/Homebrew/livecheck/strategy/json.rb b/Library/Homebrew/livecheck/strategy/json.rb index b27e990bdf..ce0b8f5cc0 100644 --- a/Library/Homebrew/livecheck/strategy/json.rb +++ b/Library/Homebrew/livecheck/strategy/json.rb @@ -4,7 +4,7 @@ module Homebrew module Livecheck module Strategy - # The {Json} strategy fetches content at a URL, parses it as JSON, and + # The {Json} strategy fetches content at a URL, parses it as JSON and # provides the parsed data to a `strategy` block. If a regex is present # in the `livecheck` block, it should be passed as the second argument to # the `strategy` block. 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/livecheck/strategy/xml.rb b/Library/Homebrew/livecheck/strategy/xml.rb index 26c2e874d3..362f373971 100644 --- a/Library/Homebrew/livecheck/strategy/xml.rb +++ b/Library/Homebrew/livecheck/strategy/xml.rb @@ -5,7 +5,7 @@ module Homebrew module Livecheck module Strategy # The {Xml} strategy fetches content at a URL, parses it as XML using - # `REXML`, and provides the `REXML::Document` to a `strategy` block. + # `REXML` and provides the `REXML::Document` to a `strategy` block. # If a regex is present in the `livecheck` block, it should be passed # as the second argument to the `strategy` block. # diff --git a/Library/Homebrew/livecheck/strategy/yaml.rb b/Library/Homebrew/livecheck/strategy/yaml.rb index 60e2290df3..407a8548b7 100644 --- a/Library/Homebrew/livecheck/strategy/yaml.rb +++ b/Library/Homebrew/livecheck/strategy/yaml.rb @@ -4,7 +4,7 @@ module Homebrew module Livecheck module Strategy - # The {Yaml} strategy fetches content at a URL, parses it as YAML, and + # The {Yaml} strategy fetches content at a URL, parses it as YAML and # provides the parsed data to a `strategy` block. If a regex is present # in the `livecheck` block, it should be passed as the second argument to # the `strategy` block. 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/manpages.rb b/Library/Homebrew/manpages.rb index 1d5c3e40c3..6b90a1c186 100644 --- a/Library/Homebrew/manpages.rb +++ b/Library/Homebrew/manpages.rb @@ -142,7 +142,7 @@ module Homebrew sig { returns(String) } def self.global_cask_options_manpage - lines = ["These options are applicable to the `install`, `reinstall`, and `upgrade` " \ + lines = ["These options are applicable to the `install`, `reinstall` and `upgrade` " \ "subcommands with the `--cask` switch.\n"] lines += Homebrew::CLI::Parser.global_cask_options.map do |_, long, kwargs| generate_option_doc(nil, long.chomp("="), kwargs.fetch(:description)) 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 @@ -165,8 +170,8 @@ class Resource < Downloadable end # Whether a livecheck specification is defined or not. - # It returns true when a livecheck block is present in the {Resource} and - # false otherwise, and is used by livecheck. + # It returns true when a `livecheck` block is present in the {Resource} and + # false otherwise and is used by livecheck. def livecheckable? @livecheckable == true end @@ -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 `%