In src/formatters/block.rs, stmt_remove_leading_newlines removes leading newlines from the first token of a statement. For LocalFunction and ConstFunction it targets the local_token / const_token:
Stmt::LocalFunction(local_function) => update_first_token!(
LocalFunction,
local_function,
local_function.local_token(),
with_local_token
),
Stmt::ConstFunction(const_function) => update_first_token!(
ConstFunction,
const_function,
const_function.const_token(),
with_const_token
),
However, when the function has a leading Luau attribute (e.g. @native), the actual first token of the statement is the attribute's at_sign, not the keyword. The leading-newline removal will silently target the wrong token, leaving stray newlines before the attribute.
The same latent issue exists for TypeFunction / ExportedTypeFunction if they ever gain attribute support.
A fix would need to check whether attributes are present and, if so, apply update_first_token! to the first attribute instead.
In
src/formatters/block.rs,stmt_remove_leading_newlinesremoves leading newlines from the first token of a statement. ForLocalFunctionandConstFunctionit targets thelocal_token/const_token:However, when the function has a leading Luau attribute (e.g.
@native), the actual first token of the statement is the attribute'sat_sign, not the keyword. The leading-newline removal will silently target the wrong token, leaving stray newlines before the attribute.The same latent issue exists for
TypeFunction/ExportedTypeFunctionif they ever gain attribute support.A fix would need to check whether attributes are present and, if so, apply
update_first_token!to the first attribute instead.