Fix RuboCop Style/RedundantFreeze offenses

This commit is contained in:
Issy Long 2024-01-18 22:18:42 +00:00
parent e9587a5ecc
commit f682147598
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
57 changed files with 93 additions and 95 deletions

View File

@ -461,5 +461,3 @@ Style/ArrayIntersect:
Enabled: false
Style/HashSyntax:
EnforcedShorthandSyntax: either
Style/RedundantFreeze:
Enabled: false

View File

@ -13,11 +13,11 @@ module Cask
"_" => :underscores,
}.freeze
DIVIDER_REGEX = /(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join("|")})/.freeze
DIVIDER_REGEX = /(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join("|")})/
MAJOR_MINOR_PATCH_REGEX = /^([^.,:]+)(?:.([^.,:]+)(?:.([^.,:]+))?)?/.freeze
MAJOR_MINOR_PATCH_REGEX = /^([^.,:]+)(?:.([^.,:]+)(?:.([^.,:]+))?)?/
INVALID_CHARACTERS = /[^0-9a-zA-Z.,:\-_+ ]/.freeze
INVALID_CHARACTERS = /[^0-9a-zA-Z.,:\-_+ ]/
class << self
private

View File

@ -222,8 +222,8 @@ module Homebrew
to_formulae_to_casks(only: only, method: :resolve)
end
LOCAL_PATH_REGEX = %r{^/|[.]|/$}.freeze
TAP_NAME_REGEX = %r{^[^./]+/[^./]+$}.freeze
LOCAL_PATH_REGEX = %r{^/|[.]|/$}
TAP_NAME_REGEX = %r{^[^./]+/[^./]+$}
private_constant :LOCAL_PATH_REGEX, :TAP_NAME_REGEX
# Keep existing paths and try to convert others to tap, formula or cask paths.

View File

@ -714,7 +714,7 @@ class Reporter
# Hack `git diff` output with regexes to look like `git diff-tree` output.
# Yes, I know this is a bit filthy but it saves duplicating the #report logic.
diff_output = Utils.popen_read("git", "diff", "--no-ext-diff", api_names_before_txt, api_names_txt)
header_regex = /^(---|\+\+\+) /.freeze
header_regex = /^(---|\+\+\+) /
add_delete_characters = ["+", "-"].freeze
diff_output.lines.map do |line|

View File

@ -35,7 +35,7 @@ module Commands
# dot as a full stop if it is either followed by a whitespace or at the end of
# the description. In this way we can prevent cutting off a sentence in the
# middle due to dots in URLs or paths.
DESCRIPTION_SPLITTING_PATTERN = /\.(?>\s|$)/.freeze
DESCRIPTION_SPLITTING_PATTERN = /\.(?>\s|$)/
def self.valid_internal_cmd?(cmd)
require?(HOMEBREW_CMD_PATH/cmd)

View File

