Skip to content

Commit

Permalink
- fix a false positive for endless method definition
Browse files Browse the repository at this point in the history
Fixes: #795.

This PR fixes false positives that non setter method ending with `=` recognizes as
a setter method.
  • Loading branch information
koic committed Apr 20, 2021
1 parent 21684f1 commit fc635a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/parser/ruby30.y
Expand Up @@ -3071,7 +3071,7 @@ require 'parser'
end
def endless_method_name(name_t)
if name_t[0].end_with?('=')
if !%w[=== == != <= >= []=].include?(name_t[0]) && name_t[0].end_with?('=')
diagnostic :error, :endless_setter, nil, name_t
end
end
2 changes: 1 addition & 1 deletion lib/parser/ruby31.y
Expand Up @@ -3071,7 +3071,7 @@ require 'parser'
end
def endless_method_name(name_t)
if name_t[0].end_with?('=')
if !%w[=== == != <= >= []=].include?(name_t[0]) && name_t[0].end_with?('=')
diagnostic :error, :endless_setter, nil, name_t
end
end
13 changes: 13 additions & 0 deletions test/test_parser.rb
Expand Up @@ -10107,6 +10107,19 @@ def test_endless_setter
SINCE_3_0)
end

def test_endless_non_setter_ending_with_equal
%i[=== == != <= >= != []=].each do |method_name|
assert_parses(
s(:def, method_name,
s(:args,
s(:arg, :other)),
s(:send, nil, :do_something)),
%Q{def #{method_name}(other) = do_something},
%q{},
SINCE_3_0)
end
end

def test_endless_method_without_args
assert_parses(
s(:def, :foo,
Expand Down

0 comments on commit fc635a8

Please sign in to comment.