Merge branch 'master' into api-language-support

This commit is contained in:
Mike McQuaid 2023-02-03 08:36:23 +00:00 committed by GitHub
commit 9d6713d023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
135 changed files with 528 additions and 391 deletions

View File

@ -41,7 +41,7 @@ Metrics/PerceivedComplexity:
Metrics/MethodLength:
Max: 232
Metrics/ModuleLength:
Max: 463
Max: 466
Exclude:
# TODO: extract more of the bottling logic
- "dev-cmd/bottle.rb"

View File

@ -198,7 +198,7 @@ GEM
thor (>= 1.2.0)
yard-sorbet
thor (1.2.1)
tzinfo (2.0.5)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
@ -209,10 +209,9 @@ GEM
parser (>= 3.1.0)
uri_template (0.7.0)
warning (1.3.0)
webrick (1.7.0)
webrick (1.8.1)
webrobots (0.1.2)
yard (0.9.28)
webrick (~> 1.7.0)
yard (0.9.26)
yard-sorbet (0.6.1)
sorbet-runtime (>= 0.5)
yard (>= 0.9)

View File

@ -3,7 +3,6 @@
require "api/analytics"
require "api/cask"
require "api/cask-source"
require "api/formula"
require "api/versions"
require "extend/cachable"
@ -23,23 +22,20 @@ module Homebrew
HOMEBREW_CACHE_API = (HOMEBREW_CACHE/"api").freeze
MAX_RETRIES = 3
sig { params(endpoint: String, json: T::Boolean).returns(T.any(String, Hash)) }
def fetch(endpoint, json: true)
sig { params(endpoint: String).returns(Hash) }
def fetch(endpoint)
return cache[endpoint] if cache.present? && cache.key?(endpoint)
api_url = "#{API_DOMAIN}/#{endpoint}"
output = Utils::Curl.curl_output("--fail", api_url, max_time: 5)
raise ArgumentError, "No file found at #{Tty.underline}#{api_url}#{Tty.reset}" unless output.success?
cache[endpoint] = if json
JSON.parse(output.stdout)
else
output.stdout
end
cache[endpoint] = JSON.parse(output.stdout)
rescue JSON::ParserError
raise ArgumentError, "Invalid JSON file: #{Tty.underline}#{api_url}#{Tty.reset}"
end
sig { params(endpoint: String, target: Pathname).returns(Hash) }
def fetch_json_api_file(endpoint, target:)
retry_count = 0
@ -58,5 +54,19 @@ module Homebrew
retry
end
end
sig { params(filepath: String, repo: String, git_head: T.nilable(String)).returns(String) }
def fetch_file_source(filepath, repo:, git_head: nil)
git_head ||= "master"
endpoint = "#{git_head}/#{filepath}"
return cache[endpoint] if cache.present? && cache.key?(endpoint)
raw_url = "https://raw.githubusercontent.com/#{repo}/#{endpoint}"
puts "Fetching #{raw_url}..."
output = Utils::Curl.curl_output("--fail", raw_url, max_time: 5)
raise ArgumentError, "No file found at #{Tty.underline}#{raw_url}#{Tty.reset}" unless output.success?
cache[endpoint] = output.stdout
end
end
end

View File

@ -1,29 +0,0 @@
# typed: false
# frozen_string_literal: true
module Homebrew
module API
# Helper functions for using the cask source API.
#
# @api private
module CaskSource
class << self
extend T::Sig
sig { params(token: String).returns(Hash) }
def fetch(token)
token = token.sub(%r{^homebrew/cask/}, "")
Homebrew::API.fetch "cask-source/#{token}.rb", json: false
end
sig { params(token: String).returns(T::Boolean) }
def available?(token)
fetch token
true
rescue ArgumentError
false
end
end
end
end
end

View File

@ -10,9 +10,14 @@ module Homebrew
class << self
extend T::Sig
sig { params(name: String).returns(Hash) }
def fetch(name)
Homebrew::API.fetch "cask/#{name}.json"
sig { params(token: String).returns(Hash) }
def fetch(token)
Homebrew::API.fetch "cask/#{token}.json"
end
sig { params(token: String, git_head: T.nilable(String)).returns(String) }
def fetch_source(token, git_head: nil)
Homebrew::API.fetch_file_source "Casks/#{token}.rb", repo: "Homebrew/homebrew-cask", git_head: git_head
end
sig { returns(Hash) }

View File

@ -199,7 +199,7 @@ rescue MethodDeprecatedError => e
exit 1
rescue Exception => e # rubocop:disable Lint/RescueException
onoe e
if internal_cmd && defined?(OS::ISSUES_URL)
if internal_cmd && !OS.unsupported_configuration?
if Homebrew::EnvConfig.no_auto_update?
$stderr.puts "#{Tty.bold}Do not report this issue until you've run `brew update` and tried again.#{Tty.reset}"
else

View File

