Skip to content

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

@onvbqalc

Description

@onvbqalc
  • Ruby version: 3.1.2
  • Rubyfmt git sha: e00d2ab89fd4b0b85a7897fac393c1ad987136de
==> rubyfmt: stable 0.10.0 (bottled), HEAD
Ruby autoformatter
https://github.com/fables-tales/rubyfmt
/opt/homebrew/Cellar/rubyfmt/0.10.0 (8 files, 15.4MB) *
  Poured from bottle using the formulae.brew.sh API on 2024-01-07 at 04:41:02
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/r/rubyfmt.rb

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions