镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix(formatter): stop inserting a space before ; - #627

Open
KSkun wants to merge 1 commit into
EmmyLua:masterfrom
KSkun:fix/no-space-before-semicolon
Open

KSkun wants to merge 1 commit into
EmmyLua:masterfrom
KSkun:fix/no-space-before-semicolon

Conversation

@KSkun

@KSkun KSkun commented Oct 10, 2026

Copy link
Copy Markdown

After a statement that ends in a keyword, the formatter put a space before the ;. return; became return ;. Because SpacingBuilder uses the first matching rule. around(KEYWORD_TOKENS).spaces(1) was declared before before(SEMI).spaces(0), so for any pair of <keyword> ; the keyword rule matched first. KEYWORD_TOKENS includes return, break, end and ::. The parser attaches the ; to the statement (doneStat), so the keyword and the ; are direct siblings.

This PR moves before(SEMI).spaces(0) to the front of the chain in LuaFormattingModelBuilder.kt.

Affected shapes:

Shape Before After
return; return ; return;
break; break ; break;
do end; do⏎end ; do⏎end;
while x do end; ...end ; ...end;
if x then end; ...end ; ...end;
if x then else end; ...end ; ...end;
if x then elseif y then end; ...end ; ...end;
for i = 1, 2 do end; ...end ; ...end;
for k, v in pairs(t) do end; ...end ; ...end;
::x::; :: x :: ; :: x ::;
function f() return; end return ; return;
while x do break; end break ; break;
if x then return; else return; end both return ; both return;
return; -- c return ; -- c return; -- c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant