Skip to content

Commit

Permalink
Merge pull request #139 from Shopify/fix-sig-final-false-positive
Browse files Browse the repository at this point in the history
  • Loading branch information
sambostock authored Feb 3, 2023
2 parents 38eeb8c + e8a9337 commit e57f642
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/rubocop/cop/sorbet/signatures/signature_cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class SignatureCop < RuboCop::Cop::Cop
@registry = Cop.registry # So we can properly subclass this cop

def_node_matcher(:signature?, <<~PATTERN)
(block (send #allowed_recv :sig) (args) ...)
(block (send
{nil? #with_runtime? #without_runtime?}
:sig
(sym :final)?
) (args) ...)
PATTERN

def_node_matcher(:with_runtime?, <<~PATTERN)
Expand All @@ -23,13 +27,6 @@ class SignatureCop < RuboCop::Cop::Cop
(const (const (const nil? :T) :Sig) :WithoutRuntime)
PATTERN

def allowed_recv(recv)
return true unless recv
return true if with_runtime?(recv)
return true if without_runtime?(recv)
false
end

def on_block(node)
on_signature(node) if signature?(node)
end
Expand Down
7 changes: 7 additions & 0 deletions spec/rubocop/cop/sorbet/signatures/enforce_signatures_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def foo; end
RUBY
end

it "makes no offense if a top-level method has a signature" do
expect_no_offenses(<<~RUBY)
sig(:final) { void }
def foo; end
RUBY
end

it "makes offense if a top-level method has no signature" do
expect_offense(<<~RUBY)
def foo; end
Expand Down

0 comments on commit e57f642

Please sign in to comment.