Incorrect indentation on nested if-then-else expression

As of version 0.657, an if-then-else expression inside another if-then-else expression adds an extra level for every line after it. This does not occur if the nested if-then-else expression is surrounded by parentheses.

--!strict
local _cond = if 1
	then if 2 then 3 else 4
	else 5

--comment
local function _func()
	--[[
		owspamdcokie	ok	d
		fwkroem	kvf,ledp;s
	]]
	for i = 1, 5 do
		local _ = '5'
	end
	repeat until false
end

Result:
image

Editor settings:

Expected behavior

No level of indentation is added and the script is formatted as if the expression was surrounded by parentheses.

Hi,

Thanks for letting us know, we have added this to our bug queue and will address it as soon as we can.

1 Like

Hi @nothing_1649,

Thanks for flagging this! This is a limitation of the current formatter, and the workaround is to use parentheses. We are planning a next-gen formatter and working on providing a better solution for this.

I’ve moved this request to the post:
https://devforum.roblox.com/t/collecting-suggestions-for-next-gen-script-editor-formatter/3555458

Please feel free to share more suggestions there.

Thank you!

1 Like

This is a duplicate of Add identation to if-then-else expressions

this isn’t a duplicate; where this report applies to nested if-then-else expressions and breaks indentation for everything after it, the other simply covers adding indentation for a single expression

1 Like