Skip to content

Conversation

@efd6
Copy link
Contributor

@efd6 efd6 commented Jan 23, 2026

See commit message.

Please take a look.

fixes #58

Work done in conjunction with Cursor.

When formatting a ternary condition that needed parentheses,
visitMaybeNested decided whether to use multiline format based only on
whether the expression spans multiple lines. This failed when comments
precede a sub-expression rather than the top-level expression being
wrapped.

For example, in:

    (
        // comment
        has(state.a) && state.b > 0
    ) ?

The comments are associated with the has(...) sub-expression, not the
entire && expression. The formatter would write "(" without a newline,
then the sub-expression would write the comments, resulting in:

    (// comment

Running celfmt again would progressively eat comments because they
ended up on a line starting with "(" which is not recognized as a
comment line.

The fix modifies visitMaybeNested to check if the expression or any of
its descendants have preceding comments when deciding whether to use
multiline format. This ensures proper newline insertion after "(" when
comments will be written by any descendant expression.

Fixes #58
@efd6 efd6 self-assigned this Jan 23, 2026
@efd6 efd6 requested a review from a team as a code owner January 23, 2026 01:23
@efd6 efd6 added bug Something isn't working Team:Security-Service Integrations Security Service Integrations Team [elastic/security-service-integrations] labels Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Team:Security-Service Integrations Security Service Integrations Team [elastic/security-service-integrations]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

celfmt is not idempotent and eats comments

2 participants