Merge branch 'master' into create-cop-for-os-checks

This commit is contained in:
apainintheneck 2022-11-29 23:14:15 -08:00
commit 00990e34a7
236 changed files with 494 additions and 314 deletions

67
.github/workflows/docs.yml vendored Normal file
View File

@ -0,0 +1,67 @@
name: Documentation CI
on:
push:
branches:
- master
pull_request:
permissions:
contents: read
jobs:
linting:
if: github.repository == 'Homebrew/brew'
runs-on: ubuntu-22.04
defaults:
run:
working-directory: docs
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Install vale
run: brew install vale
- name: Run vale for docs linting
run: vale .
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7"
bundler-cache: true
working-directory: docs
- name: Check Markdown syntax
run: bundle exec rake lint
- name: Build docs site
run: bundle exec rake build
rubydoc:
if: github.repository == 'Homebrew/brew'
runs-on: ubuntu-22.04
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/rubydoc/Gemfile
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Checkout Homebrew/rubydoc.brew.sh
uses: actions/checkout@main
with:
repository: Homebrew/rubydoc.brew.sh
path: rubydoc
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7"
bundler-cache: true
- name: Process rubydoc comments
working-directory: Library/Homebrew
run: bundle exec yard doc --plugin sorbet --no-output #--fail-on-warning

View File

@ -13,14 +13,19 @@ permissions:
env:
HOMEBREW_DEVELOPER: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_CHANGE_ARCH_TO_ARM: 1
jobs:
tests:
strategy:
matrix:
version: ["12-arm64", "12", "11-arm64", "11", "10.15"]
runner:
- "13-arm64-${{github.run_id}}-${{github.run_attempt}}"
- "12-arm64"
- "12-${{github.run_id}}-${{github.run_attempt}}"
- "11-arm64"
- "11-${{github.run_id}}-${{github.run_attempt}}"
- "10.15-${{github.run_id}}-${{github.run_attempt}}"
fail-fast: false
runs-on: ${{ matrix.version }}
runs-on: ${{ matrix.runner }}
env:
PATH: "/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
defaults:
@ -32,8 +37,9 @@ jobs:
uses: Homebrew/actions/setup-homebrew@master
- run: brew test-bot --only-cleanup-before
if: !contains(matrix.runner, github.run_id)
- run: brew test-bot --only-setup
- run: brew doctor
- run: brew test-bot --only-cleanup-after
if: always()
if: always() && !contains(matrix.runner, github.run_id)

View File

@ -37,18 +37,13 @@ jobs:
- name: Install Bundler RubyGems
run: brew install-bundler-gems --groups=sorbet
- name: Install shellcheck
run: brew install shellcheck
- name: Install shellcheck and shfmt
run: brew install shellcheck shfmt
- run: brew style --display-cop-names
- run: brew typecheck
- name: Run vale for docs linting
run: |
brew install vale
vale docs/
tap-syntax:
name: tap syntax
needs: syntax
@ -282,6 +277,7 @@ jobs:
test-default-formula-linux:
name: ${{ matrix.name }}
if: startsWith(github.repository, 'Homebrew/')
runs-on: ${{ matrix.runs-on }}
env:
HOMEBREW_BOOTSNAP: 1

View File

@ -11,8 +11,6 @@ Style/Documentation:
- "default_prefix.rb"
- "global.rb"
- "keg_relocate.rb"
- "os/linux/global.rb"
- "os/mac/global.rb"
- "os/mac/keg.rb"
- "reinstall.rb"
- "software_spec.rb"
@ -27,7 +25,6 @@ Style/Documentation:
Lint/EmptyBlock:
Exclude:
- "dependency.rb"
- "dev-cmd/extract.rb"
- "test/cache_store_spec.rb"
- "test/checksum_verification_spec.rb"

View File

