brew style --fix

This commit is contained in:
Mike McQuaid 2020-06-02 09:49:23 +01:00
parent edc6107ccb
commit aa81982aba
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
25 changed files with 50 additions and 50 deletions

View File

@ -259,7 +259,7 @@ module Cask
bad_url_format?(/sourceforge/,
[
%r{\Ahttps://sourceforge\.net/projects/[^/]+/files/latest/download\Z},
%r{\Ahttps://downloads\.sourceforge\.net/(?!(project|sourceforge)\/)},
%r{\Ahttps://downloads\.sourceforge\.net/(?!(project|sourceforge)/)},
])
end

View File

@ -4,7 +4,7 @@ module Cask
module Blacklist
def self.blacklisted_reason(name)
case name
when /^adobe\-(after|illustrator|indesign|photoshop|premiere)/
when /^adobe-(after|illustrator|indesign|photoshop|premiere)/
"Adobe casks were removed because they are too difficult to maintain."
when /^audacity$/
"Audacity was removed because it is too difficult to download programmatically."

View File

@ -180,7 +180,7 @@ module Cask
end
def process_options(*args)
exclude_regex = /^\-\-#{Regexp.union(*Config::DEFAULT_DIRS.keys.map(&Regexp.public_method(:escape)))}=/
exclude_regex = /^--#{Regexp.union(*Config::DEFAULT_DIRS.keys.map(&Regexp.public_method(:escape)))}=/
non_options = []

View File

@ -46,7 +46,7 @@ module Cask
next if self.class.options.nil?
self.class.options.each do |option_name, option_method|
option_type = case option_name.split(/(\ |\=)/).last
option_type = case option_name.split(/(\ |=)/).last
when "PATH"
Pathname
when /\w+(,\w+)+/

View File

@ -86,7 +86,7 @@ module Cask
Shellwords.shellsplit(ENV.fetch("HOMEBREW_CASK_OPTS", ""))
.select { |arg| arg.include?("=") }
.map { |arg| arg.split("=", 2) }
.map { |(flag, value)| [flag.sub(/^\-\-/, ""), value] },
.map { |(flag, value)| [flag.sub(/^--/, ""), value] },
)
end

View File

@ -11,9 +11,9 @@ module Cask
DIVIDER_REGEX = /(#{DIVIDERS.keys.map { |v| Regexp.quote(v) }.join('|')})/.freeze
MAJOR_MINOR_PATCH_REGEX = /^([^.,:]+)(?:\.([^.,:]+)(?:\.([^.,:]+))?)?/.freeze
MAJOR_MINOR_PATCH_REGEX = /^([^.,:]+)(?:.([^.,:]+)(?:.([^.,:]+))?)?/.freeze
INVALID_CHARACTERS = /[^0-9a-zA-Z\.\,\:\-\_]/.freeze
INVALID_CHARACTERS = /[^0-9a-zA-Z.,:\-_]/.freeze
class << self
private
@ -75,7 +75,7 @@ module Cask
s = downcase.delete(".").gsub(/[^a-z\d]+/, "-")
return true if s.match?(/(\d+|\b)(alpha|beta|preview|rc|dev|canary|snapshot)(\d+|\b)/i)
return true if s.match?(/\A[a-z\d]+(\-\d+)*\-?(a|b|pre)(\d+|\b)/i)
return true if s.match?(/\A[a-z\d]+(-\d+)*-?(a|b|pre)(\d+|\b)/i)
false
end

View File

@ -56,14 +56,14 @@ module CleanupRefinement
end
end
version ||= basename.to_s[/\A.*(?:\-\-.*?)*\-\-(.*?)#{Regexp.escape(extname)}\Z/, 1]
version ||= basename.to_s[/\A.*\-\-?(.*?)#{Regexp.escape(extname)}\Z/, 1]
version ||= basename.to_s[/\A.*(?:--.*?)*--(.*?)#{Regexp.escape(extname)}\Z/, 1]
version ||= basename.to_s[/\A.*--?(.*?)#{Regexp.escape(extname)}\Z/, 1]
return false unless version
version = Version.new(version)
return false unless formula_name = basename.to_s[/\A(.*?)(?:\-\-.*?)*\-\-?(?:#{Regexp.escape(version)})/, 1]
return false unless formula_name = basename.to_s[/\A(.*?)(?:--.*?)*--?(?:#{Regexp.escape(version)})/, 1]
formula = begin
Formulary.from_rack(HOMEBREW_CELLAR/formula_name)
@ -71,7 +71,7 @@ module CleanupRefinement
return false
end
resource_name = basename.to_s[/\A.*?\-\-(.*?)\-\-?(?:#{Regexp.escape(version)})/, 1]
resource_name = basename.to_s[/\A.*?--(.*?)--?(?:#{Regexp.escape(version)})/, 1]
if resource_name == "patch"
patch_hashes = formula.stable&.patches&.select(&:external?)&.map(&:resource)&.map(&:version)
@ -92,7 +92,7 @@ module CleanupRefinement
end
def stale_cask?(scrub)
return false unless name = basename.to_s[/\A(.*?)\-\-/, 1]
return false unless name = basename.to_s[/\A(.*?)--/, 1]
cask = begin
Cask::CaskLoader.load(name)
@ -100,7 +100,7 @@ module CleanupRefinement
return false
end
return true unless basename.to_s.match?(/\A#{Regexp.escape(name)}\-\-#{Regexp.escape(cask.version)}\b/)
return true unless basename.to_s.match?(/\A#{Regexp.escape(name)}--#{Regexp.escape(cask.version)}\b/)
return true if scrub && !cask.versions.include?(cask.version)

View File

@ -669,7 +669,7 @@ module Homebrew
.map(&:to_i)
case (url = stable.url)
when /[\d\._-](alpha|beta|rc\d)/
when /[\d._-](alpha|beta|rc\d)/
matched = Regexp.last_match(1)
version_prefix = stable_version_string.sub(/\d+$/, "")
return if UNSTABLE_WHITELIST[formula.name] == version_prefix
@ -803,7 +803,7 @@ module Homebrew
end
bin_names.each do |name|
["system", "shell_output", "pipe_output"].each do |cmd|
if text.to_s.match?(/test do.*#{cmd}[\(\s]+['"]#{Regexp.escape(name)}[\s'"]/m)
if text.to_s.match?(/test do.*#{cmd}[(\s]+['"]#{Regexp.escape(name)}[\s'"]/m)
problem %Q(fully scope test #{cmd} calls, e.g. #{cmd} "\#{bin}/#{name}")
end
end

View File

@ -321,7 +321,7 @@ module Homebrew
if any_go_deps
go_regex =
Version.formula_optionally_versioned_regex(:go, full: false)
ignores << %r{#{Regexp.escape(HOMEBREW_CELLAR)}/#{go_regex}/[\d\.]+/libexec}
ignores << %r{#{Regexp.escape(HOMEBREW_CELLAR)}/#{go_regex}/[\d.]+/libexec}
end
relocatable = true

View File

@ -79,7 +79,7 @@ module Homebrew
origin_branch = "#{homebrew_core_remote}/#{homebrew_core_branch}"
previous_branch = Utils.popen_read("git -C \"#{formula.tap.path}\" symbolic-ref -q --short HEAD").chomp
previous_branch = "master" if previous_branch.empty?
formula_path = formula.path.to_s[%r{(Formula\/.*)}, 1]
formula_path = formula.path.to_s[%r{(Formula/.*)}, 1]
if args.dry_run?
ohai "git remote add #{homebrew_core_remote} #{homebrew_core_url}"
@ -89,7 +89,7 @@ module Homebrew
return tap_full_name, origin_branch, previous_branch
else
formula.path.parent.cd do
unless Utils.popen_read("git remote -v").match?(%r{^homebrew.*Homebrew\/homebrew-core.*$})
unless Utils.popen_read("git remote -v").match?(%r{^homebrew.*Homebrew/homebrew-core.*$})
ohai "Adding #{homebrew_core_remote} remote"
safe_system "git", "remote", "add", homebrew_core_remote, homebrew_core_url
end
@ -225,7 +225,7 @@ module Homebrew
replacement_pairs += formula_spec.mirrors.map do |mirror|
[
/ +mirror \"#{Regexp.escape(mirror)}\"\n/m,
/ +mirror "#{Regexp.escape(mirror)}"\n/m,
"",
]
end
@ -258,7 +258,7 @@ module Homebrew
if new_mirrors
replacement_pairs << [
/^( +)(url \"#{Regexp.escape(new_url)}\"\n)/m,
/^( +)(url "#{Regexp.escape(new_url)}"\n)/m,
"\\1\\2\\1mirror \"#{new_mirrors.join("\"\n\\1mirror \"")}\"\n",
]
end
@ -283,30 +283,30 @@ module Homebrew
]
elsif new_mirrors
[
/^( +)(mirror \"#{Regexp.escape(new_mirrors.last)}\"\n)/m,
/^( +)(mirror "#{Regexp.escape(new_mirrors.last)}"\n)/m,
"\\1\\2\\1version \"#{forced_version}\"\n",
]
else
[
/^( +)(url \"#{Regexp.escape(new_url)}\"\n)/m,
/^( +)(url "#{Regexp.escape(new_url)}"\n)/m,
"\\1\\2\\1version \"#{forced_version}\"\n",
]
end
elsif requested_spec == :devel
replacement_pairs << [
/( devel do.+?version \")#{old_formula_version}(\"\n.+?end\n)/m,
/( devel do.+?version ")#{old_formula_version}("\n.+?end\n)/m,
"\\1#{forced_version}\\2",
]
end
elsif forced_version && forced_version == "0"
if requested_spec == :stable
replacement_pairs << [
/^ version \"[\w\.\-\+]+\"\n/m,
/^ version "[\w.\-+]+"\n/m,
"",
]
elsif requested_spec == :devel
replacement_pairs << [
/( devel do.+?)^ +version \"[^\n]+\"\n(.+?end\n)/m,
/( devel do.+?)^ +version "[^\n]+"\n(.+?end\n)/m,
"\\1\\2",
]
end

View File

@ -333,7 +333,7 @@ module Homebrew
def check_bintray_mirror(name, url)
headers, = curl_output("--connect-timeout", "15", "--location", "--head", url)
status_code = headers.scan(%r{^HTTP\/.* (\d+)}).last.first
status_code = headers.scan(%r{^HTTP/.* (\d+)}).last.first
return if status_code.start_with?("2")
opoo "The Bintray mirror #{url} is not reachable (HTTP status code #{status_code})."

View File

@ -221,7 +221,7 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy
end
def basename
cached_location.basename.sub(/^[\da-f]{64}\-\-/, "")
cached_location.basename.sub(/^[\da-f]{64}--/, "")
end
private
@ -390,7 +390,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
filenames = lines.map(&parse_content_disposition).compact
time =
lines.map { |line| line[/^Last\-Modified:\s*(.+)/i, 1] }
lines.map { |line| line[/^Last-Modified:\s*(.+)/i, 1] }
.compact
.map { |t| t.match?(/^\d+$/) ? Time.at(t.to_i) : Time.parse(t) }
.last
@ -820,7 +820,7 @@ class GitHubGitDownloadStrategy < GitDownloadStrategy
return unless status.success?
commit = output[/^ETag: \"(\h+)\"/, 1]
commit = output[/^ETag: "(\h+)"/, 1]
version.update_commit(commit) if commit
commit
end

View File

@ -224,7 +224,7 @@ class Pathname
return archive_ext if archive_ext
# Don't treat version numbers as extname.
return "" if basename.match?(/\b\d+\.\d+[^\.]*\Z/) && !basename.end_with?(".7z")
return "" if basename.match?(/\b\d+\.\d+[^.]*\Z/) && !basename.end_with?(".7z")
File.extname(basename)
end

View File

@ -26,7 +26,7 @@ module StringInreplaceExtension
# Looks for Makefile style variable definitions and replaces the
# value with "new_value", or removes the definition entirely.
def change_make_var!(flag, new_value)
return if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=[ \t]*((?:.*\\\n)*.*)$/, "#{flag}=#{new_value}", false)
return if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?+:!]?=[ \t]*((?:.*\\\n)*.*)$/, "#{flag}=#{new_value}", false)
errors << "expected to change #{flag.inspect} to #{new_value.inspect}"
end
@ -35,7 +35,7 @@ module StringInreplaceExtension
def remove_make_var!(flags)
Array(flags).each do |flag|
# Also remove trailing \n, if present.
unless gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=(?:.*\\\n)*.*$\n?/, "", false)
unless gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?+:!]?=(?:.*\\\n)*.*$\n?/, "", false)
errors << "expected to remove #{flag.inspect}"
end
end
@ -43,6 +43,6 @@ module StringInreplaceExtension
# Finds the specified variable
def get_make_var(flag)
self[/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=[ \t]*((?:.*\\\n)*.*)$/, 1]
self[/^#{Regexp.escape(flag)}[ \t]*[\\?+:!]?=[ \t]*((?:.*\\\n)*.*)$/, 1]
end
end

View File

@ -8,7 +8,7 @@ class Locale
REGION_REGEX = /(?:[A-Z]{2}|\d{3})/.freeze # ISO 3166-1 or UN M.49
SCRIPT_REGEX = /(?:[A-Z][a-z]{3})/.freeze # ISO 15924
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/.freeze
def self.parse(string)
string = string.to_s
@ -16,7 +16,7 @@ class Locale
raise ParserError, "'#{string}' cannot be parsed to a #{self}" unless string.match?(LOCALE_REGEX)
scan = proc do |regex|
string.scan(/(?:\-|^)(#{regex})(?:\-|$)/).flatten.first
string.scan(/(?:-|^)(#{regex})(?:-|$)/).flatten.first
end
language = scan.call(LANGUAGE_REGEX)

View File

@ -129,7 +129,7 @@ module RuboCop
string = stanza.stanza_node.children[2]
return string.str_content if string.str_type?
string.to_s.gsub(%r{.*"([a-z0-9]+\:\/\/[^"]+)".*}m, '\1')
string.to_s.gsub(%r{.*"([a-z0-9]+://[^"]+)".*}m, '\1')
end
def url_match_homepage?(stanza)

View File

@ -153,7 +153,7 @@ module RuboCop
find_instance_method_call(body_node, :build, :include?) do |method|
arg = parameters(method).first
next unless match = regex_match_group(arg, /^\-\-(.*)$/)
next unless match = regex_match_group(arg, /^--(.*)$/)
problem "Reference '#{match[1]}' without dashes"
end
@ -403,7 +403,7 @@ module RuboCop
path = parameters(method).first
next unless path.str_type?
next unless match = regex_match_group(path, /^[^\*{},]+$/)
next unless match = regex_match_group(path, /^[^*{},]+$/)
problem "Dir([\"#{string_content(path)}\"]) is unnecessary; just use \"#{match[0]}\""
end

View File

@ -88,7 +88,7 @@ class SystemConfig
_, err, status = system_command("java", args: ["-version"], print_stderr: false)
return "N/A" unless status.success?
err[/java version "([\d\._]+)"/, 1] || "N/A"
err[/java version "([\d._]+)"/, 1] || "N/A"
end
def describe_git
@ -100,7 +100,7 @@ class SystemConfig
def describe_curl
out, = system_command(curl_executable, args: ["--version"])
if /^curl (?<curl_version>[\d\.]+)/ =~ out
if /^curl (?<curl_version>[\d.]+)/ =~ out
"#{curl_version} => #{curl_executable}"
else
"N/A"

View File

@ -9,7 +9,7 @@ end
describe "brew --cache", :integration_test do
it "prints all cache files for a given Formula" do
expect { brew "--cache", testball }
.to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}\-\-testball\-}).to_stdout
.to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--testball-}).to_stdout
.and not_to_output.to_stderr
.and be_a_success
end

View File

@ -68,7 +68,7 @@ describe "brew install", :integration_test do
# and there will be the git requirement, but we cannot instantiate git
# formula since we only have testball1 formula.
expect { brew "install", "testball1", "--HEAD", "--ignore-dependencies" }
.to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD\-d5eb689}).to_stdout
.to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD-d5eb689}).to_stdout
.and output(/Cloning into/).to_stderr
.and be_a_success
expect(HOMEBREW_CELLAR/"testball1/HEAD-d5eb689/foo/test").not_to be_a_file

View File

@ -73,7 +73,7 @@ describe RuboCop::Cop::FormulaAudit::Homepage do
RUBY
inspect_source(source)
if homepage.match?(%r{http:\/\/www\.freedesktop\.org})
if homepage.match?(%r{http://www\.freedesktop\.org})
if homepage.match?(/Software/)
expected_offenses = [{ message: "#{homepage} should be styled " \
"`https://wiki.freedesktop.org/www/Software/project_name`",
@ -89,7 +89,7 @@ describe RuboCop::Cop::FormulaAudit::Homepage do
column: 2,
source: source }]
end
elsif homepage.match?(%r{https:\/\/code\.google\.com})
elsif homepage.match?(%r{https://code\.google\.com})
expected_offenses = [{ message: "#{homepage} should end with a slash",
severity: :convention,
line: 2,

View File

@ -19,7 +19,7 @@ describe Searchable do
context "when given a regex" do
it "does not simplify strings" do
expect(subject.search(/with\-dashes/)).to eq ["with-dashes"]
expect(subject.search(/with-dashes/)).to eq ["with-dashes"]
end
end

View File

@ -253,7 +253,7 @@ describe "globally-scoped helper methods" do
)
}.to raise_error(
MethodDeprecatedError,
%r{method.*replacement.*homebrew/core.*\/Taps\/homebrew\/homebrew-core\/}m,
%r{method.*replacement.*homebrew/core.*/Taps/homebrew/homebrew-core/}m,
)
end
end

View File

@ -168,7 +168,7 @@ module Kernel
tap = Tap.fetch(match[:user], match[:repo])
tap_message = +"\nPlease report this issue to the #{tap} tap (not Homebrew/brew or Homebrew/core)"
tap_message += ", or even better, submit a PR to fix it" if replacement
tap_message << ":\n #{line.sub(/^(.*\:\d+)\:.*$/, '\1')}\n\n"
tap_message << ":\n #{line.sub(/^(.*:\d+):.*$/, '\1')}\n\n"
break
end

View File

@ -196,7 +196,7 @@ def curl_http_content_headers_and_checksum(url, hash_needed: false, user_agent:
status_code = :unknown
while status_code == :unknown || status_code.to_s.start_with?("3")
headers, _, output = output.partition("\r\n\r\n")
status_code = headers[%r{HTTP\/.* (\d+)}, 1]
status_code = headers[%r{HTTP/.* (\d+)}, 1]
final_url = headers[/^Location:\s*(.*)$/i, 1]&.chomp
end
@ -208,7 +208,7 @@ def curl_http_content_headers_and_checksum(url, hash_needed: false, user_agent:
url: url,
final_url: final_url,
status: status_code,
etag: headers[%r{ETag: ([wW]\/)?"(([^"]|\\")*)"}, 2],
etag: headers[%r{ETag: ([wW]/)?"(([^"]|\\")*)"}, 2],
content_length: headers[/Content-Length: (\d+)/, 1],
file_hash: output_hash,
file: output,