Indented comment messes up indentation of all following code

Using an indented comment in an indented variable assignment expression will add +1 indentation to all remaining lines in the script when formatted (e.g. by pressing enter at the end of a line).

I use this commenting pattern when I have a chain of “if expressions” and I want to add a comment above a particular case (not the entire variable assignment).

do
	local Variable =
		if true then 1 else 0
end

-- There is no comment above, so creating
-- a new line at the end of this next line will work fine.
local ValueA = true

do
	local Variable =
		-- This is a comment.
		if true then 1 else 0
end

-- There is an indented comment above, so creating
-- a new line at the end of this next line will have messed up formatting.
local ValueB = true

See this video for an example:

1 Like