@ -689,6 +689,8 @@ done
HOMEBREW_ARG_COUNT="$#"
HOMEBREW_COMMAND="$1"
shift
# If you are going to change anything in below case statement,
# be sure to also update HOMEBREW_INTERNAL_COMMAND_ALIASES hash in commands.rb
case "${HOMEBREW_COMMAND}" in
ls) HOMEBREW_COMMAND="list" ;;
homepage) HOMEBREW_COMMAND="home" ;;
@ -705,6 +707,8 @@ case "${HOMEBREW_COMMAND}" in
environment) HOMEBREW_COMMAND="--env" ;;
--config) HOMEBREW_COMMAND="config" ;;
-v) HOMEBREW_COMMAND="--version" ;;
lc) HOMEBREW_COMMAND="livecheck" ;;
tc) HOMEBREW_COMMAND="typecheck" ;;
esac
# Set HOMEBREW_DEV_CMD_RUN for users who have run a development command.
@ -767,13 +771,21 @@ To turn developer mode off, run $(bold "brew developer off")
fi
# Test HOMEBREW_INSTALL_FROM_API on HOMEBREW_DEV_CMD_RUN and HOMEBREW_DEVELOPER
# folks who haven't run a HOMEBREW_DEVELOPER_COMMAND.
# folks who haven't run a HOMEBREW_DEVELOPER_COMMAND if they are in a default
# prefix and on a supported macOS version.
if [[ -z "${HOMEBREW_NO_INSTALL_FROM_API}" &&
-z "${HOMEBREW_INSTALL_FROM_API}" &&
-z "${HOMEBREW_DEVELOPER_COMMAND}" ]] &&
[[ -z "${HOMEBREW_MACOS_VERSION_NUMERIC}" ||
"${HOMEBREW_MACOS_VERSION_NUMERIC}" -ge "110000" ]] &&
[[ "${HOMEBREW_PREFIX}" == "/usr/local" ||
"${HOMEBREW_PREFIX}" == "/opt/homebrew" ||
"${HOMEBREW_PREFIX}" == "/home/linuxbrew/.linuxbrew" ]] &&
[[ -n "${HOMEBREW_DEV_CMD_RUN}" || -n "${HOMEBREW_DEVELOPER}" ]]
then
export HOMEBREW_INSTALL_FROM_API=1
else
unset HOMEBREW_INSTALL_FROM_API
fi
if [[ -f "${HOMEBREW_LIBRARY}/Homebrew/cmd/${HOMEBREW_COMMAND}.sh" ]]

View File

@ -246,6 +246,8 @@ module Cask
"conflicts_with" => conflicts_with,
"container" => container&.pairs,
"auto_updates" => auto_updates,
"tap_git_head" => tap&.git_head,
"languages" => languages,
}
end

View File

@ -215,7 +215,7 @@ module Cask
# Use the cask-source API if there are any `*flight` blocks or the cask has multiple languages
if json_cask[:artifacts].any? { |artifact| FLIGHT_STANZAS.include?(artifact.keys.first) } ||
json_cask[:languages].any?
cask_source = Homebrew::API::CaskSource.fetch(token)
cask_source = Homebrew::API::Cask.fetch_source(token, git_head: json_cask[:tap_git_head])
return FromContentLoader.new(cask_source).load(config: config)
end
@ -223,7 +223,9 @@ module Cask
json_cask[:artifacts] = json_cask[:artifacts].map(&method(:from_h_hash_gsubs))
json_cask[:caveats] = from_h_string_gsubs(json_cask[:caveats])
Cask.new(token, source: cask_source, config: config) do
tap = Tap.fetch(json_cask[:tap]) if json_cask[:tap].to_s.include?("/")
Cask.new(token, tap: tap, source: cask_source, config: config) do
version json_cask[:version]
if json_cask[:sha256] == "no_check"
@ -371,7 +373,7 @@ module Cask
return loader_class.new(ref)
end
if Homebrew::EnvConfig.install_from_api? && !need_path && Homebrew::API::CaskSource.available?(ref)
if Homebrew::EnvConfig.install_from_api? && !need_path && Homebrew::API::Cask.all_casks.key?(ref)
return FromAPILoader.new(ref)
end

View File

@ -298,9 +298,10 @@ module Homebrew
def parse(argv = ARGV.freeze, ignore_invalid_options: false)
raise "Arguments were already parsed!" if @args_parsed
# If we accept formula options, parse once allowing invalid options
# so we can get the remaining list containing formula names.
if @formula_options
# If we accept formula options, but the command isn't scoped only
# to casks, parse once allowing invalid options so we can get the
# remaining list containing formula names.
if @formula_options && !only_casks?(argv)
remaining, non_options = parse_remaining(argv, ignore_invalid_options: true)
argv = [*remaining, "--", *non_options]
@ -639,6 +640,10 @@ module Homebrew
end
end.compact.uniq(&:name)
end
def only_casks?(argv)
argv.include?("--casks") || argv.include?("--cask")
end
end
class OptionConstraintError < UsageError

View File

@ -9,6 +9,7 @@ require "description_cache_store"
require "cli/parser"
require "settings"
require "linuxbrew-core-migration"
require "extend/os/cmd/update-report"
module Homebrew
extend T::Sig
@ -293,31 +294,7 @@ module Homebrew
end
def migrate_gcc_dependents_if_needed
# TODO: Refactor and move to extend/os
return if OS.mac? # rubocop:disable Homebrew/MoveToExtendOS
return if Settings.read("gcc-rpaths.fixed") == "true"
Formula.installed.each do |formula|
next unless formula.tap&.core_tap?
recursive_runtime_dependencies = Dependency.expand(
formula,
cache_key: "update-report",
) do |_, dependency|
Dependency.prune if dependency.build? || dependency.test?
end
next unless recursive_runtime_dependencies.map(&:name).include? "gcc"
keg = formula.installed_kegs.last
tab = Tab.for_keg(keg)
# Force reinstallation upon `brew upgrade` to fix the bottle RPATH.
tab.source["versions"]["version_scheme"] = -1
tab.write
rescue TapFormulaUnavailableError
nil
end
Settings.write "gcc-rpaths.fixed", true
# do nothing
end
end

View File

