Fix new Style/MutableConstant RuboCop offenses for Ruby 3.1

- A follow-up to de592af20bbff5bcb548d2474f0722e59ff1129a, resetting the previous disabled comments too.
This commit is contained in:
Issy Long 2023-12-16 11:47:46 +00:00
parent 29d1be9e9a
commit 149b0e4f31
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
11 changed files with 29 additions and 18 deletions

View File

@ -386,10 +386,9 @@ Style/InvertibleUnlessCondition:
# Don't require non-standard `exclude?` (for now at least) - it's not available in every file # Don't require non-standard `exclude?` (for now at least) - it's not available in every file
:include?: :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: Style/MutableConstant:
Enabled: false # would rather freeze too much than too little
EnforcedStyle: strict
# Zero-prefixed octal literals are widely used and understood. # Zero-prefixed octal literals are widely used and understood.
Style/NumericLiteralPrefix: Style/NumericLiteralPrefix:

View File

@ -10,10 +10,13 @@ class PATH
delegate each: :@paths 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)) } Element = T.type_alias { T.nilable(T.any(Pathname, String, PATH)) }
private_constant :Element private_constant :Element
Elements = T.type_alias { T.any(Element, T::Array[Element]) } Elements = T.type_alias { T.any(Element, T::Array[Element]) }
private_constant :Elements private_constant :Elements
# rubocop:enable Style/MutableConstant
sig { params(paths: Elements).void } sig { params(paths: Elements).void }
def initialize(*paths) def initialize(*paths)

View File

@ -8,7 +8,10 @@ module Cask
# #
# @api private # @api private
module Staged 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)]) } 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 } sig { params(paths: Paths, permissions_str: String).void }
def set_permissions(paths, permissions_str) def set_permissions(paths, permissions_str)

View File

@ -12,7 +12,7 @@ require "erb"
require "utils/gzip" require "utils/gzip"
require "api" require "api"
BOTTLE_ERB = <<-EOS BOTTLE_ERB = <<-EOS.freeze
bottle do bottle do
<% if [HOMEBREW_BOTTLE_DEFAULT_DOMAIN.to_s, <% if [HOMEBREW_BOTTLE_DEFAULT_DOMAIN.to_s,
"#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}/bottles"].exclude?(root_url) %> "#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}/bottles"].exclude?(root_url) %>

View File

@ -133,9 +133,12 @@ end
class String class String
BLANK_RE = /\A[[:space:]]*\z/.freeze 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| ENCODED_BLANKS_ = T.let(Hash.new do |h, enc|
h[enc] = Regexp.new(BLANK_RE.source.encode(enc), BLANK_RE.options | Regexp::FIXEDENCODING) h[enc] = Regexp.new(BLANK_RE.source.encode(enc), BLANK_RE.options | Regexp::FIXEDENCODING)
end, T::Hash[Encoding, Regexp]) end, T::Hash[Encoding, Regexp])
# rubocop:enable Style/MutableConstant
# A string is blank if it's empty or contains whitespaces only: # A string is blank if it's empty or contains whitespaces only:
# #

View File

@ -12,8 +12,8 @@ class GitHubPackages
include Context include Context
URL_DOMAIN = "ghcr.io" URL_DOMAIN = "ghcr.io"
URL_PREFIX = "https://#{URL_DOMAIN}/v2/" URL_PREFIX = "https://#{URL_DOMAIN}/v2/".freeze
DOCKER_PREFIX = "docker://#{URL_DOMAIN}/" DOCKER_PREFIX = "docker://#{URL_DOMAIN}/".freeze
public_constant :URL_DOMAIN public_constant :URL_DOMAIN
private_constant :URL_PREFIX private_constant :URL_PREFIX
private_constant :DOCKER_PREFIX private_constant :DOCKER_PREFIX

View File

@ -5,6 +5,8 @@ require "test_runner_formula"
require "github_runner" require "github_runner"
class GitHubRunnerMatrix 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) } RunnerSpec = T.type_alias { T.any(LinuxRunnerSpec, MacOSRunnerSpec) }
private_constant :RunnerSpec private_constant :RunnerSpec
@ -25,6 +27,7 @@ class GitHubRunnerMatrix
RunnerSpecHash = T.type_alias { T.any(LinuxRunnerSpecHash, MacOSRunnerSpecHash) } RunnerSpecHash = T.type_alias { T.any(LinuxRunnerSpecHash, MacOSRunnerSpecHash) }
private_constant :RunnerSpecHash private_constant :RunnerSpecHash
# rubocop:enable Style/MutableConstant
sig { returns(T::Array[GitHubRunner]) } sig { returns(T::Array[GitHubRunner]) }
attr_reader :runners attr_reader :runners

