Skip to content

feat(core): add an optional max prop to <group> - #449

Open
p-bakker wants to merge 1 commit into
alloy-framework:mainfrom
p-bakker:feat/group-max
Open

p-bakker wants to merge 1 commit into
alloy-framework:mainfrom
p-bakker:feat/group-max

Conversation

@p-bakker

@p-bakker p-bakker commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

<group> chooses between its flat and broken form by asking whether the flat form fits the space left on the current line. That couples two questions a generator often needs to keep apart: how much room is left, and how wide this construct is allowed to be.

max answers only the second. When it is set, the group's children are measured in their flat form against max alone, so the group lays out identically wherever it appears. Style rules that cap a specific construct — argument lists, collection literals, call chains — below the file's print width map onto it directly. When max is absent, behaviour is unchanged.

The threshold replaces the print width rather than adding to it, and that is what makes the decision column-independent: a group that fits max stays flat even when that overruns printWidth, leaving an enclosing group to break elsewhere to make room. shouldBreak, hard lines and <breakParent /> still force a break, and id still publishes the outcome to <ifBreak> / <indentIfBreak>.

Folded onto <group> rather than shipped as a second intrinsic: it is the same axis as shouldBreak (a break trigger), callers that don't set it pay nothing, and the API surface stays at one group primitive.

`<group>` chooses between its flat and broken form by asking whether the
flat form fits the space left on the current line. That couples two
questions a generator often needs to keep apart: how much room is left,
and how wide this construct is allowed to be.

`max` answers only the second. When it is set, the group's children are
measured in their flat form against `max` alone, so the group lays out
identically wherever it appears. Style rules that cap a specific
construct — argument lists, collection literals, call chains — below the
file's print width map onto it directly. When `max` is absent, behaviour
is unchanged.

The threshold replaces the print width rather than adding to it, and
that is what makes the decision column-independent: a group that fits
`max` stays flat even when that overruns `printWidth`, leaving an
enclosing group to break elsewhere to make room. `shouldBreak`, hard
lines and `<breakParent />` still force a break, and `id` still
publishes the outcome to `<ifBreak>` / `<indentIfBreak>`.

Folded onto `<group>` rather than shipped as a second intrinsic: it is
the same axis as `shouldBreak` (a break trigger), callers that don't set
it pay nothing, and the API surface stays at one group primitive.
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @alloy-js/core
Show changes

@alloy-js/core - feature ✏️

Add an optional max prop to <group>. When set, the group's children are measured in their flat form against max rather than against the space left on the current line, so the group lays out the same way wherever it appears. This suits layout rules stated per construct rather than per line — a style that caps argument lists, collection literals or call chains below the file's print width. A group that fits max stays flat even when that overruns printWidth, leaving an enclosing group to break elsewhere.

@pkg-pr-new

pkg-pr-new Bot commented Sep 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@alloy-js/core@449

commit: c331f5a

* here.
*
* Not memoized: the result depends on `hasLineSuffix` as well as on the
* node, so nesting `max` groups `d` deep re-measures the innermost subtree

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anything we could do here for the potential performance issue?

we should at least document it on the max property and in the formatting doc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will have a look if there's a path to optimizing this, else add the suggested docs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear you did want a group with max > printWidth to keep going, not just that this says this group can take up to x amount but it should still fit within the regular lines

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tnx for the feedback, will look into this: max should not enable a line going over the total printWidth, so at least the text here is wrong/misleading

This branch has not been deployed

No deployments
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.

2 participants