Skip to content

feat(printer): add per-node NEWLINE_ON_FLUENT_CALL attribute to BetterStandardPrinter#7910

Merged
TomasVotruba merged 4 commits intorectorphp:mainfrom
MrPunyapal:feat/printer-newline-on-fluent-call-attribute
Apr 7, 2026
Merged

feat(printer): add per-node NEWLINE_ON_FLUENT_CALL attribute to BetterStandardPrinter#7910
TomasVotruba merged 4 commits intorectorphp:mainfrom
MrPunyapal:feat/printer-newline-on-fluent-call-attribute

Conversation

@MrPunyapal
Copy link
Copy Markdown
Contributor

@MrPunyapal MrPunyapal commented Feb 23, 2026

Summary

Add a per-node attribute AttributeKey::NEWLINE_ON_FLUENT_CALL so individual MethodCall nodes can opt into newline-on-fluent formatting without enabling the global newLineOnFluentCall() option.

Motivation

The printer currently only checks the global Option::NEW_LINE_ON_FLUENT_CALL flag. When a rule enables that option globally, every fluent chain across the processed codebase is reformatted. This causes undesirable, wide-ranging formatting changes. A per-node attribute lets rules request one-method-per-line formatting for specific nodes (for example, expect() chains) without affecting unrelated code.

This is the problem I'm facing for rector-pest chain rule which chains multiple statements in one chain and sometimes it creates very long line and there is no way around pretty print them instead of applying new line config to whole project.

Example

When creating a MethodCall node in a Rector rule, tag it to enable newline formatting:

use Rector\NodeTypeResolver\Node\AttributeKey;

$methodCall = new MethodCall($receiver, 'and', [$arg]);
$methodCall->setAttribute(AttributeKey::NEWLINE_ON_FLUENT_CALL, true);

@MrPunyapal
Copy link
Copy Markdown
Contributor Author

@samsonasik any thoughts?

@TomasVotruba
Copy link
Copy Markdown
Member

Thank you for your patience. Looks good to me 👍

@TomasVotruba TomasVotruba merged commit 43ad95c into rectorphp:main Apr 7, 2026
58 of 59 checks passed
@MrPunyapal MrPunyapal deleted the feat/printer-newline-on-fluent-call-attribute branch April 7, 2026 16:48
@MrPunyapal
Copy link
Copy Markdown
Contributor Author

Thanks for taking time looking into it 💪

@samsonasik
Copy link
Copy Markdown
Member

e2e test expectation seems needs update due to PR for line info at

@samsonasik
Copy link
Copy Markdown
Member

I created new PR to fix e2e test:

@MrPunyapal
Copy link
Copy Markdown
Contributor Author

Thanks @samsonasik 🙌

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.

3 participants