@ -11,7 +11,7 @@ GEM
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
bindata (2.4.14)
bootsnap (1.14.0)
bootsnap (1.15.0)
msgpack (~> 1.2)
byebug (11.1.3)
coderay (1.1.3)
@ -82,7 +82,7 @@ GEM
parser
rainbow (~> 3.0)
sorbet-runtime (>= 0.5)
parser (3.1.2.1)
parser (3.1.3.0)
ast (~> 2.4.1)
patchelf (1.4.0)
elftools (>= 1.2)
@ -92,7 +92,7 @@ GEM
method_source (~> 1.0)
public_suffix (5.0.0)
racc (1.6.0)
rack (3.0.0)
rack (3.0.1)
rainbow (3.1.1)
rbi (0.0.14)
ast
@ -147,7 +147,7 @@ GEM
rubocop-performance (1.15.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.17.2)
rubocop-rails (2.17.3)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)

View File

@ -13,26 +13,6 @@ case "${HOMEBREW_SYSTEM}" in
Linux) HOMEBREW_LINUX="1" ;;
esac
if [[ "${HOMEBREW_MACOS}" == "1" ]] &&
[[ "$(sysctl -n hw.optional.arm64 2>/dev/null)" == "1" ]]
then
# used in vendor-install.sh
# shellcheck disable=SC2034
HOMEBREW_PHYSICAL_PROCESSOR="arm64"
HOMEBREW_ROSETTA="$(sysctl -n sysctl.proc_translated)"
# If we're running under macOS Rosetta 2, and it was requested by setting
# HOMEBREW_CHANGE_ARCH_TO_ARM (for example in CI), then we re-exec this
# same file under the native architecture
# These variables are set from the user environment.
# shellcheck disable=SC2154
if [[ "${HOMEBREW_CHANGE_ARCH_TO_ARM}" == "1" ]] &&
[[ "${HOMEBREW_ROSETTA}" == "1" ]]
then
exec arch -arm64e "${HOMEBREW_BREW_FILE}" "$@"
fi
fi
# Where we store built products; a Cellar in HOMEBREW_PREFIX (often /usr/local
# for bottles) unless there's already a Cellar in HOMEBREW_REPOSITORY.
# These variables are set by bin/brew
@ -170,6 +150,8 @@ safe_cd() {
}
brew() {
# This variable is set by bin/brew
# shellcheck disable=SC2154
"${HOMEBREW_BREW_FILE}" "$@"
}
@ -442,6 +424,13 @@ then
# Don't change this from Mac OS X to match what macOS itself does in Safari on 10.12
HOMEBREW_OS_USER_AGENT_VERSION="Mac OS X ${HOMEBREW_MACOS_VERSION}"
if [[ "$(sysctl -n hw.optional.arm64 2>/dev/null)" == "1" ]]
then
# used in vendor-install.sh
# shellcheck disable=SC2034
HOMEBREW_PHYSICAL_PROCESSOR="arm64"
fi
# Intentionally set this variable by exploding another.
# shellcheck disable=SC2086,SC2183
printf -v HOMEBREW_MACOS_VERSION_NUMERIC "%02d%02d%02d" ${HOMEBREW_MACOS_VERSION//./ }

View File

@ -8,5 +8,5 @@
source "${HOMEBREW_LIBRARY}/Homebrew/items.sh"
homebrew-casks() {
homebrew-items 'Formula' 's|/Casks/|/|' '^homebrew/cask'
homebrew-items '*/Casks/*\.rb' '' 's|/Casks/|/|' '^homebrew/cask'
}

View File

@ -8,5 +8,5 @@
source "${HOMEBREW_LIBRARY}/Homebrew/items.sh"
homebrew-formulae() {
homebrew-items 'Casks' 's|/Formula/|/|' '^homebrew/core'
homebrew-items '*\.rb' 'Casks' 's|/Formula/|/|' '^homebrew/core'
}

View File

@ -41,7 +41,7 @@ module Homebrew
flag "--version=",
description: "Specify the new <version> for the cask."
flag "--message=",
description: "Append <message> to the default pull request message."
description: "Prepend <message> to the default pull request message."
flag "--url=",
description: "Specify the <URL> for the new download."
flag "--sha256=",

View File

@ -60,7 +60,7 @@ module Homebrew
"that `--version=0` can be used to delete an existing version override from a " \
"formula if it has become redundant."
flag "--message=",
description: "Append <message> to the default pull request message."
description: "Prepend <message> to the default pull request message."
flag "--url=",
description: "Specify the <URL> for the new download. If a <URL> is specified, the <SHA-256> " \
"checksum of the new download should also be specified."

View File

@ -181,32 +181,6 @@ module Homebrew
EOS
end
# Anaconda installs multiple system & brew dupes, including OpenSSL, Python,
# sqlite, libpng, Qt, etc. Regularly breaks compile on Vim, MacVim and others.
# Is flagged as part of the *-config script checks below, but people seem
# to ignore those as warnings rather than extremely likely breakage.
def check_for_anaconda
return unless which("anaconda")
return unless which("python")
anaconda_directory = which("anaconda").realpath.dirname
python_binary = Utils.popen_read(which("python"), "-c", "import sys; sys.stdout.write(sys.executable)")
python_directory = Pathname.new(python_binary).realpath.dirname
# Only warn if Python lives with Anaconda, since is most problematic case.
return unless python_directory == anaconda_directory
<<~EOS
Anaconda is known to frequently break Homebrew builds, including Vim and
MacVim, due to bundling many duplicates of system and Homebrew-provided
tools.
If you encounter a build failure please temporarily remove Anaconda
from your $PATH and attempt the build again prior to reporting the
failure to us. Thanks!
EOS
end
def __check_stray_files(dir, pattern, allow_list, message)
return unless File.directory?(dir)
@ -477,54 +451,6 @@ module Homebrew
EOS
end
def check_for_config_scripts
return unless HOMEBREW_CELLAR.exist?
real_cellar = HOMEBREW_CELLAR.realpath
scripts = []
allowlist = %W[
/bin /sbin
/usr/bin /usr/sbin
/usr/X11/bin /usr/X11R6/bin /opt/X11/bin
#{HOMEBREW_PREFIX}/bin #{HOMEBREW_PREFIX}/sbin
/Applications/Server.app/Contents/ServerRoot/usr/bin
/Applications/Server.app/Contents/ServerRoot/usr/sbin
]
if OS.mac? && Hardware::CPU.physical_cpu_arm64?
allowlist += %W[
#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/bin
#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/sbin
#{HOMEBREW_DEFAULT_PREFIX}/bin
#{HOMEBREW_DEFAULT_PREFIX}/sbin
]
end
allowlist.map!(&:downcase)
paths.each do |p|
next if allowlist.include?(p.downcase) || !File.directory?(p)
realpath = Pathname.new(p).realpath.to_s
next if realpath.start_with?(real_cellar.to_s, HOMEBREW_CELLAR.to_s)
scripts += Dir.chdir(p) { Dir["*-config"] }.map { |c| File.join(p, c) }
end
return if scripts.empty?
inject_file_list scripts, <<~EOS
"config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and which additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew-provided
script of the same name. We found the following "config" scripts:
EOS
end
def check_for_symlinked_cellar
return unless HOMEBREW_CELLAR.exist?
return unless HOMEBREW_CELLAR.symlink?

View File

@ -471,7 +471,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
lines = output.to_s.lines.map(&:chomp)
final_url = curl_response_last_location(parsed_output[:responses], absolutize: true, base_url: url)
final_url = curl_response_follow_redirections(parsed_output[:responses], url)
final_url ||= url
content_disposition_parser = Mechanize::HTTP::ContentDispositionParser.new

View File

@ -1,9 +1,10 @@
homebrew-items() {
local items
local sed_extended_regex_flag
local find_filter="$1"
local sed_filter="$2"
local grep_filter="$3"
local find_include_filter="$1"
local find_exclude_filter="$2"
local sed_filter="$3"
local grep_filter="$4"
# HOMEBREW_MACOS is set by brew.sh
# shellcheck disable=SC2154
@ -19,14 +20,14 @@ homebrew-items() {
items="$(
find "${HOMEBREW_REPOSITORY}/Library/Taps" \
-type d \( \
-name "${find_filter}" -o \
-name "${find_exclude_filter}" -o \
-name cmd -o \
-name .github -o \
-name lib -o \
-name spec -o \
-name vendor \
\) \
-prune -false -o -name '*\.rb' |
-prune -false -o -path "${find_include_filter}" |
sed "${sed_extended_regex_flag}" \
-e 's/\.rb//g' \
-e 's_.*/Taps/(.*)/(home|linux)brew-_\1/_' \

View File

@ -18,7 +18,7 @@ module Bootsnap
def logger; end
def logger=(logger); end
def rb_get_path(fname); end
def setup(cache_dir:, development_mode: T.unsafe(nil), load_path_cache: T.unsafe(nil), ignore_directories: T.unsafe(nil), compile_cache_iseq: T.unsafe(nil), compile_cache_yaml: T.unsafe(nil), compile_cache_json: T.unsafe(nil)); end
def setup(cache_dir:, development_mode: T.unsafe(nil), load_path_cache: T.unsafe(nil), ignore_directories: T.unsafe(nil), readonly: T.unsafe(nil), compile_cache_iseq: T.unsafe(nil), compile_cache_yaml: T.unsafe(nil), compile_cache_json: T.unsafe(nil)); end
def unload_cache!; end
end
end
@ -26,7 +26,7 @@ end
module Bootsnap::CompileCache
class << self
def permission_error(path); end
def setup(cache_dir:, iseq:, yaml:, json:); end
def setup(cache_dir:, iseq:, yaml:, json:, readonly: T.unsafe(nil)); end
def supported?; end
end
end
@ -54,7 +54,7 @@ module Bootsnap::LoadPathCache
def enabled?; end
def load_path_cache; end
def loaded_features_index; end
def setup(cache_path:, development_mode:, ignore_directories:); end
def setup(cache_path:, development_mode:, ignore_directories:, readonly: T.unsafe(nil)); end
def supported?; end
def unload!; end
end
@ -193,7 +193,7 @@ Bootsnap::LoadPathCache::PathScanner::REQUIRABLE_EXTENSIONS = T.let(T.unsafe(nil
Bootsnap::LoadPathCache::SLASH = T.let(T.unsafe(nil), String)
class Bootsnap::LoadPathCache::Store
def initialize(store_path); end
def initialize(store_path, readonly: T.unsafe(nil)); end
def fetch(key); end
def get(key); end

View File

@ -59,6 +59,8 @@ class Parser::AST::Processor < ::AST::Processor
def on_find_pattern(node); end
def on_for(node); end
def on_forward_arg(node); end
def on_forwarded_kwrestarg(node); end
def on_forwarded_restarg(node); end
def on_gvar(node); end
def on_gvasgn(node); end
def on_hash(node); end
@ -235,6 +237,8 @@ class Parser::Builders::Default
def forward_arg(dots_t); end
def forward_only_args(begin_t, dots_t, end_t); end
def forwarded_args(dots_t); end
def forwarded_kwrestarg(dstar_t); end
def forwarded_restarg(star_t); end
def gvar(token); end
def hash_pattern(lbrace_t, kwargs, rbrace_t); end
def ident(token); end
@ -520,6 +524,7 @@ class Parser::Lexer
def static_env=(_arg0); end
def tokens; end
def tokens=(_arg0); end
def version; end
protected
@ -528,6 +533,7 @@ class Parser::Lexer
def emit(type, value = T.unsafe(nil), s = T.unsafe(nil), e = T.unsafe(nil)); end
def emit_comment(s = T.unsafe(nil), e = T.unsafe(nil)); end
def emit_do(do_block = T.unsafe(nil)); end
def emit_invalid_escapes?; end
def emit_table(table, s = T.unsafe(nil), e = T.unsafe(nil)); end
def encode_escape(ord); end
def eof_codepoint?(point); end
@ -1610,9 +1616,13 @@ class Parser::StaticEnvironment
def declare(name); end
def declare_anonymous_blockarg; end
def declare_anonymous_kwrestarg; end
def declare_anonymous_restarg; end
def declare_forward_args; end
def declared?(name); end
def declared_anonymous_blockarg?; end
def declared_anonymous_kwrestarg?; end
def declared_anonymous_restarg?; end
def declared_forward_args?; end
def empty?; end
def extend_dynamic; end
@ -1622,6 +1632,8 @@ class Parser::StaticEnvironment
end
Parser::StaticEnvironment::ANONYMOUS_BLOCKARG = T.let(T.unsafe(nil), Symbol)
Parser::StaticEnvironment::ANONYMOUS_KWRESTARG = T.let(T.unsafe(nil), Symbol)
Parser::StaticEnvironment::ANONYMOUS_RESTARG = T.let(T.unsafe(nil), Symbol)
Parser::StaticEnvironment::FORWARD_ARGS = T.let(T.unsafe(nil), Symbol)
class Parser::SyntaxError < ::StandardError

View File

@ -496,10 +496,13 @@ class Rack::Lint::Wrapper
def respond_to?(name, *_arg1); end
def response; end
def to_ary; end
def to_path; end
def verify_content_length(size); end
def verify_to_path; end
end
Rack::Lint::Wrapper::BODY_METHODS = T.let(T.unsafe(nil), Hash)
class Rack::Lint::Wrapper::ErrorWrapper
def initialize(error); end

View File

@ -178,6 +178,7 @@ RuboCop::Cop::Rails::ActionFilter::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array
class RuboCop::Cop::Rails::ActionOrder < ::RuboCop::Cop::Base
include ::RuboCop::Cop::VisibilityHelp
include ::RuboCop::Cop::DefNode
include ::RuboCop::Cop::RangeHelp
extend ::RuboCop::Cop::AutoCorrector
def action_declarations(param0, param1); end
@ -186,9 +187,14 @@ class RuboCop::Cop::Rails::ActionOrder < ::RuboCop::Cop::Base
private
def actions; end
def add_range(range1, range2); end
def correction_target(def_node); end
def expected_order; end
def find_index(node); end
def range_with_comments(node); end
def range_with_comments_and_lines(node); end
def register_offense(previous, current); end
def swap_range(corrector, range1, range2); end
end
RuboCop::Cop::Rails::ActionOrder::MSG = T.let(T.unsafe(nil), String)
@ -695,6 +701,9 @@ class RuboCop::Cop::Rails::DynamicFindBy < ::RuboCop::Cop::Base
def autocorrect_argument_keywords(corrector, node, keywords); end
def autocorrect_method_name(corrector, node); end
def column_keywords(method); end
def dynamic_find_by_arguments?(node); end
def dynamic_find_by_arguments_count?(node); end
def dynamic_find_by_arguments_type?(node); end
def static_method_name(method_name); end
def whitelisted?(node); end
end
@ -921,7 +930,7 @@ class RuboCop::Cop::Rails::FreezeTime < ::RuboCop::Cop::Base
def current_time_with_convert?(node, method_name); end
end
RuboCop::Cop::Rails::FreezeTime::CONV_METHODS = T.let(T.unsafe(nil), Array)
RuboCop::Cop::Rails::FreezeTime::CONVERT_METHODS = T.let(T.unsafe(nil), Array)
RuboCop::Cop::Rails::FreezeTime::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::Rails::FreezeTime::NOW_METHODS = T.let(T.unsafe(nil), Array)
RuboCop::Cop::Rails::FreezeTime::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
@ -1061,6 +1070,7 @@ class RuboCop::Cop::Rails::I18nLazyLookup < ::RuboCop::Cop::Base
end
RuboCop::Cop::Rails::I18nLazyLookup::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::Rails::I18nLazyLookup::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
class RuboCop::Cop::Rails::I18nLocaleAssignment < ::RuboCop::Cop::Base
def i18n_locale_assignment?(param0 = T.unsafe(nil)); end
@ -1775,7 +1785,8 @@ class RuboCop::Cop::Rails::RootPathnameMethods < ::RuboCop::Cop::Base
private
def build_path_glob(path, method); end
def build_path_glob_replacement(path, method); end
def build_path_replacement(path, method, args); end
def evidence(node); end
def include_interpolation?(arguments); end
def join_arguments(arguments); end
@ -2047,8 +2058,13 @@ class RuboCop::Cop::Rails::ToSWithArgument < ::RuboCop::Cop::Base
def on_csend(node); end
def on_send(node); end
private
def rails_extended_to_s?(node); end
end
RuboCop::Cop::Rails::ToSWithArgument::EXTENDED_FORMAT_TYPES = T.let(T.unsafe(nil), Set)
RuboCop::Cop::Rails::ToSWithArgument::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::Rails::ToSWithArgument::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)

View File

@ -6723,6 +6723,10 @@ class RuboCop::AST::Node
def cask_block?(param0=T.unsafe(nil)); end
def forwarded_kwrestarg_type?(); end
def forwarded_restarg_type?(); end
def key_node(param0=T.unsafe(nil)); end
def method_node(param0=T.unsafe(nil)); end
@ -6742,11 +6746,18 @@ module RuboCop::AST::NodePattern::Sets
SET_INCLUDE_WITH_WITHOUT = ::T.let(nil, ::T.untyped)
SET_ON_INTEL_ON_ARM = ::T.let(nil, ::T.untyped)
SET_OR_NEWER_OR_OLDER = ::T.let(nil, ::T.untyped)
SET_STDOUT_STDERR = ::T.let(nil, ::T.untyped)
SET_SYSTEM_SHELL_OUTPUT_PIPE_OUTPUT = ::T.let(nil, ::T.untyped)
SET_WITH_WITHOUT = ::T.let(nil, ::T.untyped)
SET____ETC_4 = ::T.let(nil, ::T.untyped)
end
module RuboCop::AST::Traversal
def on_forwarded_kwrestarg(node); end
def on_forwarded_restarg(node); end
end
class RuboCop::Cask::AST::Stanza
def app?(); end

View File

@ -11,21 +11,6 @@ describe Homebrew::Diagnostic::Checks do
expect(checks.inject_file_list(%w[/a /b], "foo:\n")).to eq("foo:\n /a\n /b\n")
end
specify "#check_for_anaconda" do
mktmpdir do |path|
anaconda = "#{path}/anaconda"
python = "#{path}/python"
FileUtils.touch anaconda
File.write(python, "#! #{`which bash`}\necho -n '#{python}'\n")
FileUtils.chmod 0755, anaconda
FileUtils.chmod 0755, python
ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV.fetch("PATH")}"
expect(checks.check_for_anaconda).to match("Anaconda")
end
end
specify "#check_access_directories" do
skip "User is root so everything is writable." if Process.euid.zero?
begin
@ -90,19 +75,6 @@ describe Homebrew::Diagnostic::Checks do
sbin.rmtree
end
specify "#check_for_config_scripts" do
mktmpdir do |tmp|
file = "#{tmp}/foo-config"
FileUtils.touch file
FileUtils.chmod 0755, file
homebrew_path = "#{tmp}#{File::PATH_SEPARATOR}#{ENV.fetch("PATH")}"
stub_const("ORIGINAL_PATHS", PATH.new(homebrew_path).map { |path| Pathname.new(path).expand_path }.compact)
expect(checks.check_for_config_scripts)
.to match('"config" scripts exist')
end
end
specify "#check_for_symlinked_cellar" do
HOMEBREW_CELLAR.rmtree

View File

@ -556,4 +556,58 @@ describe "Utils::Curl" do
expect(curl_response_last_location([response_hash[:ok]])).to be_nil
end
end
describe "#curl_response_follow_redirections" do
it "returns the original URL when there are no location headers" do
expect(
curl_response_follow_redirections(
[response_hash[:ok]],
"https://brew.sh/test1/test2",
),
).to eq("https://brew.sh/test1/test2")
end
it "returns the URL relative to base when locations are relative" do
expect(
curl_response_follow_redirections(
[response_hash[:redirection_root_relative], response_hash[:ok]],
"https://brew.sh/test1/test2",
),
).to eq("https://brew.sh/example/")
expect(
curl_response_follow_redirections(
[response_hash[:redirection_parent_relative], response_hash[:ok]],
"https://brew.sh/test1/test2",
),
).to eq("https://brew.sh/test1/example/")
expect(
curl_response_follow_redirections(
[
response_hash[:redirection_parent_relative],
response_hash[:redirection_parent_relative],
response_hash[:ok],
],
"https://brew.sh/test1/test2",
),
).to eq("https://brew.sh/test1/example/example/")
end
it "returns new base when there are absolute location(s)" do
expect(
curl_response_follow_redirections(
[response_hash[:redirection], response_hash[:ok]],
"https://brew.sh/test1/test2",
),
).to eq(location_urls[0])
expect(
curl_response_follow_redirections(
[response_hash[:redirection], response_hash[:redirection_parent_relative], response_hash[:ok]],
"https://brew.sh/test1/test2",
),
).to eq("#{location_urls[0]}example/")
end
end
end

View File

@ -506,6 +506,30 @@ module Utils
nil
end
# Returns the final URL by following location headers in cURL responses.
# @param responses [Array<Hash>] An array of hashes containing response
# status information and headers from `#parse_curl_response`.
# @param base_url [String] The URL to use as a base.
# @return [String] The final absolute URL after redirections.
sig {
params(
responses: T::Array[T::Hash[Symbol, T.untyped]],
base_url: String,
).returns(String)
}
def curl_response_follow_redirections(responses, base_url)
responses.each do |response|
next if response[:headers].blank?
location = response[:headers]["location"]
next if location.blank?
base_url = URI.join(base_url, location).to_s
end
base_url
end
private
# Parses HTTP response text from `curl` output into a hash containing the

View File

@ -35,8 +35,8 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/bindata-2.4.14/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/universal-darwin-21/#{Gem.extension_api_version}/msgpack-1.6.0")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/msgpack-1.6.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/universal-darwin-21/#{Gem.extension_api_version}/bootsnap-1.14.0")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/bootsnap-1.14.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/universal-darwin-21/#{Gem.extension_api_version}/bootsnap-1.15.0")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/bootsnap-1.15.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/universal-darwin-21/#{Gem.extension_api_version}/byebug-11.1.3")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/byebug-11.1.3/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/coderay-1.1.3/lib")
@ -76,14 +76,14 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/mustache-1.1.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/parallel-1.22.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/parallel_tests-3.13.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/parser-3.1.2.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/parser-3.1.3.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rainbow-3.1.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/sorbet-runtime-0.5.10461/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/parlour-8.0.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/patchelf-1.4.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/plist-3.6.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/pry-0.14.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rack-3.0.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rack-3.0.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/unparser-0.6.4/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rbi-0.0.14/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/universal-darwin-21/#{Gem.extension_api_version}/rdiscount-2.2.7")
@ -106,7 +106,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/unicode-display_width-2.3.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-1.35.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.15.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.17.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.17.3/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.15.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.6.11/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-macho-3.0.0/lib")

View File

@ -817,8 +817,14 @@ module Rack
verify_to_path
end
BODY_METHODS = {to_ary: true, each: true, call: true, to_path: true}
def to_path
@body.to_path
end
def respond_to?(name, *)
if name == :to_ary
if BODY_METHODS.key?(name)
@body.respond_to?(name)
else
super

View File

@ -46,7 +46,7 @@ module Rack
end
def method_override_param(req)
req.POST[METHOD_OVERRIDE_PARAM_KEY]
req.POST[METHOD_OVERRIDE_PARAM_KEY] if req.form_data? || req.parseable_data?
rescue Utils::InvalidParameterError, Utils::ParameterTypeError
req.get_header(RACK_ERRORS).puts "Invalid or incomplete POST params"
rescue EOFError

View File

@ -25,7 +25,7 @@ module Rack
VERSION
end
RELEASE = "3.0.0"
RELEASE = "3.0.1"
# Return the Rack release as a dotted string.
def self.release

View File

@ -1,41 +0,0 @@
# frozen_string_literal: true
module RuboCop
module Cop
module Rails
# Identifies passing any argument to `#to_s`.
#
# @safety
# This cop is marked as unsafe because it may detect `#to_s` calls
# that are not related to Active Support implementation.
#
# @example
#
# # bad
# obj.to_s(:delimited)
#
# # good
# obj.to_formatted_s(:delimited)
#
class ToSWithArgument < Base
extend AutoCorrector
extend TargetRailsVersion
MSG = 'Use `to_formatted_s` instead.'
RESTRICT_ON_SEND = %i[to_s].freeze
minimum_target_rails_version 7.0
def on_send(node)
return if node.arguments.empty?
add_offense(node.loc.selector) do |corrector|
corrector.replace(node.loc.selector, 'to_formatted_s')
end
end
alias on_csend on_send
end
end
end
end

View File

@ -540,7 +540,7 @@ Rails/I18nLazyLookup:
Enabled: pending
VersionAdded: '2.14'
Include:
- 'controllers/**/*'
- 'app/controllers/**/*.rb'
Rails/I18nLocaleAssignment:
Description: 'Prefer the usage of `I18n.with_locale` instead of manually updating `I18n.locale` value.'

View File

@ -10,8 +10,8 @@ module RuboCop
def_node_matcher :active_record?, <<~PATTERN
{
(const nil? :ApplicationRecord)
(const (const nil? :ActiveRecord) :Base)
(const {nil? cbase} :ApplicationRecord)
(const (const {nil? cbase} :ActiveRecord) :Base)
}
PATTERN

View File

@ -134,7 +134,7 @@ module RuboCop
end
def self.from_hash_brackets_map(node, match)
new(match, node.children.last, 'Hash['.length, ']'.length)
new(match, node.children.last, "#{node.receiver.source}[".length, ']'.length)
end
def strip_prefix_and_suffix(node, corrector)

View File

@ -8,7 +8,7 @@ module RuboCop
def_node_matcher :migration_class?, <<~PATTERN
(class
(const nil? _)
(const {nil? cbase} _)
(send
(const (const {nil? cbase} :ActiveRecord) :Migration)
:[]

View File

@ -43,8 +43,8 @@ module RuboCop
def_node_search :action_controller?, <<~PATTERN
{
(const nil? :ApplicationController)
(const (const nil? :ActionController) :Base)
(const {nil? cbase} :ApplicationController)
(const (const {nil? cbase} :ActionController) :Base)
}
PATTERN
@ -69,9 +69,12 @@ module RuboCop
def followed_by_render?(flash_node)
flash_assigment_node = find_ancestor(flash_node, type: :send)
context = flash_assigment_node
context = context.parent if context.parent.if_type?
if (if_node = context.each_ancestor(:if).first)
context = if_node
elsif context.right_siblings.empty?
return true
end
context = context.right_siblings
return true if context.empty?
context.compact.any? do |node|
render?(node)

View File

@ -30,7 +30,7 @@ module RuboCop
def_node_matcher :action_controller_test_case?, <<~PATTERN
(class
(const nil? _)
(const {nil? cbase} _)
(const (const {nil? cbase} :ActionController) :TestCase) _)
PATTERN

View File

@ -6,7 +6,8 @@ module RuboCop
# Enforces consistent ordering of the standard Rails RESTful controller actions.
#
# The cop is configurable and can enforce any ordering of the standard actions.
# All other methods are ignored.
# All other methods are ignored. So, the actions specified in `ExpectedOrder` should be
# defined before actions not specified.
#
# [source,yaml]
# ----
@ -35,6 +36,7 @@ module RuboCop
extend AutoCorrector
include VisibilityHelp
include DefNode
include RangeHelp
MSG = 'Action `%<current>s` should appear before `%<previous>s`.'
@ -71,10 +73,44 @@ module RuboCop
current: current.method_name
)
add_offense(current, message: message) do |corrector|
corrector.replace(current, previous.source)
corrector.replace(previous, current.source)
current = correction_target(current)
previous = correction_target(previous)
swap_range(corrector, current, previous)
end
end
def correction_target(def_node)
range_with_comments_and_lines(def_node.each_ancestor(:if).first || def_node)
end
def add_range(range1, range2)
range1.with(
begin_pos: [range1.begin_pos, range2.begin_pos].min,
end_pos: [range1.end_pos, range2.end_pos].max
)
end
def range_with_comments(node)
ranges = [
node,
*processed_source.ast_with_comments[node]
].map do |element|
element.location.expression
end
ranges.reduce do |result, range|
add_range(result, range)
end
end
def range_with_comments_and_lines(node)
range_by_whole_lines(range_with_comments(node), include_final_newline: true)
end
def swap_range(corrector, range1, range2)
corrector.insert_before(range2, range1.source)
corrector.remove(range1)
end
end
end
end

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