seaofvoices / darklua

A command line tool that transforms Lua code
https://darklua.com/
MIT License
71 stars 9 forks source link

"dense" and "readable" generators add a space after field parts that end in a number #185

Closed sircfenner closed 3 months ago

sircfenner commented 4 months ago

Current behavior, when running darklua process using either dense or readable generator and no rules specified:

x0.y()
-- becomes:
x0 .y()

Expected behavior is that the redundant space is not added.

Looks like the problematic generators are calling write_field, which calls write_prefix, which eventually calls should_break_with_space. This returns true where the identifier in the relevant part of the field expression ends in a number.

Tested on darklua version 0.13.0. The issue does not occur with the "retain_lines" generator.

jeparlefrancais commented 4 months ago

Oh! This is a side effect of checking for instances where darklua writes a number followed by the concat operator, which needs to insert a space (like 1 ..var, instead of 1..var where it would read 1. as a number)