@ -11,6 +11,8 @@ module Commands
HOMEBREW_CMD_PATH = (HOMEBREW_LIBRARY_PATH/"cmd").freeze
HOMEBREW_DEV_CMD_PATH = (HOMEBREW_LIBRARY_PATH/"dev-cmd").freeze
# If you are going to change anything in below hash,
# be sure to also update appropriate case statement in brew.sh
HOMEBREW_INTERNAL_COMMAND_ALIASES = {
"ls" => "list",
"homepage" => "home",

View File

@ -30,9 +30,8 @@ module Homebrew
members = {
plc: GitHub.members_by_team("Homebrew", "plc"),
tsc: GitHub.members_by_team("Homebrew", "tsc"),
maintainers: GitHub.members_by_team("Homebrew", "maintainers"),
}
members[:other] = GitHub.members_by_team("Homebrew", "maintainers")
.except(*members.values.map(&:keys).flatten.uniq)
sentences = {}
members.each do |group, hash|
@ -48,8 +47,8 @@ module Homebrew
"\\1 is #{sentences[:plc]}.")
content.gsub!(/(Homebrew's \[Technical Steering Committee.*) is .*\./,
"\\1 is #{sentences[:tsc]}.")
content.gsub!(/(Homebrew's other current maintainers are).*\./,
"\\1 #{sentences[:other]}.")
content.gsub!(/(Homebrew's maintainers are).*\./,
"\\1 #{sentences[:maintainers]}.")
File.write(readme, content)

View File

@ -226,7 +226,9 @@ module Homebrew
},
HOMEBREW_INSTALL_FROM_API: {
description: "If set, install formulae and casks in homebrew/core and homebrew/cask taps using Homebrew's " \
"API instead of needing (large, slow) local checkouts of these repositories.",
"API instead of needing (large, slow) local checkouts of these repositories. Note, this will " \
"only take effect in supported configurations (i.e. using the default Homebrew prefix and, " \
"if on macOS, on a supported version).",
boolean: true,
},
HOMEBREW_LIVECHECK_WATCHLIST: {
@ -285,8 +287,7 @@ module Homebrew
boolean: true,
},
HOMEBREW_NO_EMOJI: {
description: "If set, do not print `HOMEBREW_INSTALL_BADGE` on a successful build." \
"\n\n *Note:* Will only try to print emoji on OS X Lion or newer.",
description: "If set, do not print `HOMEBREW_INSTALL_BADGE` on a successful build.",
boolean: true,
},
HOMEBREW_NO_ENV_HINTS: {
@ -485,6 +486,9 @@ module Homebrew
sig { returns(T::Boolean) }
def install_from_api?
return false if OS.unsupported_configuration?
return false unless Homebrew.default_prefix?
ENV["HOMEBREW_NO_INSTALL_FROM_API"].blank? && ENV["HOMEBREW_INSTALL_FROM_API"].present?
end
end

View File

@ -524,7 +524,7 @@ class BuildError < RuntimeError
end
end
if formula.tap && defined?(OS::ISSUES_URL)
if formula.tap && !OS.unsupported_configuration?
if formula.tap.official?
puts Formatter.error(Formatter.url(OS::ISSUES_URL), label: "READ THIS")
elsif (issues_url = formula.tap.issues_url)

View File

@ -0,0 +1,4 @@
# typed: strict
# frozen_string_literal: true
require "extend/os/linux/cmd/update-report" if OS.linux?

View File

@ -0,0 +1,34 @@
# typed: false
# frozen_string_literal: true
module Homebrew
extend T::Sig
module_function
def migrate_gcc_dependents_if_needed
return if Settings.read("gcc-rpaths.fixed") == "true"
Formula.installed.each do |formula|
next unless formula.tap&.core_tap?
recursive_runtime_dependencies = Dependency.expand(
formula,
cache_key: "update-report",
) do |_, dependency|
Dependency.prune if dependency.build? || dependency.test?
end
next unless recursive_runtime_dependencies.map(&:name).include? "gcc"
keg = formula.installed_kegs.last
tab = Tab.for_keg(keg)
# Force reinstallation upon `brew upgrade` to fix the bottle RPATH.
tab.source["versions"]["version_scheme"] = -1
tab.write
rescue TapFormulaUnavailableError
nil
end
Settings.write "gcc-rpaths.fixed", true
end
end

View File

@ -1,4 +0,0 @@
# typed: strict
# frozen_string_literal: true
require "active_support/core_ext/object/blank"

View File

@ -2126,6 +2126,7 @@ class Formula
"disabled" => disabled?,
"disable_date" => disable_date,
"disable_reason" => disable_reason,
"tap_git_head" => tap&.git_head,
}
if stable

View File

@ -129,8 +129,6 @@ end.compact.freeze
require "set"
require "extend/string"
require "system_command"
require "exceptions"
require "utils"

View File

@ -48,7 +48,7 @@ module Homebrew
readme.read[/(Homebrew's \[Technical Steering Committee.*\.)/, 1]
.gsub(/\[([^\]]+)\]\([^)]+\)/, '\1')
variables[:maintainers] =
readme.read[/(Homebrew's other current maintainers .*\.)/, 1]
readme.read[/(Homebrew's maintainers .*\.)/, 1]
.gsub(/\[([^\]]+)\]\([^)]+\)/, '\1')
variables[:alumni] =
readme.read[/(Former maintainers .*\.)/, 1]

View File

@ -59,8 +59,8 @@ module OS
if !OS::Mac.version.prerelease? &&
!OS::Mac.version.outdated_release? &&
ARGV.none? { |v| v.start_with?("--cc=") } &&
(HOMEBREW_PREFIX == HOMEBREW_DEFAULT_PREFIX ||
(HOMEBREW_PREFIX == HOMEBREW_MACOS_ARM_DEFAULT_PREFIX && Hardware::CPU.arm?))
(HOMEBREW_PREFIX.to_s == HOMEBREW_DEFAULT_PREFIX ||
(HOMEBREW_PREFIX.to_s == HOMEBREW_MACOS_ARM_DEFAULT_PREFIX && Hardware::CPU.arm?))
ISSUES_URL = "https://docs.brew.sh/Troubleshooting"
end
PATH_OPEN = "/usr/bin/open"
@ -69,4 +69,9 @@ module OS
ISSUES_URL = "https://docs.brew.sh/Troubleshooting"
PATH_OPEN = "xdg-open"
end
sig { returns(T::Boolean) }
def self.unsupported_configuration?
!defined?(OS::ISSUES_URL)
end
end

View File

@ -1,12 +0,0 @@
# typed: strict
# frozen_string_literal: true
# Utility method extensions for String.
class String
extend T::Sig
sig { returns(String) }
def undent
gsub(/^.{#{(slice(/^ +/) || '').length}}/, "")
end
end

View File

@ -2,7 +2,6 @@
# frozen_string_literal: true
require "rubocops/extend/formula"
require "extend/string"
module RuboCop
module Cop

View File

@ -1,7 +1,6 @@
# typed: false
# frozen_string_literal: true
require "extend/string"
require "rubocops/shared/helper_functions"
module RuboCop

View File

@ -3,7 +3,6 @@
require "rubocops/extend/formula"
require "rubocops/shared/desc_helper"
require "extend/string"
module RuboCop
module Cop

View File

@ -2,7 +2,6 @@
# frozen_string_literal: true
require "rubocops/extend/formula"
require "extend/string"
module RuboCop
module Cop

View File

@ -8,7 +8,6 @@ require_relative "cask/constants/stanza"
require_relative "cask/ast/stanza"
require_relative "cask/ast/cask_header"
require_relative "cask/ast/cask_block"
require_relative "cask/extend/string"
require_relative "cask/extend/node"
require_relative "cask/mixin/cask_help"
require_relative "cask/mixin/on_homepage_stanza"

View File

@ -579,6 +579,12 @@ end
class TZInfo::PeriodNotFound < ::StandardError; end
module TZInfo::RubyCoreSupport
class << self
def untaint(o); end
end
end
class TZInfo::StringDeduper
def initialize; end

View File

@ -265,6 +265,7 @@ class WEBrick::HTTPRequest
private
def _read_data(io, method, *arg); end
def parse_host_request_line(host); end
def parse_query; end
def parse_uri(str, scheme = T.unsafe(nil)); end
def read_body(socket, block); end
@ -284,7 +285,6 @@ class WEBrick::HTTPResponse
def [](field); end
def []=(field, value); end
def _rack_setup_header; end
def body; end
def body=(_arg0); end
def chunked=(val); end
@ -319,9 +319,13 @@ class WEBrick::HTTPResponse
def sent_size; end
def set_error(ex, backtrace = T.unsafe(nil)); end
def set_redirect(status, url); end
def setup_header; end
def status; end
def status=(status); end
def status_line; end
def upgrade; end
def upgrade!(protocol); end
def upgrade=(_arg0); end
private
@ -450,6 +454,15 @@ class WEBrick::HTTPServlet::FileHandler < ::WEBrick::HTTPServlet::AbstractServle
end
end
class WEBrick::HTTPServlet::ProcHandler < ::WEBrick::HTTPServlet::AbstractServlet
def initialize(proc); end
def do_GET(request, response); end
def do_POST(request, response); end
def do_PUT(request, response); end
def get_instance(server, *options); end
end
module WEBrick::HTTPStatus
private

View File

@ -149,13 +149,16 @@ class Rack::Request
def xhr?; end
class << self
def forwarded_priority; end
def forwarded_priority=(_arg0); end
def ip_filter; end
def ip_filter=(_arg0); end
def x_forwarded_proto_priority; end
def x_forwarded_proto_priority=(_arg0); end
end
end
Rack::Request::ALLOWED_SCHEMES = T.let(T.unsafe(nil), Array)
Rack::Request::SCHEME_WHITELIST = T.let(T.unsafe(nil), Array)
class String
include ::Comparable
@ -202,8 +205,6 @@ module YARD
def ruby18?; end
def ruby19?; end
def ruby2?; end
def ruby31?; end
def ruby3?; end
def windows?; end
end
end
@ -1419,12 +1420,7 @@ class YARD::Handlers::Ruby::MixinHandler < ::YARD::Handlers::Ruby::Base
def recipient(mixin); end
end
class YARD::Handlers::Ruby::ModuleFunctionHandler < ::YARD::Handlers::Ruby::Base
include ::YARD::Handlers::Ruby::DecoratorHandlerMethods
def make_module_function(instance_method, namespace); end
end
class YARD::Handlers::Ruby::ModuleFunctionHandler < ::YARD::Handlers::Ruby::Base; end
class YARD::Handlers::Ruby::ModuleHandler < ::YARD::Handlers::Ruby::Base; end
class YARD::Handlers::Ruby::PrivateClassMethodHandler < ::YARD::Handlers::Ruby::Base
@ -2409,7 +2405,6 @@ class YARD::Parser::Ruby::ModuleNode < ::YARD::Parser::Ruby::KeywordNode
end
class YARD::Parser::Ruby::ParameterNode < ::YARD::Parser::Ruby::AstNode
def args_forward; end
def block_param; end
def double_splat_param; end
def named_params; end
@ -3335,7 +3330,6 @@ class YARD::Tags::Directive
protected
def inside_directive?; end
def parser; end
end

View File

@ -4390,10 +4390,6 @@ module Homebrew::API::Cask
extend ::T::Private::Methods::SingletonMethodHooks
end
module Homebrew::API::CaskSource
extend ::T::Private::Methods::SingletonMethodHooks
end
module Homebrew::API::Formula
extend ::T::Private::Methods::SingletonMethodHooks
end

View File

@ -141,11 +141,15 @@ module SystemConfig
def core_tap_config(f = $stdout)
if CoreTap.instance.installed?
f.puts "Core tap ORIGIN: #{core_tap_origin}"
f.puts "Core tap origin: #{core_tap_origin}"
f.puts "Core tap HEAD: #{core_tap_head}"
f.puts "Core tap last commit: #{core_tap_last_commit}"
f.puts "Core tap branch: #{core_tap_branch}"
else
end
if (formula_json = Homebrew::API::HOMEBREW_CACHE_API/"formula.json") && formula_json.exist?
f.puts "Core tap JSON: #{formula_json.mtime.to_s(:short)}"
elsif !CoreTap.instance.installed?
f.puts "Core tap: N/A"
end
end

View File

@ -178,7 +178,7 @@ class Tap
def git_head
raise TapUnavailableError, name unless installed?
path.git_head
@git_head ||= path.git_head
end
# Time since last git commit for this {Tap}.

View File

@ -41,4 +41,14 @@ describe Homebrew::API::Cask do
expect(casks_output).to eq casks_hash
end
end
describe "::fetch_source" do
it "fetches the source of a cask (defaulting to master when no `git_head` is passed)" do
curl_output = OpenStruct.new(stdout: "foo", success?: true)
expect(Utils::Curl).to receive(:curl_output)
.with("--fail", "https://raw.githubusercontent.com/Homebrew/homebrew-cask/master/Casks/foo.rb", max_time: 5)
.and_return(curl_output)
described_class.fetch_source("foo", git_head: nil)
end
end
end

View File

@ -21,12 +21,6 @@ describe Homebrew::API do
end
describe "::fetch" do
it "fetches a text file" do
mock_curl_output stdout: text
fetched_text = described_class.fetch("foo.txt", json: false)
expect(fetched_text).to eq text
end
it "fetches a JSON file" do
mock_curl_output stdout: json
fetched_json = described_class.fetch("foo.json")
@ -70,4 +64,19 @@ describe Homebrew::API do
}.to raise_error(SystemExit)
end
end
describe "::fetch_file_source" do
it "fetches a file" do
mock_curl_output stdout: json
fetched_json = described_class.fetch_file_source("foo.json", repo: "Homebrew/homebrew-core", git_head: "master")
expect(fetched_json).to eq json
end
it "raises an error if the file does not exist" do
mock_curl_output success: false
expect {
described_class.fetch_file_source("bar.txt", repo: "Homebrew/homebrew-core", git_head: "master")
}.to raise_error(ArgumentError, /No file found/)
end
end
end

View File

@ -84,7 +84,10 @@ describe Cask::Cmd::List, :cask do
end
describe "lists json" do
let(:casks) { ["local-caffeine", "local-transmission", "multiple-versions", "third-party/tap/third-party-cask"] }
let(:casks) {
["local-caffeine", "local-transmission", "multiple-versions", "with-languages",
"third-party/tap/third-party-cask"]
}
let(:expected_output) {
<<~EOS
[
@ -124,7 +127,11 @@ describe Cask::Cmd::List, :cask do
},
"conflicts_with": null,
"container": null,
"auto_updates": null
"auto_updates": null,
"tap_git_head": null,
"languages": [
]
},
{
"token": "local-transmission",
@ -155,7 +162,11 @@ describe Cask::Cmd::List, :cask do
},
"conflicts_with": null,
"container": null,
"auto_updates": null
"auto_updates": null,
"tap_git_head": null,
"languages": [
]
},
{
"token": "multiple-versions",
@ -189,7 +200,11 @@ describe Cask::Cmd::List, :cask do
},
"conflicts_with": null,
"container": null,
"auto_updates": null
"auto_updates": null,
"tap_git_head": null,
"languages": [
]
},
{
"token": "third-party-cask",
@ -220,7 +235,47 @@ describe Cask::Cmd::List, :cask do
},
"conflicts_with": null,
"container": null,
"auto_updates": null
"auto_updates": null,
"tap_git_head": null,
"languages": [
]
},
{
"token": "with-languages",
"full_token": "with-languages",
"tap": "homebrew/cask",
"name": [
],
"desc": null,
"homepage": "https://brew.sh/",
"url": "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip",
"appcast": null,
"version": "1.2.3",
"versions": {
},
"installed": "1.2.3",
"outdated": false,
"sha256": "xyz789",
"artifacts": [
{
"app": [
"Caffeine.app"
]
}
],
"caveats": null,
"depends_on": {
},
"conflicts_with": null,
"container": null,
"auto_updates": null,
"tap_git_head": null,
"languages": [
"zh",
"en-US"
]
}
]
EOS
@ -257,7 +312,7 @@ describe Cask::Cmd::List, :cask do
it "of given Casks" do
expect {
described_class.run("--json", "local-caffeine", "local-transmission", "multiple-versions",
"third-party/tap/third-party-cask")
"third-party/tap/third-party-cask", "with-languages")
}.to output(expected_output).to_stdout
end
end

