Skip to content

stmt_remove_leading_newlines ignores attributes on LocalFunction/ConstFunction #1109

@JohnnyMorganz

Description

@JohnnyMorganz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions