Merge pull request #16538 from dduugg/TopLevelMethodDefinition
Enable Style/TopLevelMethodDefinition
This commit is contained in:
commit
cfac516ee0
@ -432,6 +432,11 @@ Style/SymbolArray:
|
||||
Style/TernaryParentheses:
|
||||
EnforcedStyle: require_parentheses_when_complex
|
||||
|
||||
Style/TopLevelMethodDefinition:
|
||||
Enabled: true
|
||||
Exclude:
|
||||
- "Taps/**/*.rb"
|
||||
|
||||
# Trailing commas make diffs nicer.
|
||||
Style/TrailingCommaInArguments:
|
||||
EnforcedStyleForMultiline: comma
|
||||
|
@ -7,6 +7,7 @@
|
||||
--template-path yard/templates
|
||||
--exclude test/
|
||||
--exclude vendor/
|
||||
--exclude yard/
|
||||
extend/os/**/*.rb
|
||||
**/*.rb
|
||||
-
|
||||
|
@ -7,67 +7,6 @@ require "formulary"
|
||||
require "software_spec"
|
||||
require "tap"
|
||||
|
||||
def with_monkey_patch
|
||||
# Since `method_defined?` is not a supported type guard, the use of `alias_method` below is not typesafe:
|
||||
BottleSpecification.class_eval do
|
||||
T.unsafe(self).alias_method :old_method_missing, :method_missing if method_defined?(:method_missing)
|
||||
define_method(:method_missing) do |*|
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
Module.class_eval do
|
||||
T.unsafe(self).alias_method :old_method_missing, :method_missing if method_defined?(:method_missing)
|
||||
define_method(:method_missing) do |*|
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
Resource.class_eval do
|
||||
T.unsafe(self).alias_method :old_method_missing, :method_missing if method_defined?(:method_missing)
|
||||
define_method(:method_missing) do |*|
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
DependencyCollector.class_eval do
|
||||
T.unsafe(self).alias_method :old_parse_symbol_spec, :parse_symbol_spec if method_defined?(:parse_symbol_spec)
|
||||
define_method(:parse_symbol_spec) do |*|
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
yield
|
||||
ensure
|
||||
BottleSpecification.class_eval do
|
||||
if method_defined?(:old_method_missing)
|
||||
T.unsafe(self).alias_method :method_missing, :old_method_missing
|
||||
undef :old_method_missing
|
||||
end
|
||||
end
|
||||
|
||||
Module.class_eval do
|
||||
if method_defined?(:old_method_missing)
|
||||
T.unsafe(self).alias_method :method_missing, :old_method_missing
|
||||
undef :old_method_missing
|
||||
end
|
||||
end
|
||||
|
||||
Resource.class_eval do
|
||||
if method_defined?(:old_method_missing)
|
||||
T.unsafe(self).alias_method :method_missing, :old_method_missing
|
||||
undef :old_method_missing
|
||||
end
|
||||
end
|
||||
|
||||
DependencyCollector.class_eval do
|
||||
if method_defined?(:old_parse_symbol_spec)
|
||||
T.unsafe(self).alias_method :parse_symbol_spec, :old_parse_symbol_spec
|
||||
undef :old_parse_symbol_spec
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Homebrew
|
||||
BOTTLE_BLOCK_REGEX = / bottle (?:do.+?end|:[a-z]+)\n\n/m
|
||||
|
||||
@ -222,4 +161,65 @@ module Homebrew
|
||||
contents.sub!(BOTTLE_BLOCK_REGEX, "")
|
||||
with_monkey_patch { Formulary.from_contents(name, file, contents, ignore_errors: true) }
|
||||
end
|
||||
|
||||
private_class_method def self.with_monkey_patch
|
||||
# Since `method_defined?` is not a supported type guard, the use of `alias_method` below is not typesafe:
|
||||
BottleSpecification.class_eval do
|
||||
T.unsafe(self).alias_method :old_method_missing, :method_missing if method_defined?(:method_missing)
|
||||
define_method(:method_missing) do |*|
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
Module.class_eval do
|
||||
T.unsafe(self).alias_method :old_method_missing, :method_missing if method_defined?(:method_missing)
|
||||
define_method(:method_missing) do |*|
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
Resource.class_eval do
|
||||
T.unsafe(self).alias_method :old_method_missing, :method_missing if method_defined?(:method_missing)
|
||||
define_method(:method_missing) do |*|
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
DependencyCollector.class_eval do
|
||||
T.unsafe(self).alias_method :old_parse_symbol_spec, :parse_symbol_spec if method_defined?(:parse_symbol_spec)
|
||||
define_method(:parse_symbol_spec) do |*|
|
||||
# do nothing
|
||||
end
|
||||
end
|
||||
|
||||
yield
|
||||
ensure
|
||||
BottleSpecification.class_eval do
|
||||
if method_defined?(:old_method_missing)
|
||||
T.unsafe(self).alias_method :method_missing, :old_method_missing
|
||||
undef :old_method_missing
|
||||
end
|
||||
end
|
||||
|
||||
Module.class_eval do
|
||||
if method_defined?(:old_method_missing)
|
||||
T.unsafe(self).alias_method :method_missing, :old_method_missing
|
||||
undef :old_method_missing
|
||||
end
|
||||
end
|
||||
|
||||
Resource.class_eval do
|
||||
if method_defined?(:old_method_missing)
|
||||
T.unsafe(self).alias_method :method_missing, :old_method_missing
|
||||
undef :old_method_missing
|
||||
end
|
||||
end
|
||||
|
||||
DependencyCollector.class_eval do
|
||||
if method_defined?(:old_parse_symbol_spec)
|
||||
T.unsafe(self).alias_method :parse_symbol_spec, :old_parse_symbol_spec
|
||||
undef :old_parse_symbol_spec
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,20 +2,20 @@
|
||||
|
||||
require "cli/named_args"
|
||||
|
||||
def setup_unredable_formula(name)
|
||||
describe Homebrew::CLI::NamedArgs do
|
||||
def setup_unredable_formula(name)
|
||||
error = FormulaUnreadableError.new(name, RuntimeError.new("testing"))
|
||||
allow(Formulary).to receive(:factory).with(name, any_args).and_raise(error)
|
||||
end
|
||||
end
|
||||
|
||||
def setup_unredable_cask(name)
|
||||
def setup_unredable_cask(name)
|
||||
error = Cask::CaskUnreadableError.new(name, "testing")
|
||||
allow(Cask::CaskLoader).to receive(:load).with(name, any_args).and_raise(error)
|
||||
|
||||
config = instance_double(Cask::Config)
|
||||
allow(Cask::Config).to receive(:from_args).and_return(config)
|
||||
end
|
||||
end
|
||||
|
||||
describe Homebrew::CLI::NamedArgs do
|
||||
let(:foo) do
|
||||
formula "foo" do
|
||||
url "https://brew.sh"
|
||||
|
@ -4,6 +4,32 @@ require "cmd/shared_examples/args_parse"
|
||||
require "dev-cmd/bottle"
|
||||
|
||||
describe "brew bottle" do
|
||||
def stub_hash(parameters)
|
||||
<<~EOS
|
||||
{
|
||||
"#{parameters[:name]}":{
|
||||
"formula":{
|
||||
"pkg_version":"#{parameters[:version]}",
|
||||
"path":"#{parameters[:path]}"
|
||||
},
|
||||
"bottle":{
|
||||
"root_url":"#{parameters[:root_url] || HOMEBREW_BOTTLE_DEFAULT_DOMAIN}",
|
||||
"prefix":"/usr/local",
|
||||
"cellar":"#{parameters[:cellar]}",
|
||||
"rebuild":0,
|
||||
"tags":{
|
||||
"#{parameters[:os]}":{
|
||||
"filename":"#{parameters[:filename]}",
|
||||
"local_filename":"#{parameters[:local_filename]}",
|
||||
"sha256":"#{parameters[:sha256]}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOS
|
||||
end
|
||||
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
it "builds a bottle for the given Formula", :integration_test do
|
||||
@ -538,29 +564,3 @@ describe "brew bottle" do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def stub_hash(parameters)
|
||||
<<~EOS
|
||||
{
|
||||
"#{parameters[:name]}":{
|
||||
"formula":{
|
||||
"pkg_version":"#{parameters[:version]}",
|
||||
"path":"#{parameters[:path]}"
|
||||
},
|
||||
"bottle":{
|
||||
"root_url":"#{parameters[:root_url] || HOMEBREW_BOTTLE_DEFAULT_DOMAIN}",
|
||||
"prefix":"/usr/local",
|
||||
"cellar":"#{parameters[:cellar]}",
|
||||
"rebuild":0,
|
||||
"tags":{
|
||||
"#{parameters[:os]}":{
|
||||
"filename":"#{parameters[:filename]}",
|
||||
"local_filename":"#{parameters[:local_filename]}",
|
||||
"sha256":"#{parameters[:sha256]}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOS
|
||||
end
|
||||
|
@ -4,6 +4,14 @@ require "dev-cmd/determine-test-runners"
|
||||
require "cmd/shared_examples/args_parse"
|
||||
|
||||
describe "brew determine-test-runners" do
|
||||
def get_runners(file)
|
||||
runner_line = File.open(file).first
|
||||
json_text = runner_line[/runners=(.*)/, 1]
|
||||
runner_hash = JSON.parse(json_text)
|
||||
runner_hash.map { |item| item["runner"].delete_suffix(ephemeral_suffix) }
|
||||
.sort
|
||||
end
|
||||
|
||||
after do
|
||||
FileUtils.rm_f github_output
|
||||
end
|
||||
@ -48,14 +56,6 @@ describe "brew determine-test-runners" do
|
||||
end
|
||||
end
|
||||
|
||||
def get_runners(file)
|
||||
runner_line = File.open(file).first
|
||||
json_text = runner_line[/runners=(.*)/, 1]
|
||||
runner_hash = JSON.parse(json_text)
|
||||
runner_hash.map { |item| item["runner"].delete_suffix(ephemeral_suffix) }
|
||||
.sort
|
||||
end
|
||||
|
||||
class DetermineRunnerTestHelper
|
||||
@instances = 0
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
# This follows the docs at https://github.com/lsegal/yard/blob/main/docs/Templates.md#setuprb
|
||||
# rubocop:disable Style/TopLevelMethodDefinition
|
||||
def init
|
||||
# `sorbet` is available transitively through the `yard-sorbet` plugin, but we're
|
||||
# outside of the standalone sorbet config, so `checked` is enabled by default
|
||||
@ -16,3 +18,4 @@ def internal
|
||||
T.bind(self, YARD::Templates::Template, checked: false)
|
||||
erb(:internal) if object.has_tag?(:api) && object.tag(:api).text == "internal"
|
||||
end
|
||||
# rubocop:enable Style/TopLevelMethodDefinition
|
||||
|
Loading…
x
Reference in New Issue
Block a user