View File

@ -11,7 +11,7 @@ describe RuboCop::Cop::Cask::HomepageUrlTrailingSlash do
context "when the homepage URL ends with a slash" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
homepage 'https://foo.brew.sh/'
end
@ -23,7 +23,7 @@ describe RuboCop::Cop::Cask::HomepageUrlTrailingSlash do
context "when the homepage URL does not end with a slash but has a path" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
homepage 'https://foo.brew.sh/path'
end
@ -35,14 +35,14 @@ describe RuboCop::Cop::Cask::HomepageUrlTrailingSlash do
context "when the homepage URL does not end with a slash and has no path" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
homepage 'https://foo.brew.sh'
end
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
homepage 'https://foo.brew.sh/'
end

View File

@ -12,7 +12,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when auditing `postflight` stanzas" do
context "when there are no on_system blocks" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
postflight do
foobar
@ -26,7 +26,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is an `on_intel` block" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
postflight do
on_intel do
@ -37,7 +37,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
postflight do
if Hardware::CPU.intel?
@ -64,7 +64,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is an `on_monterey` block" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
postflight do
on_monterey do
@ -75,7 +75,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
postflight do
if MacOS.version == :monterey
@ -102,7 +102,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is an `on_monterey :or_older` block" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
postflight do
on_monterey :or_older do
@ -113,7 +113,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
postflight do
if MacOS.version <= :monterey
@ -143,7 +143,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when auditing `sha256` stanzas inside on_arch blocks" do
context "when there are no on_arch blocks" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
end
@ -155,7 +155,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when the proper `sha256` stanza is used" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
sha256 arm: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
intel: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
@ -168,7 +168,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when the `sha256` stanza needs to be removed from the on_arch blocks" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
on_intel do
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
@ -180,7 +180,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
#{" "}
sha256 arm: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b", intel: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
@ -188,7 +188,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
CASK
end
let(:offense_source) do
<<-CASK.undent
<<~CASK
on_arm do
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
end
@ -213,7 +213,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is only one on_arch block" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
on_intel do
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
@ -227,7 +227,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is also a `version` stanza inside the on_arch blocks" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
on_intel do
version "1.0.0"
@ -246,7 +246,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is also a `version` stanza inside only a single on_arch block" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
on_intel do
version "2.0.0"
@ -266,7 +266,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when auditing loose `Hardware::CPU` method calls" do
context "when there is a `Hardware::CPU.arm?` reference" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
if Hardware::CPU.arm? && other_condition
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
@ -291,7 +291,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is a `Hardware::CPU.intel?` reference" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
if Hardware::CPU.intel? && other_condition
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
@ -316,7 +316,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is a `Hardware::CPU.arch` reference" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version "1.2.3"
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
@ -342,7 +342,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when auditing loose `MacOS.version` method calls" do
context "when there is a `MacOS.version ==` reference" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
if MacOS.version == :catalina
version "1.0.0"
@ -367,7 +367,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is a `MacOS.version <=` reference" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
if MacOS.version <= :catalina
version "1.0.0"
@ -392,7 +392,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is a `MacOS.version >=` reference" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
if MacOS.version >= :catalina
version "1.0.0"
@ -417,7 +417,7 @@ describe RuboCop::Cop::Cask::OnSystemConditionals do
context "when there is a `MacOS.version` reference" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version "1.2.3"
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"

View File

@ -18,7 +18,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when there is only one stanza" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
end
@ -30,7 +30,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when no stanzas are incorrectly grouped" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -43,7 +43,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when no stanzas or variable assignments are incorrectly grouped" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm64", intel: "x86_64"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -59,7 +59,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when one stanza is incorrectly grouped" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
@ -68,7 +68,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -92,7 +92,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when the arch stanza is incorrectly grouped" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm64", intel: "x86_64"
version :latest
@ -101,7 +101,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm64", intel: "x86_64"
@ -127,7 +127,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when one variable assignment is incorrectly grouped" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm64", intel: "x86_64"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -137,7 +137,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm64", intel: "x86_64"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -164,7 +164,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when many stanzas are incorrectly grouped" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -181,7 +181,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -232,7 +232,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when many stanzas and variable assignments are incorrectly grouped" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm64", intel: "x86_64"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -253,7 +253,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm64", intel: "x86_64"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -320,7 +320,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when caveats stanza is incorrectly grouped" do
let(:source) do
format(<<-CASK.undent, caveats: caveats.strip)
format(<<~CASK, caveats: caveats.strip)
cask 'foo' do
version :latest
sha256 :no_check
@ -332,7 +332,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
CASK
end
let(:correct_source) do
format(<<-CASK.undent, caveats: caveats.strip)
format(<<~CASK, caveats: caveats.strip)
cask 'foo' do
version :latest
sha256 :no_check
@ -355,8 +355,8 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when caveats is a heredoc" do
let(:caveats) do
<<-CAVEATS.undent
caveats <<-EOS.undent
<<~CAVEATS
caveats <<~EOS
This is a multiline caveat.
Let's hope it doesn't cause any problems!
@ -369,7 +369,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when caveats is a block" do
let(:caveats) do
<<-CAVEATS.undent
<<~CAVEATS
caveats do
puts 'This is a multiline caveat.'
@ -384,7 +384,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when the postflight stanza is incorrectly grouped" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -398,7 +398,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -420,7 +420,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when a stanza has a comment" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -437,7 +437,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -462,7 +462,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
context "when a stanza has a comment and there is a variable assignment" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm64", intel: "x86_64"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -481,7 +481,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm64", intel: "x86_64"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -509,7 +509,7 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
# TODO: detect incorrectly grouped stanzas in nested expressions
context "when stanzas are nested in a conditional expression" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
if true
version :latest