View File

@ -42,7 +42,7 @@ HOMEBREW_PHYSICAL_PROCESSOR = ENV.fetch("HOMEBREW_PHYSICAL_PROCESSOR").freeze
HOMEBREW_BREWED_CURL_PATH = Pathname(ENV.fetch("HOMEBREW_BREWED_CURL_PATH")).freeze 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_CURL = ENV.fetch("HOMEBREW_USER_AGENT_CURL").freeze
HOMEBREW_USER_AGENT_RUBY = 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 = HOMEBREW_USER_AGENT_FAKE_SAFARI =
# Don't update this beyond 10.15.7 until Safari actually updates their # 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) # user agent to be beyond 10.15.7 (not the case as-of macOS 14)
@ -83,10 +83,10 @@ require "default_prefix"
module Homebrew module Homebrew
extend FileUtils extend FileUtils
DEFAULT_CELLAR = "#{DEFAULT_PREFIX}/Cellar" DEFAULT_CELLAR = "#{DEFAULT_PREFIX}/Cellar".freeze
DEFAULT_MACOS_CELLAR = "#{HOMEBREW_DEFAULT_PREFIX}/Cellar" DEFAULT_MACOS_CELLAR = "#{HOMEBREW_DEFAULT_PREFIX}/Cellar".freeze
DEFAULT_MACOS_ARM_CELLAR = "#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar" DEFAULT_MACOS_ARM_CELLAR = "#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar".freeze
DEFAULT_LINUX_CELLAR = "#{HOMEBREW_LINUX_DEFAULT_PREFIX}/Cellar" DEFAULT_LINUX_CELLAR = "#{HOMEBREW_LINUX_DEFAULT_PREFIX}/Cellar".freeze
class << self class << self
attr_writer :failed, :raise_deprecation_exceptions, :auditing attr_writer :failed, :raise_deprecation_exceptions, :auditing

View File

@ -159,7 +159,7 @@ class Object
end end
module MacOSVersions module MacOSVersions
SYMBOLS = LazyObject.new do SYMBOLS = LazyObject.new do # rubocop:disable Style/MutableConstant
odisabled "MacOSVersions::SYMBOLS", "MacOSVersion::SYMBOLS" odisabled "MacOSVersions::SYMBOLS", "MacOSVersion::SYMBOLS"
MacOSVersion::SYMBOLS MacOSVersion::SYMBOLS
end end
@ -168,7 +168,7 @@ end
module OS module OS
module Mac module Mac
# TODO: Replace `::Version` with `Version` when this is removed. # 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" odisabled "OS::Mac::Version", "MacOSVersion"
MacOSVersion MacOSVersion
end end

View File

@ -7,10 +7,10 @@ describe "patching" do
Class.new(Formula) do Class.new(Formula) do
# These are defined within an anonymous class to avoid polluting the global namespace. # These are defined within an anonymous class to avoid polluting the global namespace.
# rubocop:disable RSpec/LeakyConstantDeclaration,Lint/ConstantDefinitionInBlock # rubocop:disable RSpec/LeakyConstantDeclaration,Lint/ConstantDefinitionInBlock
TESTBALL_URL = "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" 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" 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" PATCH_URL_A = "file://#{TEST_FIXTURE_DIR}/patches/noop-a.diff".freeze
PATCH_URL_B = "file://#{TEST_FIXTURE_DIR}/patches/noop-b.diff" 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_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 PATCH_B_CONTENTS = File.read("#{TEST_FIXTURE_DIR}/patches/noop-b.diff").freeze
APPLY_A = "noop-a.diff" APPLY_A = "noop-a.diff"

View File

@ -65,7 +65,7 @@ module GitHub
"the `(.+)` organization has an IP allow list enabled, " \ "the `(.+)` organization has an IP allow list enabled, " \
"and your IP address is not permitted to access this resource").freeze "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. No GitHub credentials found in macOS Keychain, GitHub CLI or the environment.
#{GitHub.pat_blurb} #{GitHub.pat_blurb}
MESSAGE MESSAGE