[ruby/prism] Implement ambiguous binary operator warning

6258c3695f
This commit is contained in:
Kevin Newton 2024-05-20 09:54:14 -04:00 committed by git
parent 8248268434
commit e90e8f8bd3
5 changed files with 55 additions and 1 deletions

View file

@ -15,6 +15,7 @@ module Prism
regexp_test.rb
static_literals_test.rb
unescape_test.rb
warnings_test.rb
]
filepaths.each do |relative|

View file

@ -23,6 +23,23 @@ module Prism
assert_warning("a /b/", "wrap regexp in parentheses")
end
def test_binary_operator
[
[:**, "argument prefix"],
[:*, "argument prefix"],
[:<<, "here document"],
[:&, "argument prefix"],
[:+, "unary operator"],
[:-, "unary operator"],
[:/, "regexp literal"],
[:%, "string literal"]
].each do |(operator, warning)|
assert_warning("puts 1 #{operator}0", warning)
assert_warning("puts :a #{operator}0", warning)
assert_warning("m = 1; puts m #{operator}0", warning)
end
end
def test_equal_in_conditional
assert_warning("if a = 1; end; a = a", "should be ==")
end