JohnnyMorganz / StyLua

An opinionated Lua code formatter
Mozilla Public License 2.0
1.53k stars 68 forks source link

Сomment incorrectly influences formation #777

Open d-enk opened 1 year ago

d-enk commented 1 year ago

local arg_with_long_name, function_with_long_name

--- 1
function_with_long_name(function_with_long_name(
    arg_with_long_name, -- comment
    arg_with_long_name,
    arg_with_long_name,
    arg_with_long_name,
    arg_with_long_name,
    arg_with_long_name
))

--- 2
function_with_long_name(function_with_long_name(
    arg_with_long_name, --[[comment]]
    arg_with_long_name,
    arg_with_long_name,
    arg_with_long_name,
    arg_with_long_name,
    arg_with_long_name
))

--- 3
function_with_long_name(function_with_long_name(
    arg_with_long_name,
    arg_with_long_name,
    arg_with_long_name,
    arg_with_long_name,
    arg_with_long_name,
    arg_with_long_name
))

For 1 case formatting does not work and does not look like expected behavior.

JohnnyMorganz commented 10 months ago

The problem here is we eagerly select a different codepath because of the singleline comment in the first example. It is difficult to detect this comment without being too expensive since it is nested inside another function call. Will see if there is a way to solve this without a major performance penalty.