View File

@ -11,7 +11,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when there is only one stanza" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
end
@ -23,7 +23,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when no stanzas are out of order" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm", intel: "x86_64"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -39,7 +39,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when one pair of stanzas is out of order" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
sha256 :no_check
version :latest
@ -47,7 +47,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -77,7 +77,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when the arch stanza is out of order" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -86,7 +86,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm", intel: "x86_64"
version :latest
@ -123,7 +123,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when an arch variable assignment is out of order" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm", intel: "x86_64"
sha256 :no_check
@ -133,7 +133,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm", intel: "x86_64"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -165,7 +165,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when an arch variable assignment is above the arch stanza" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
arch arm: "arm", intel: "x86_64"
@ -175,7 +175,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm", intel: "x86_64"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -207,7 +207,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when many stanzas are out of order" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
url 'https://foo.brew.sh/foo.zip'
uninstall :quit => 'com.example.foo',
@ -219,7 +219,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -266,7 +266,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when a stanza appears multiple times" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
name 'Foo'
url 'https://foo.brew.sh/foo.zip'
@ -279,7 +279,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -299,7 +299,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when a stanza has a comment" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
# comment with an empty line between
@ -313,7 +313,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check # comment on same line
@ -332,7 +332,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when a variable assignment is out of order with a comment" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -347,7 +347,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" # comment on same line
version :latest
@ -367,7 +367,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when the caveats stanza is out of order" do
let(:source) do
format(<<-CASK.undent, caveats: caveats.strip)
format(<<~CASK, caveats: caveats.strip)
cask 'foo' do
name 'Foo'
url 'https://foo.brew.sh/foo.zip'
@ -379,7 +379,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
CASK
end
let(:correct_source) do
format(<<-CASK.undent, caveats: caveats.strip)
format(<<~CASK, caveats: caveats.strip)
cask 'foo' do
version :latest
sha256 :no_check
@ -399,8 +399,8 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when caveats is a heredoc" do
let(:caveats) do
<<-CAVEATS.undent
caveats <<-EOS.undent
<<~CAVEATS
caveats <<~EOS
This is a multiline caveat.
Let's hope it doesn't cause any problems!
@ -413,7 +413,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when caveats is a block" do
let(:caveats) do
<<-CAVEATS.undent
<<~CAVEATS
caveats do
puts 'This is a multiline caveat.'
@ -428,7 +428,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
context "when the postflight stanza is out of order" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
name 'Foo'
url 'https://foo.brew.sh/foo.zip'
@ -442,7 +442,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version :latest
sha256 :no_check
@ -462,7 +462,7 @@ describe RuboCop::Cop::Cask::StanzaOrder do
# TODO: detect out-of-order stanzas in nested expressions
context "when stanzas are nested in a conditional expression" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
if true
sha256 :no_check

View File

@ -11,7 +11,7 @@ describe RuboCop::Cop::Cask::UrlLegacyCommaSeparators do
context "when url version interpolation does not include version.before_comma or version.after_comma" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version '1.1'
url 'https://foo.brew.sh/foo-\#{version}.dmg'
@ -24,7 +24,7 @@ describe RuboCop::Cop::Cask::UrlLegacyCommaSeparators do
context "when the url uses csv" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version '1.1,111'
url 'https://foo.brew.sh/foo-\#{version.csv.first}.dmg'
@ -37,7 +37,7 @@ describe RuboCop::Cop::Cask::UrlLegacyCommaSeparators do
context "when the url uses version.before_comma" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version '1.1,111'
url 'https://foo.brew.sh/foo-\#{version.before_comma}.dmg'
@ -45,7 +45,7 @@ describe RuboCop::Cop::Cask::UrlLegacyCommaSeparators do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version '1.1,111'
url 'https://foo.brew.sh/foo-\#{version.csv.first}.dmg'
@ -70,7 +70,7 @@ describe RuboCop::Cop::Cask::UrlLegacyCommaSeparators do
context "when the url uses version.after_comma" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version '1.1,111'
url 'https://foo.brew.sh/foo-\#{version.after_comma}.dmg'
@ -78,7 +78,7 @@ describe RuboCop::Cop::Cask::UrlLegacyCommaSeparators do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
version '1.1,111'
url 'https://foo.brew.sh/foo-\#{version.csv.second}.dmg'

View File

@ -11,7 +11,7 @@ describe RuboCop::Cop::Cask::Variables do
context "when there are no variables" do
let(:source) do
<<-CASK.undent
<<~CASK
cask "foo" do
version :latest
end
@ -23,7 +23,7 @@ describe RuboCop::Cop::Cask::Variables do
context "when there is an arch stanza" do
let(:source) do
<<-CASK.undent
<<~CASK
cask "foo" do
arch arm: "darwin-arm64", intel: "darwin"
end
@ -35,7 +35,7 @@ describe RuboCop::Cop::Cask::Variables do
context "when there is a non-arch variable that uses the arch conditional" do
let(:source) do
<<-CASK.undent
<<~CASK
cask "foo" do
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
end
@ -47,14 +47,14 @@ describe RuboCop::Cop::Cask::Variables do
context "when there is an arch variable" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"
end
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "darwin-arm64", intel: "darwin"
end
@ -78,14 +78,14 @@ describe RuboCop::Cop::Cask::Variables do
context "when there is an arch variable that doesn't use strings" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64
end
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: :darwin_arm64, intel: :darwin
end
@ -109,14 +109,14 @@ describe RuboCop::Cop::Cask::Variables do
context "when there is an arch with an empty string" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch = Hardware::CPU.intel? ? "" : "arm64"
end
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "arm64"
end
@ -140,14 +140,14 @@ describe RuboCop::Cop::Cask::Variables do
context "when there is a non-arch variable" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
folder = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"
end
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
end
@ -171,14 +171,14 @@ describe RuboCop::Cop::Cask::Variables do
context "when there is a non-arch variable with an empty string" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
folder = Hardware::CPU.intel? ? "amd64" : ""
end
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
folder = on_arch_conditional intel: "amd64"
end
@ -202,7 +202,7 @@ describe RuboCop::Cop::Cask::Variables do
context "when there is an arch and a non-arch variable" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"
folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"
@ -210,7 +210,7 @@ describe RuboCop::Cop::Cask::Variables do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
arch arm: "darwin-arm64", intel: "darwin"
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
@ -242,7 +242,7 @@ describe RuboCop::Cop::Cask::Variables do
context "when there are two non-arch variables" do
let(:source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"
platform = Hardware::CPU.intel? ? "darwin": "darwin-arm64"
@ -250,7 +250,7 @@ describe RuboCop::Cop::Cask::Variables do
CASK
end
let(:correct_source) do
<<-CASK.undent
<<~CASK
cask 'foo' do
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"

View File

@ -26,7 +26,7 @@ end
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/concurrent-ruby-1.2.0/lib/concurrent-ruby")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/i18n-1.12.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/minitest-5.17.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/tzinfo-2.0.5/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/tzinfo-2.0.6/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/zeitwerk-2.6.6/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/activesupport-6.1.7.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/public_suffix-5.0.1/lib")
@ -69,7 +69,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/racc-1.6.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/nokogiri-1.13.10-x86_64-darwin/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubyntlm-0.6.3/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/webrick-1.7.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/webrick-1.8.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/webrobots-0.1.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/mechanize-2.8.5/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/method_source-1.0.0/lib")
@ -119,7 +119,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/sorbet-static-and-runtime-0.5.10461/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/thor-1.2.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/spoom-1.1.11/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/yard-0.9.28/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/yard-0.9.26/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/yard-sorbet-0.6.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/tapioca-0.7.3/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/warning-1.3.0/lib")

View File

@ -1,18 +0,0 @@
# encoding: UTF-8
# frozen_string_literal: true
module TZInfo
# Object#untaint is deprecated in Ruby >= 2.7 and will be removed in 3.2.
# UntaintExt adds a refinement to make Object#untaint a no-op and avoid the
# warning.
#
# @private
module UntaintExt # :nodoc:
refine Object do
def untaint
self
end
end
end
private_constant :UntaintExt
end

View File

@ -17,12 +17,8 @@ module TZInfo
end
end
# Object#untaint is a deprecated no-op in Ruby >= 2.7 and will be removed in
# 3.2. Add a refinement to either silence the warning, or supply the method if
# needed.
if !Object.new.respond_to?(:untaint) || RUBY_VERSION =~ /\A(\d+)\.(\d+)(?:\.|\z)/ && ($1 == '2' && $2.to_i >= 7 || $1.to_i >= 3)
require_relative 'tzinfo/untaint_ext'
end
require_relative 'tzinfo/ruby_core_support'
require_relative 'tzinfo/version'

View File

