Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new Style/MutableConstant RuboCop offenses for Ruby 3.1 #16346

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,9 @@ Style/InvertibleUnlessCondition:
# Don't require non-standard `exclude?` (for now at least) - it's not available in every file
:include?:

# TODO: Enable this cop again once https://github.com/Homebrew/brew/pull/16337#issuecomment-1855668516 is done.
# From the RuboCop docs: "NOTE: Regexp and Range literals are frozen objects since Ruby 3.0."
Style/MutableConstant:
Enabled: false
# would rather freeze too much than too little
EnforcedStyle: strict

# Zero-prefixed octal literals are widely used and understood.
Style/NumericLiteralPrefix:
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/PATH.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class PATH

delegate each: :@paths

# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
Element = T.type_alias { T.nilable(T.any(Pathname, String, PATH)) }
private_constant :Element
Elements = T.type_alias { T.any(Element, T::Array[Element]) }
private_constant :Elements
# rubocop:enable Style/MutableConstant

sig { params(paths: Elements).void }
def initialize(*paths)
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/cask/staged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ module Cask
#
# @api private
module Staged
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
Paths = T.type_alias { T.any(String, Pathname, T::Array[T.any(String, Pathname)]) }
# rubocop:enable Style/MutableConstant

sig { params(paths: Paths, permissions_str: String).void }
def set_permissions(paths, permissions_str)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
require "utils/gzip"
require "api"

BOTTLE_ERB = <<-EOS
BOTTLE_ERB = <<-EOS.freeze
bottle do
<% if [HOMEBREW_BOTTLE_DEFAULT_DOMAIN.to_s,
"#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}/bottles"].exclude?(root_url) %>
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/extend/blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ def present? # :nodoc:

class String
BLANK_RE = /\A[[:space:]]*\z/.freeze
# This is a cache that is intentionally mutable
# rubocop:disable Style/MutableConstant
ENCODED_BLANKS_ = T.let(Hash.new do |h, enc|
h[enc] = Regexp.new(BLANK_RE.source.encode(enc), BLANK_RE.options | Regexp::FIXEDENCODING)
end, T::Hash[Encoding, Regexp])
# rubocop:enable Style/MutableConstant

# A string is blank if it's empty or contains whitespaces only:
#
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/github_packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class GitHubPackages
include Context

URL_DOMAIN = "ghcr.io"
URL_PREFIX = "https://#{URL_DOMAIN}/v2/"
DOCKER_PREFIX = "docker://#{URL_DOMAIN}/"
URL_PREFIX = "https://#{URL_DOMAIN}/v2/".freeze
DOCKER_PREFIX = "docker://#{URL_DOMAIN}/".freeze
public_constant :URL_DOMAIN
private_constant :URL_PREFIX
private_constant :DOCKER_PREFIX
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/github_runner_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require "github_runner"

class GitHubRunnerMatrix
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
RunnerSpec = T.type_alias { T.any(LinuxRunnerSpec, MacOSRunnerSpec) }
private_constant :RunnerSpec

Expand All @@ -25,6 +27,7 @@ class GitHubRunnerMatrix

RunnerSpecHash = T.type_alias { T.any(LinuxRunnerSpecHash, MacOSRunnerSpecHash) }
private_constant :RunnerSpecHash
# rubocop:enable Style/MutableConstant

sig { returns(T::Array[GitHubRunner]) }
attr_reader :runners
Expand Down
10 changes: 5 additions & 5 deletions Library/Homebrew/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
HOMEBREW_BREWED_CURL_PATH = Pathname(ENV.fetch("HOMEBREW_BREWED_CURL_PATH")).freeze
HOMEBREW_USER_AGENT_CURL = ENV.fetch("HOMEBREW_USER_AGENT_CURL").freeze
HOMEBREW_USER_AGENT_RUBY =
"#{ENV.fetch("HOMEBREW_USER_AGENT")} ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
"#{ENV.fetch("HOMEBREW_USER_AGENT")} ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}".freeze
HOMEBREW_USER_AGENT_FAKE_SAFARI =
# Don't update this beyond 10.15.7 until Safari actually updates their
# user agent to be beyond 10.15.7 (not the case as-of macOS 14)
Expand Down Expand Up @@ -83,10 +83,10 @@
module Homebrew
extend FileUtils

DEFAULT_CELLAR = "#{DEFAULT_PREFIX}/Cellar"
DEFAULT_MACOS_CELLAR = "#{HOMEBREW_DEFAULT_PREFIX}/Cellar"
DEFAULT_MACOS_ARM_CELLAR = "#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar"
DEFAULT_LINUX_CELLAR = "#{HOMEBREW_LINUX_DEFAULT_PREFIX}/Cellar"
DEFAULT_CELLAR = "#{DEFAULT_PREFIX}/Cellar".freeze
DEFAULT_MACOS_CELLAR = "#{HOMEBREW_DEFAULT_PREFIX}/Cellar".freeze
DEFAULT_MACOS_ARM_CELLAR = "#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar".freeze
DEFAULT_LINUX_CELLAR = "#{HOMEBREW_LINUX_DEFAULT_PREFIX}/Cellar".freeze

class << self
attr_writer :failed, :raise_deprecation_exceptions, :auditing
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/macos_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class << self
end

module MacOSVersions
SYMBOLS = LazyObject.new do
SYMBOLS = LazyObject.new do # rubocop:disable Style/MutableConstant
odisabled "MacOSVersions::SYMBOLS", "MacOSVersion::SYMBOLS"
MacOSVersion::SYMBOLS
end
Expand All @@ -168,7 +168,7 @@ module MacOSVersions
module OS
module Mac
# TODO: Replace `::Version` with `Version` when this is removed.
Version = LazyObject.new do
Version = LazyObject.new do # rubocop:disable Style/MutableConstant
odisabled "OS::Mac::Version", "MacOSVersion"
MacOSVersion
end
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/test/patching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
Class.new(Formula) do
# These are defined within an anonymous class to avoid polluting the global namespace.
# rubocop:disable RSpec/LeakyConstantDeclaration,Lint/ConstantDefinitionInBlock
TESTBALL_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
TESTBALL_PATCHES_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1-patches.tgz"
PATCH_URL_A = "file://#{TEST_FIXTURE_DIR}/patches/noop-a.diff"
PATCH_URL_B = "file://#{TEST_FIXTURE_DIR}/patches/noop-b.diff"
TESTBALL_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz".freeze
TESTBALL_PATCHES_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1-patches.tgz".freeze
PATCH_URL_A = "file://#{TEST_FIXTURE_DIR}/patches/noop-a.diff".freeze
PATCH_URL_B = "file://#{TEST_FIXTURE_DIR}/patches/noop-b.diff".freeze
PATCH_A_CONTENTS = File.read("#{TEST_FIXTURE_DIR}/patches/noop-a.diff").freeze
PATCH_B_CONTENTS = File.read("#{TEST_FIXTURE_DIR}/patches/noop-b.diff").freeze
APPLY_A = "noop-a.diff"
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/github/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def pretty_ratelimit_reset(reset)
"the `(.+)` organization has an IP allow list enabled, " \
"and your IP address is not permitted to access this resource").freeze

NO_CREDENTIALS_MESSAGE = <<~MESSAGE
NO_CREDENTIALS_MESSAGE = <<~MESSAGE.freeze
No GitHub credentials found in macOS Keychain, GitHub CLI or the environment.
#{GitHub.pat_blurb}
MESSAGE
Expand Down