@ -4,7 +4,7 @@
# @private
module CompilerConstants
GNU_GCC_VERSIONS = %w[4.9 5 6 7 8 9 10 11 12 13].freeze
GNU_GCC_REGEXP = /^gcc-(4\.9|[5-9]|10|11|12|13)$/.freeze
GNU_GCC_REGEXP = /^gcc-(4\.9|[5-9]|10|11|12|13)$/
COMPILER_SYMBOL_MAP = {
"gcc" => :gcc,
"clang" => :clang,

View File

@ -69,7 +69,7 @@ ensure
end
module Homebrew
BOTTLE_BLOCK_REGEX = / bottle (?:do.+?end|:[a-z]+)\n\n/m.freeze
BOTTLE_BLOCK_REGEX = / bottle (?:do.+?end|:[a-z]+)\n\n/m
sig { returns(CLI::Parser) }
def self.extract_args

View File

@ -132,7 +132,7 @@ class Symbol
end
class String
BLANK_RE = /\A[[:space:]]*\z/.freeze
BLANK_RE = /\A[[:space:]]*\z/
# This is a cache that is intentionally mutable
# rubocop:disable Style/MutableConstant
ENCODED_BLANKS_ = T.let(Hash.new do |h, enc|

View File

@ -130,7 +130,7 @@ class Keg
end
end
VARIABLE_REFERENCE_RX = /^@(loader_|executable_|r)path/.freeze
VARIABLE_REFERENCE_RX = /^@(loader_|executable_|r)path/
def each_linkage_for(file, linkage_type, resolve_variable_references: false, &block)
file.public_send(linkage_type, resolve_variable_references: resolve_variable_references)
@ -159,7 +159,7 @@ class Keg
# Matches framework references like `XXX.framework/Versions/YYY/XXX` and
# `XXX.framework/XXX`, both with or without a slash-delimited prefix.
FRAMEWORK_RX = %r{(?:^|/)(([^/]+)\.framework/(?:Versions/[^/]+/)?\2)$}.freeze
FRAMEWORK_RX = %r{(?:^|/)(([^/]+)\.framework/(?:Versions/[^/]+/)?\2)$}
def find_dylib_suffix_from(bad_name)
if (framework = bad_name.match(FRAMEWORK_RX))
@ -233,7 +233,7 @@ class Keg
private
CELLAR_RX = %r{\A#{HOMEBREW_CELLAR}/(?<formula_name>[^/]+)/[^/]+}.freeze
CELLAR_RX = %r{\A#{HOMEBREW_CELLAR}/(?<formula_name>[^/]+)/[^/]+}
# Replace HOMEBREW_CELLAR references with HOMEBREW_PREFIX/opt references
# if the Cellar reference is to a different keg.

View File

@ -18,7 +18,7 @@ require "active_support/core_ext/hash/deep_transform_values"
module Formulary
extend Cachable
URL_START_REGEX = %r{(https?|ftp|file)://}.freeze
URL_START_REGEX = %r{(https?|ftp|file)://}
# :codesign and custom requirement classes are not supported
API_SUPPORTED_REQUIREMENTS = [:arch, :linux, :macos, :maximum_macos, :xcode].freeze

View File

@ -18,12 +18,12 @@ class GitHubPackages
private_constant :URL_PREFIX
private_constant :DOCKER_PREFIX
URL_REGEX = %r{(?:#{Regexp.escape(URL_PREFIX)}|#{Regexp.escape(DOCKER_PREFIX)})([\w-]+)/([\w-]+)}.freeze
URL_REGEX = %r{(?:#{Regexp.escape(URL_PREFIX)}|#{Regexp.escape(DOCKER_PREFIX)})([\w-]+)/([\w-]+)}
# Valid OCI tag characters
# https://github.com/opencontainers/distribution-spec/blob/main/spec.md#workflow-categories
VALID_OCI_TAG_REGEX = /^[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127}$/.freeze
INVALID_OCI_TAG_CHARS_REGEX = /[^a-zA-Z0-9._-]/.freeze
VALID_OCI_TAG_REGEX = /^[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127}$/
INVALID_OCI_TAG_CHARS_REGEX = /[^a-zA-Z0-9._-]/
GZIP_BUFFER_SIZE = 64 * 1024
private_constant :GZIP_BUFFER_SIZE

View File

@ -10,7 +10,7 @@ require "json"
class GitHubReleases
include Context
URL_REGEX = %r{https://github\.com/([\w-]+)/([\w-]+)?/releases/download/(.+)}.freeze
URL_REGEX = %r{https://github\.com/([\w-]+)/([\w-]+)?/releases/download/(.+)}
sig { params(bottles_hash: T::Hash[String, T.untyped]).void }
def upload_bottles(bottles_hash)

View File

@ -65,10 +65,10 @@ HOMEBREW_MACOS_OLDEST_SUPPORTED = ENV.fetch("HOMEBREW_MACOS_OLDEST_SUPPORTED").f
HOMEBREW_MACOS_OLDEST_ALLOWED = ENV.fetch("HOMEBREW_MACOS_OLDEST_ALLOWED").freeze
HOMEBREW_PULL_API_REGEX =
%r{https://api\.github\.com/repos/([\w-]+)/([\w-]+)?/pulls/(\d+)}.freeze
%r{https://api\.github\.com/repos/([\w-]+)/([\w-]+)?/pulls/(\d+)}
HOMEBREW_PULL_OR_COMMIT_URL_REGEX =
%r[https://github\.com/([\w-]+)/([\w-]+)?/(?:pull/(\d+)|commit/[0-9a-fA-F]{4,40})].freeze
HOMEBREW_BOTTLES_EXTNAME_REGEX = /\.([a-z0-9_]+)\.bottle\.(?:(\d+)\.)?tar\.gz$/.freeze
%r[https://github\.com/([\w-]+)/([\w-]+)?/(?:pull/(\d+)|commit/[0-9a-fA-F]{4,40})]
HOMEBREW_BOTTLES_EXTNAME_REGEX = /\.([a-z0-9_]+)\.bottle\.(?:(\d+)\.)?tar\.gz$/
require "extend/module"
require "extend/blank"

View File

@ -78,8 +78,8 @@ class Keg
end
# Locale-specific directories have the form `language[_territory][.codeset][@modifier]`
LOCALEDIR_RX = %r{(locale|man)/([a-z]{2}|C|POSIX)(_[A-Z]{2})?(\.[a-zA-Z\-0-9]+(@.+)?)?}.freeze
INFOFILE_RX = %r{info/([^.].*?\.info|dir)$}.freeze
LOCALEDIR_RX = %r{(locale|man)/([a-z]{2}|C|POSIX)(_[A-Z]{2})?(\.[a-zA-Z\-0-9]+(@.+)?)?}
INFOFILE_RX = %r{info/([^.].*?\.info|dir)$}
KEG_LINK_DIRECTORIES = %w[
bin etc include lib sbin share var
].freeze

View File

@ -12,7 +12,7 @@ class Keg
NULL_BYTE_STRING = "\\x00"
class Relocation
RELOCATABLE_PATH_REGEX_PREFIX = /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))/.freeze
RELOCATABLE_PATH_REGEX_PREFIX = /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))/
def initialize
@replacement_map = {}
@ -83,7 +83,7 @@ class Keg
[]
end
JAVA_REGEX = %r{#{HOMEBREW_PREFIX}/opt/openjdk(@\d+(\.\d+)*)?/libexec(/openjdk\.jdk/Contents/Home)?}.freeze
JAVA_REGEX = %r{#{HOMEBREW_PREFIX}/opt/openjdk(@\d+(\.\d+)*)?/libexec(/openjdk\.jdk/Contents/Home)?}
def prepare_relocation_to_placeholders
relocation = Relocation.new

View File

@ -92,7 +92,7 @@ module Language
module_function
# A regex to match potential shebang permutations.
NODE_SHEBANG_REGEX = %r{^#! ?/usr/bin/(?:env )?node( |$)}.freeze
NODE_SHEBANG_REGEX = %r{^#! ?/usr/bin/(?:env )?node( |$)}
# The length of the longest shebang matching `SHEBANG_REGEX`.
NODE_SHEBANG_MAX_LENGTH = "#! /usr/bin/env node ".length

View File

@ -11,7 +11,7 @@ module Language
module_function
# A regex to match potential shebang permutations.
PERL_SHEBANG_REGEX = %r{^#! ?/usr/bin/(?:env )?perl( |$)}.freeze
PERL_SHEBANG_REGEX = %r{^#! ?/usr/bin/(?:env )?perl( |$)}
# The length of the longest shebang matching `SHEBANG_REGEX`.
PERL_SHEBANG_MAX_LENGTH = "#! /usr/bin/env perl ".length

View File

@ -95,7 +95,7 @@ module Language
module_function
# A regex to match potential shebang permutations.
PYTHON_SHEBANG_REGEX = %r{^#! ?/usr/bin/(?:env )?python(?:[23](?:\.\d{1,2})?)?( |$)}.freeze
PYTHON_SHEBANG_REGEX = %r{^#! ?/usr/bin/(?:env )?python(?:[23](?:\.\d{1,2})?)?( |$)}
# The length of the longest shebang matching `SHEBANG_REGEX`.
PYTHON_SHEBANG_MAX_LENGTH = "#! /usr/bin/env pythonx.yyy ".length

View File

@ -81,7 +81,7 @@ module Homebrew
(?:ar(?:\.(?:bz2|gz|lz|lzma|lzo|xz|Z|zst))?|
b2|bz2?|z2|az|gz|lz|lzma|xz|Z|aZ|zst)
$
/ix.freeze
/ix
# An error message to use when a `strategy` block returns a value of
# an inappropriate type.

View File

@ -37,7 +37,7 @@ module Homebrew
(?<prefix>[^/]*?) # Any text in filename or directory before version
v?\d+(?:\.\d+)+ # The numeric version
(?<suffix>/|[^/]*) # Any text in filename or directory after version
}ix.freeze
}ix
# Whether the strategy can be applied to the provided URL.
#

View File

@ -36,7 +36,7 @@ module Homebrew
/(?<prefix>(?:[^/]+?[_-])?) # Filename text before the version
v?\d+(?:\.\d+)+ # The numeric version
(?<suffix>[^/]+) # Filename text after the version
}ix.freeze
}ix
# Whether the strategy can be applied to the provided URL.
#

View File

@ -27,7 +27,7 @@ module Homebrew
(?<prefix>[^/]+) # Filename text before the version
-v?\d+(?:\.\d+)* # The numeric version
(?<suffix>[^/]+) # Filename text after the version
}ix.freeze
}ix
# Whether the strategy can be applied to the provided URL.
#

View File

@ -19,7 +19,7 @@ module Homebrew
PRIORITY = 0
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = %r{^https?://.+/[^/]+\.ya?ml(?:\?[^/?]+)?$}i.freeze
URL_MATCH_REGEX = %r{^https?://.+/[^/]+\.ya?ml(?:\?[^/?]+)?$}i
# Whether the strategy can be applied to the provided URL.
#

View File

@ -24,7 +24,7 @@ module Homebrew
PRIORITY = 0
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = %r{^https?://}i.freeze
URL_MATCH_REGEX = %r{^https?://}i
# Whether the strategy can be applied to the provided URL.
#

View File

@ -30,7 +30,7 @@ module Homebrew
# The default regex used to naively identify versions from tags when a
# regex isn't provided.
DEFAULT_REGEX = /\D*(.+)/.freeze
DEFAULT_REGEX = /\D*(.+)/
# Whether the strategy can be applied to the provided URL.
#

View File

@ -41,11 +41,11 @@ module Homebrew
^https?://github\.com
/(?:downloads/)?(?<username>[^/]+) # The GitHub username
/(?<repository>[^/]+) # The GitHub repository name
}ix.freeze
}ix
# The default regex used to identify a version from a tag when a regex
# isn't provided.
DEFAULT_REGEX = /v?(\d+(?:\.\d+)+)/i.freeze
DEFAULT_REGEX = /v?(\d+(?:\.\d+)+)/i
# Keys in the release JSON that could contain the version.
# The tag name is checked first, to better align with the {Git}

View File

@ -32,7 +32,7 @@ module Homebrew
^https?://download\.gnome\.org
/sources
/(?<package_name>[^/]+)/ # The GNOME package name
}ix.freeze
}ix
# Whether the strategy can be applied to the provided URL.
#

View File

@ -36,7 +36,7 @@ module Homebrew
^https?://
(?:(?:[^/]+?\.)*gnu\.org/(?:gnu|software)/(?<project_name>[^/]+)/
|(?<project_name>[^/]+)\.gnu\.org/?$)
}ix.freeze
}ix
# Whether the strategy can be applied to the provided URL.
#

View File

@ -19,17 +19,17 @@ module Homebrew
class Hackage
# A `Regexp` used in determining if the strategy applies to the URL and
# also as part of extracting the package name from the URL basename.
PACKAGE_NAME_REGEX = /(?<package_name>.+?)-\d+/i.freeze
PACKAGE_NAME_REGEX = /(?<package_name>.+?)-\d+/i
# A `Regexp` used to extract the package name from the URL basename.
FILENAME_REGEX = /^#{PACKAGE_NAME_REGEX.source.strip}/i.freeze
FILENAME_REGEX = /^#{PACKAGE_NAME_REGEX.source.strip}/i
# A `Regexp` used in determining if the strategy applies to the URL.
URL_MATCH_REGEX = %r{
^https?://(?:downloads|hackage)\.haskell\.org
(?:/[^/]+)+ # Path before the filename
#{PACKAGE_NAME_REGEX.source.strip}
}ix.freeze
}ix
# Whether the strategy can be applied to the provided URL.
#

View File

@ -19,7 +19,7 @@ module Homebrew
PRIORITY = 0
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = %r{^https?://}i.freeze
URL_MATCH_REGEX = %r{^https?://}i
# The header fields to check when a `strategy` block isn't provided.
DEFAULT_HEADERS_TO_CHECK = ["content-disposition", "location"].freeze

View File

@ -31,7 +31,7 @@ module Homebrew
PRIORITY = 0
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = %r{^https?://}i.freeze
URL_MATCH_REGEX = %r{^https?://}i
# Whether the strategy can be applied to the provided URL.
# {Json} will technically match any HTTP URL but is only usable with

View File

@ -27,11 +27,11 @@ module Homebrew
URL_MATCH_REGEX = %r{
^https?://(?:[^/]+?\.)*launchpad\.net
/(?<project_name>[^/]+) # The Launchpad project name
}ix.freeze
}ix
# The default regex used to identify the latest version when a regex
# isn't provided.
DEFAULT_REGEX = %r{class="[^"]*version[^"]*"[^>]*>\s*Latest version is (.+)\s*</}.freeze
DEFAULT_REGEX = %r{class="[^"]*version[^"]*"[^>]*>\s*Latest version is (.+)\s*</}
# Whether the strategy can be applied to the provided URL.
#

View File

@ -23,7 +23,7 @@ module Homebrew
URL_MATCH_REGEX = %r{
^https?://registry\.npmjs\.org
/(?<package_name>.+?)/-/ # The npm package name
}ix.freeze
}ix
# Whether the strategy can be applied to the provided URL.
#

View File

@ -24,7 +24,7 @@ module Homebrew
PRIORITY = 0
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = %r{^https?://}i.freeze
URL_MATCH_REGEX = %r{^https?://}i
# Whether the strategy can be applied to the provided URL.
# {PageMatch} will technically match any HTTP URL but is only

View File

@ -25,7 +25,7 @@ module Homebrew
(?<package_name>.+)- # The package name followed by a hyphen
.*? # The version string
(?<suffix>\.tar\.[a-z0-9]+|\.[a-z0-9]+)$ # Filename extension
/ix.freeze
/ix
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = %r{
@ -33,7 +33,7 @@ module Homebrew
/packages
(?:/[^/]+)+ # The hexadecimal paths before the filename
/#{FILENAME_REGEX.source.strip} # The filename
}ix.freeze
}ix
# Whether the strategy can be applied to the provided URL.
#

View File

@ -39,7 +39,7 @@ module Homebrew
(?:/projects?/(?<project_name>[^/]+)/
|/p/(?<project_name>[^/]+)/
|(?::/cvsroot)?/(?<project_name>[^/]+))
}ix.freeze
}ix
# Whether the strategy can be applied to the provided URL.
#

View File

@ -19,7 +19,7 @@ module Homebrew
PRIORITY = 0
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = %r{^https?://}i.freeze
URL_MATCH_REGEX = %r{^https?://}i
# Common `os` values used in appcasts to refer to macOS.
APPCAST_MACOS_STRINGS = ["macos", "osx"].freeze

View File

@ -35,7 +35,7 @@ module Homebrew
PRIORITY = 0
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = %r{^https?://}i.freeze
URL_MATCH_REGEX = %r{^https?://}i
# Whether the strategy can be applied to the provided URL.
# {Xml} will technically match any HTTP URL but is only usable with

View File

@ -42,17 +42,17 @@ module Homebrew
# A `Regexp` used in determining if the strategy applies to the URL and
# also as part of extracting the module name from the URL basename.
MODULE_REGEX = /(?<module_name>.+)-\d+/i.freeze
MODULE_REGEX = /(?<module_name>.+)-\d+/i
# A `Regexp` used to extract the module name from the URL basename.
FILENAME_REGEX = /^#{MODULE_REGEX.source.strip}/i.freeze
FILENAME_REGEX = /^#{MODULE_REGEX.source.strip}/i
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = %r{
^https?://(?:[^/]+?\.)* # Scheme and any leading subdomains
(?:x\.org/(?:[^/]+/)*individual/(?:[^/]+/)*#{MODULE_REGEX.source.strip}
|freedesktop\.org/(?:archive|dist|software)/(?:[^/]+/)*#{MODULE_REGEX.source.strip})
}ix.freeze
}ix
# Used to cache page content, so we don't fetch the same pages
# repeatedly.

View File

@ -31,7 +31,7 @@ module Homebrew
PRIORITY = 0
# The `Regexp` used to determine if the strategy applies to the URL.
URL_MATCH_REGEX = %r{^https?://}i.freeze
URL_MATCH_REGEX = %r{^https?://}i
# Whether the strategy can be applied to the provided URL.
# {Yaml} will technically match any HTTP URL but is only usable with

View File

@ -12,18 +12,18 @@ class Locale
end
# ISO 639-1 or ISO 639-2
LANGUAGE_REGEX = /(?:[a-z]{2,3})/.freeze
LANGUAGE_REGEX = /(?:[a-z]{2,3})/
private_constant :LANGUAGE_REGEX
# ISO 15924
SCRIPT_REGEX = /(?:[A-Z][a-z]{3})/.freeze
SCRIPT_REGEX = /(?:[A-Z][a-z]{3})/
private_constant :SCRIPT_REGEX
# ISO 3166-1 or UN M.49
REGION_REGEX = /(?:[A-Z]{2}|\d{3})/.freeze
REGION_REGEX = /(?:[A-Z]{2}|\d{3})/
private_constant :REGION_REGEX
LOCALE_REGEX = /\A((?:#{LANGUAGE_REGEX}|#{REGION_REGEX}|#{SCRIPT_REGEX})(?:-|$)){1,3}\Z/.freeze
LOCALE_REGEX = /\A((?:#{LANGUAGE_REGEX}|#{REGION_REGEX}|#{SCRIPT_REGEX})(?:-|$)){1,3}\Z/
private_constant :LOCALE_REGEX
def self.parse(string)

View File

@ -8,7 +8,7 @@ module OS
# @api private
class SDK
# 11.x SDKs are explicitly excluded - we want the MacOSX11.sdk symlink instead.
VERSIONED_SDK_REGEX = /MacOSX(10\.\d+|\d+)\.sdk$/.freeze
VERSIONED_SDK_REGEX = /MacOSX(10\.\d+|\d+)\.sdk$/
sig { returns(MacOSVersion) }
attr_reader :version

View File

@ -10,7 +10,7 @@ class PkgVersion
include Comparable
extend Forwardable
REGEX = /\A(.+?)(?:_(\d+))?\z/.freeze
REGEX = /\A(.+?)(?:_(\d+))?\z/
private_constant :REGEX
attr_reader :version, :revision

View File

@ -12,7 +12,7 @@ module Readall
include Cachable
# TODO: remove this once the `MacOS` module is undefined on Linux
MACOS_MODULE_REGEX = /\b(MacOS|OS::Mac)(\.|::)\b/.freeze
MACOS_MODULE_REGEX = /\b(MacOS|OS::Mac)(\.|::)\b/
private_constant :MACOS_MODULE_REGEX
private :cache

View File

@ -153,7 +153,7 @@ module RuboCop
class LivecheckRegexExtension < FormulaCop
extend AutoCorrector
TAR_PATTERN = /\\?\.t(ar|(g|l|x)z$|[bz2]{2,4}$)(\\?\.((g|l|x)z)|[bz2]{2,4}|Z)?$/i.freeze
TAR_PATTERN = /\\?\.t(ar|(g|l|x)z$|[bz2]{2,4}$)(\\?\.((g|l|x)z)|[bz2]{2,4}|Z)?$/i
def audit_formula(_node, _class_node, _parent_class_node, body_node)
livecheck_node = find_block(body_node, :livecheck)

View File

@ -188,7 +188,7 @@ module Homebrew
end
end
SOCKET_STRING_REGEX = %r{^([a-z]+)://(.+):([0-9]+)$}i.freeze
SOCKET_STRING_REGEX = %r{^([a-z]+)://(.+):([0-9]+)$}i
sig {
params(value: T.nilable(T.any(String, T::Hash[Symbol, String])))

View File

@ -2,19 +2,19 @@
# frozen_string_literal: true
# Match taps' formulae, e.g. `someuser/sometap/someformula`
HOMEBREW_TAP_FORMULA_REGEX = T.let(%r{^([\w-]+)/([\w-]+)/([\w+-.@]+)$}.freeze, Regexp)
HOMEBREW_TAP_FORMULA_REGEX = T.let(%r{^([\w-]+)/([\w-]+)/([\w+-.@]+)$}, Regexp)
# Match taps' casks, e.g. `someuser/sometap/somecask`
HOMEBREW_TAP_CASK_REGEX = T.let(%r{^([\w-]+)/([\w-]+)/([a-z0-9\-_]+)$}.freeze, Regexp)
HOMEBREW_TAP_CASK_REGEX = T.let(%r{^([\w-]+)/([\w-]+)/([a-z0-9\-_]+)$}, Regexp)
# Match main cask taps' casks, e.g. `homebrew/cask/somecask` or `somecask`
HOMEBREW_MAIN_TAP_CASK_REGEX = T.let(%r{^([Hh]omebrew/(?:homebrew-)?cask/)?[a-z0-9\-_]+$}.freeze, Regexp)
HOMEBREW_MAIN_TAP_CASK_REGEX = T.let(%r{^([Hh]omebrew/(?:homebrew-)?cask/)?[a-z0-9\-_]+$}, Regexp)
# Match taps' directory paths, e.g. `HOMEBREW_LIBRARY/Taps/someuser/sometap`
HOMEBREW_TAP_DIR_REGEX = T.let(
%r{#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Taps/(?<user>[\w-]+)/(?<repo>[\w-]+)}.freeze, Regexp
%r{#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Taps/(?<user>[\w-]+)/(?<repo>[\w-]+)}, Regexp
)
# Match taps' formula paths, e.g. `HOMEBREW_LIBRARY/Taps/someuser/sometap/someformula`
HOMEBREW_TAP_PATH_REGEX = T.let(Regexp.new(HOMEBREW_TAP_DIR_REGEX.source + %r{(?:/.*)?$}.source).freeze, Regexp)
# Match official taps' casks, e.g. `homebrew/cask/somecask or homebrew/cask-versions/somecask`
HOMEBREW_CASK_TAP_CASK_REGEX =
T.let(%r{^(?:([Cc]askroom)/(cask|versions)|([Hh]omebrew)/(?:homebrew-)?(cask|cask-[\w-]+))/([\w+-.]+)$}.freeze,
T.let(%r{^(?:([Cc]askroom)/(cask|versions)|([Hh]omebrew)/(?:homebrew-)?(cask|cask-[\w-]+))/([\w+-.]+)$},
Regexp)
HOMEBREW_OFFICIAL_REPO_PREFIXES_REGEX = T.let(/^(home|linux)brew-/.freeze, Regexp)
HOMEBREW_OFFICIAL_REPO_PREFIXES_REGEX = T.let(/^(home|linux)brew-/, Regexp)

View File

@ -83,7 +83,7 @@ describe Homebrew::Livecheck::Strategy::ElectronBuilder do
# block here simply to ensure this method works as expected when a
# regex isn't provided.
expect(electron_builder.find_versions(url: http_url, provided_content: content) do |yaml|
regex = /^v?(\d+(?:\.\d+)+)$/i.freeze
regex = /^v?(\d+(?:\.\d+)+)$/i
yaml["version"][regex, 1]
end).to eq(find_versions_cached_return_hash)
end

View File

@ -130,7 +130,7 @@ describe Homebrew::Livecheck::Strategy::Json do
# block here simply to ensure this method works as expected when a
# regex isn't provided.
expect(json.find_versions(url: http_url, provided_content: content) do |json|
regex = /^v?(\d+(?:\.\d+)+)$/i.freeze
regex = /^v?(\d+(?:\.\d+)+)$/i
json["versions"].select { |item| item["version"]&.match?(regex) }
.map { |item| item["version"][regex, 1] }
end).to eq(find_versions_cached_return_hash.merge({ regex: nil }))

View File

@ -222,7 +222,7 @@ describe Homebrew::Livecheck::Strategy::Xml do
# block here simply to ensure this method works as expected when a
# regex isn't provided.
expect(xml.find_versions(url: http_url, provided_content: content_version_text) do |xml|
regex = /^v?(\d+(?:\.\d+)+)$/i.freeze
regex = /^v?(\d+(?:\.\d+)+)$/i
xml.get_elements("/versions/version").map { |item| item.text[regex, 1] }
end).to eq(find_versions_cached_return_hash.merge({ regex: nil }))
end

View File

@ -131,7 +131,7 @@ describe Homebrew::Livecheck::Strategy::Yaml do
# block here simply to ensure this method works as expected when a
# regex isn't provided.
expect(yaml.find_versions(url: http_url, provided_content: content) do |yaml|
regex = /^v?(\d+(?:\.\d+)+)$/i.freeze
regex = /^v?(\d+(?:\.\d+)+)$/i
yaml["versions"].select { |item| item["version"]&.match?(regex) }
.map { |item| item["version"][regex, 1] }
end).to eq(find_versions_cached_return_hash.merge({ regex: nil }))

View File

@ -15,7 +15,7 @@ module Utils
# This regex is used to extract the part of an ETag within quotation marks,
# ignoring any leading weak validator indicator (`W/`). This simplifies
# ETag comparison in `#curl_check_http_content`.
ETAG_VALUE_REGEX = %r{^(?:[wW]/)?"((?:[^"]|\\")*)"}.freeze
ETAG_VALUE_REGEX = %r{^(?:[wW]/)?"((?:[^"]|\\")*)"}
# HTTP responses and body content are typically separated by a double
# `CRLF` (whereas HTTP header lines are separated by a single `CRLF`).
@ -24,7 +24,7 @@ module Utils
# This regex is used to isolate the parts of an HTTP status line, namely
# the status code and any following descriptive text (e.g. `Not Found`).
HTTP_STATUS_LINE_REGEX = %r{^HTTP/.* (?<code>\d+)(?: (?<text>[^\r\n]+))?}.freeze
HTTP_STATUS_LINE_REGEX = %r{^HTTP/.* (?<code>\d+)(?: (?<text>[^\r\n]+))?}
private_constant :ETAG_VALUE_REGEX, :HTTP_RESPONSE_BODY_SEPARATOR, :HTTP_STATUS_LINE_REGEX

View File

@ -509,9 +509,9 @@ module GitHub
end
def self.pull_request_title_regex(name, version = nil)
return /(^|\s)#{Regexp.quote(name)}(:|,|\s|$)/i.freeze if version.blank?
return /(^|\s)#{Regexp.quote(name)}(:|,|\s|$)/i if version.blank?
/(^|\s)#{Regexp.quote(name)}(:|,|\s)(.*\s)?#{Regexp.quote(version)}(:|,|\s|$)/i.freeze
/(^|\s)#{Regexp.quote(name)}(:|,|\s)(.*\s)?#{Regexp.quote(version)}(:|,|\s|$)/i
end
def self.fetch_pull_requests(name, tap_remote_repo, state: nil, version: nil)

View File

@ -26,7 +26,7 @@ module GitHub
CREATE_ISSUE_FORK_OR_PR_SCOPES = ["repo"].freeze
CREATE_WORKFLOW_SCOPES = ["workflow"].freeze
ALL_SCOPES = (CREATE_GIST_SCOPES + CREATE_ISSUE_FORK_OR_PR_SCOPES + CREATE_WORKFLOW_SCOPES).freeze
GITHUB_PERSONAL_ACCESS_TOKEN_REGEX = /^(?:[a-f0-9]{40}|gh[po]_\w{36,251})$/.freeze
GITHUB_PERSONAL_ACCESS_TOKEN_REGEX = /^(?:[a-f0-9]{40}|gh[po]_\w{36,251})$/
# Helper functions to access the GitHub API.
#

View File

@ -106,7 +106,7 @@ module Utils
zsh: "~/.zshrc",
}.freeze
UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@~\n])}.freeze
UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@~\n])}
sig { params(str: String).returns(String) }
def csh_quote(str)

View File

@ -139,7 +139,7 @@ class Version
# A token string.
class StringToken < Token
PATTERN = /[a-z]+/i.freeze
PATTERN = /[a-z]+/i
sig { override.returns(String) }
attr_reader :value
@ -164,7 +164,7 @@ class Version
# A token consisting of only numbers.
class NumericToken < Token
PATTERN = /[0-9]+/i.freeze
PATTERN = /[0-9]+/i
sig { override.returns(Integer) }
attr_reader :value
@ -204,7 +204,7 @@ class Version
# A token representing the part of a version designating it as an alpha release.
class AlphaToken < CompositeToken
PATTERN = /alpha[0-9]*|a[0-9]+/i.freeze
PATTERN = /alpha[0-9]*|a[0-9]+/i
sig { override.params(other: T.untyped).returns(T.nilable(Integer)) }
def <=>(other)
@ -223,7 +223,7 @@ class Version
# A token representing the part of a version designating it as a beta release.
class BetaToken < CompositeToken
PATTERN = /beta[0-9]*|b[0-9]+/i.freeze
PATTERN = /beta[0-9]*|b[0-9]+/i
sig { override.params(other: T.untyped).returns(T.nilable(Integer)) }
def <=>(other)
@ -244,7 +244,7 @@ class Version
# A token representing the part of a version designating it as a pre-release.
class PreToken < CompositeToken
PATTERN = /pre[0-9]*/i.freeze
PATTERN = /pre[0-9]*/i
sig { override.params(other: T.untyped).returns(T.nilable(Integer)) }
def <=>(other)
@ -265,7 +265,7 @@ class Version
# A token representing the part of a version designating it as a release candidate.
class RCToken < CompositeToken
PATTERN = /rc[0-9]*/i.freeze
PATTERN = /rc[0-9]*/i
sig { override.params(other: T.untyped).returns(T.nilable(Integer)) }
def <=>(other)
@ -286,7 +286,7 @@ class Version
# A token representing the part of a version designating it as a patch release.
class PatchToken < CompositeToken
PATTERN = /p[0-9]*/i.freeze
PATTERN = /p[0-9]*/i
sig { override.params(other: T.untyped).returns(T.nilable(Integer)) }
def <=>(other)
@ -305,7 +305,7 @@ class Version
# A token representing the part of a version designating it as a post release.
class PostToken < CompositeToken
PATTERN = /.post[0-9]+/i.freeze
PATTERN = /.post[0-9]+/i
sig { override.params(other: T.untyped).returns(T.nilable(Integer)) }
def <=>(other)
@ -503,7 +503,7 @@ class Version
@detected_from_url
end
HEAD_VERSION_REGEX = /\AHEAD(?:-(?<commit>.*))?\Z/.freeze
HEAD_VERSION_REGEX = /\AHEAD(?:-(?<commit>.*))?\Z/
private_constant :HEAD_VERSION_REGEX
# Check if this is a HEAD version.

View File

@ -49,8 +49,8 @@ class Version
# @api private
class StemParser < RegexParser
SOURCEFORGE_DOWNLOAD_REGEX = %r{(?:sourceforge\.net|sf\.net)/.*/download$}.freeze
NO_FILE_EXTENSION_REGEX = /\.[^a-zA-Z]+$/.freeze
SOURCEFORGE_DOWNLOAD_REGEX = %r{(?:sourceforge\.net|sf\.net)/.*/download$}
NO_FILE_EXTENSION_REGEX = /\.[^a-zA-Z]+$/
sig { override.params(spec: Pathname).returns(String) }
def self.process_spec(spec)