fables-tales / rubyfmt

Ruby Autoformatter!
MIT License
1.07k stars 50 forks source link

not(var.nil?) gets wrongfully converted to not var.nil? which can lead to invalid ruby code #459

Open onvbqalc opened 7 months ago

onvbqalc commented 7 months ago

Input file

class MyClass
  def my_method
    a.nil? || not(b.nil?) || c.nil?
  end
end

Rubyfmt's output

# First format - no output but brackets () are removed
# leaving conditional as: a.nil? || not b.nil? || c.nil?
#
# Second format:
Rubyfmt detected a syntax error in the ruby code being executed

This breaks because

Code should have been left as-is on the first format - instead, it got converted to invalid ruby code:

a.nil? || not b.nil? || c.nil?

(is not valid ruby)