Find patch nodes nested inside blocks

This commit is contained in:
Frank Lam 2020-06-27 03:13:50 +08:00
parent b2eafdf11d
commit ffb1cc8e19
No known key found for this signature in database
GPG Key ID: 771022A2327531C7
2 changed files with 14 additions and 1 deletions

View File

@ -18,7 +18,7 @@ module RuboCop
patch_problems(url_string) patch_problems(url_string)
end end
inline_patches = find_method_calls_by_name(body, :patch) inline_patches = find_every_method_call_by_name(body, :patch)
inline_patches.each { |patch| inline_patch_problems(patch) } inline_patches.each { |patch| inline_patch_problems(patch) }
if inline_patches.empty? && patch_end? if inline_patches.empty? && patch_end?

View File

@ -175,6 +175,19 @@ describe RuboCop::Cop::FormulaAudit::Patches do
RUBY RUBY
end end
it "reports no offenses for valid nested inline patches" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
stable do
patch :DATA
end
end
__END__
patch content here
RUBY
end
it "reports an offense when DATA is found with no __END__" do it "reports an offense when DATA is found with no __END__" do
expect_offense(<<~RUBY) expect_offense(<<~RUBY)
class Foo < Formula class Foo < Formula