@ -4,10 +4,6 @@
require 'strscan'
module TZInfo
# Use send as a workaround for erroneous 'wrong number of arguments' errors
# with JRuby 9.0.5.0 when calling methods with Java implementations. See #114.
send(:using, UntaintExt) if TZInfo.const_defined?(:UntaintExt)
module DataSources
# An {InvalidPosixTimeZone} exception is raised if an invalid POSIX-style
# time zone string is encountered.
@ -43,12 +39,12 @@ module TZInfo
s = StringScanner.new(tz_string)
check_scan(s, /([^-+,\d<][^-+,\d]*) | <([^>]+)>/x)
std_abbrev = @string_deduper.dedupe((s[1] || s[2]).untaint)
std_abbrev = @string_deduper.dedupe(RubyCoreSupport.untaint(s[1] || s[2]))
check_scan(s, /([-+]?\d+)(?::(\d+)(?::(\d+))?)?/)
std_offset = get_offset_from_hms(s[1], s[2], s[3])
if s.scan(/([^-+,\d<][^-+,\d]*) | <([^>]+)>/x)
dst_abbrev = @string_deduper.dedupe((s[1] || s[2]).untaint)
dst_abbrev = @string_deduper.dedupe(RubyCoreSupport.untaint(s[1] || s[2]))
if s.scan(/([-+]?\d+)(?::(\d+)(?::(\d+))?)?/)
dst_offset = get_offset_from_hms(s[1], s[2], s[3])

View File

@ -2,10 +2,6 @@
# frozen_string_literal: true
module TZInfo
# Use send as a workaround for erroneous 'wrong number of arguments' errors
# with JRuby 9.0.5.0 when calling methods with Java implementations. See #114.
send(:using, UntaintExt) if TZInfo.const_defined?(:UntaintExt)
module DataSources
# A {TZInfoDataNotFound} exception is raised if the tzinfo-data gem could
# not be found (i.e. `require 'tzinfo/data'` failed) when selecting the Ruby
@ -52,7 +48,7 @@ module TZInfo
data_file = File.join('', 'tzinfo', 'data.rb')
path = $".reverse_each.detect {|p| p.end_with?(data_file) }
if path
@base_path = File.join(File.dirname(path), 'data').untaint
@base_path = RubyCoreSupport.untaint(File.join(File.dirname(path), 'data'))
else
@base_path = 'tzinfo/data'
end

View File

@ -2,10 +2,6 @@
# frozen_string_literal: true
module TZInfo
# Use send as a workaround for erroneous 'wrong number of arguments' errors
# with JRuby 9.0.5.0 when calling methods with Java implementations. See #114.
send(:using, UntaintExt) if TZInfo.const_defined?(:UntaintExt)
module DataSources
# An {InvalidZoneinfoDirectory} exception is raised if {ZoneinfoDataSource}
# is initialized with a specific zoneinfo path that is not a valid zoneinfo
@ -444,7 +440,7 @@ module TZInfo
end
unless entry =~ /\./ || exclude.include?(entry)
entry.untaint
RubyCoreSupport.untaint(entry)
path = dir + [entry]
full_path = File.join(@zoneinfo_dir, *path)

View File

@ -2,10 +2,6 @@
# frozen_string_literal: true
module TZInfo
# Use send as a workaround for erroneous 'wrong number of arguments' errors
# with JRuby 9.0.5.0 when calling methods with Java implementations. See #114.
send(:using, UntaintExt) if TZInfo.const_defined?(:UntaintExt)
module DataSources
# An {InvalidZoneinfoFile} exception is raised if an attempt is made to load
# an invalid zoneinfo file.
@ -448,7 +444,7 @@ module TZInfo
abbrev_end = abbrev.index("\0", abbrev_start)
raise InvalidZoneinfoFile, "Missing abbreviation null terminator in file '#{file.path}'." unless abbrev_end
abbr = @string_deduper.dedupe(abbrev[abbrev_start...abbrev_end].force_encoding(Encoding::UTF_8).untaint)
abbr = @string_deduper.dedupe(RubyCoreSupport.untaint(abbrev[abbrev_start...abbrev_end].force_encoding(Encoding::UTF_8)))
TimezoneOffset.new(base_utc_offset, std_offset, abbr)
end

View File

@ -0,0 +1,38 @@
module TZInfo
# Methods to support different versions of Ruby.
#
# @private
module RubyCoreSupport #:nodoc:
class << self
# Object#untaint is deprecated and becomes a no-op in Ruby >= 2.7. It has
# been removed from Ruby 3.2.
if !Object.new.respond_to?(:untaint) || RUBY_VERSION =~ /\A(\d+)\.(\d+)(?:\.|\z)/ && ($1 == '2' && $2.to_i >= 7 || $1.to_i >= 3)
# :nocov_functional_untaint:
# Returns the supplied `Object`
#
# @param o [Object] the `Object` to untaint.
# @return [Object] `o`.
def untaint(o)
o
end
# :nocov_functional_untaint:
else
# :nocov_no_functional_untaint:
# Untaints and returns the supplied `Object`.
#
# @param o [Object] the `Object` to untaint.
# @return [Object] `o`.
def untaint(o)
o.untaint
end
# :nocov_no_functional_untaint:
end
end
end
private_constant :RubyCoreSupport
end

View File

@ -3,5 +3,5 @@
module TZInfo
# The TZInfo version number.
VERSION = '2.0.5'
VERSION = '2.0.6'
end

View File

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#--
# accesslog.rb -- Access log handling utilities
#

View File

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# cgi.rb -- Yet another CGI library
#

View File

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# compat.rb -- cross platform compatibility
#

View File

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# config.rb -- Default configurations.
#

View File

@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#
# cookie.rb -- Cookie class
#
@ -92,7 +92,7 @@ module WEBrick
# The cookie string suitable for use in an HTTP header
def to_s
ret = ""
ret = +""
ret << @name << "=" << @value
ret << "; " << "Version=" << @version.to_s if @version > 0
ret << "; " << "Domain=" << @domain if @domain

Some files were not shown because too many files have changed in this diff Show More