New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stabilize member chain with empty line #15522
Stabilize member chain with empty line #15522
Conversation
This comment has been minimized.
This comment has been minimized.
if ( | ||
groups.length <= cutoff && | ||
!nodeHasComment && | ||
!groups.some((g) => g.at(-1).hasTrailingEmptyLine) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether it should be something like group.some(willBreak)
as
printedGroups.slice(0, -1).some(willBreak) || |
Probably it will affect code like following:
this.bar(a).baz(
<ul>
<li>a</li>
</ul>,
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add test for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we name the element as printedNodes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I was wrong. Trying to add test for it, I found it isn't affected by groups.some((g) => g.at(-1).hasTrailingEmptyLine)
vs willBreak(oneLine)
(group.some(willBreak)
that I suggested isn't correct).
Changing groups.some((g) => g.at(-1).hasTrailingEmptyLine)
into willBreak(oneLine)
, some existing test are affected.
Example
stable and this PR
function f() {
return this._getWorker(workerOptions)({
filePath,
hasteImplModulePath: this._options.hasteImplModulePath,
}).then((metadata) => {
// \`1\` for truthy values instead of \`true\` to save cache space.
fileMetadata[H.VISITED] = 1;
const metadataId = metadata.id;
const metadataModule = metadata.module;
if (metadataId && metadataModule) {
fileMetadata[H.ID] = metadataId;
setModule(metadataId, metadataModule);
}
fileMetadata[H.DEPENDENCIES] = metadata.dependencies || [];
});
}
willBreak(oneLine)
function f() {
return this._getWorker(workerOptions)({
filePath,
hasteImplModulePath: this._options.hasteImplModulePath,
})
.then((metadata) => {
// \`1\` for truthy values instead of \`true\` to save cache space.
fileMetadata[H.VISITED] = 1;
const metadataId = metadata.id;
const metadataModule = metadata.module;
if (metadataId && metadataModule) {
fileMetadata[H.ID] = metadataId;
setModule(metadataId, metadataModule);
}
fileMetadata[H.DEPENDENCIES] = metadata.dependencies || [];
});
}
I'd like to hear your opinion about
- whether we should find and add test case specifically focusing on it.
- Just for information: Zod looks good library to search for practical method chains.
- which is better
groups.some((g) => g.at(-1).hasTrailingEmptyLine)
vswillBreak(oneLine)
- IMO,
groups.some((g) => g.at(-1).hasTrailingEmptyLine)
looks slightly better because:- it looks slightly more readable to me for existing test cases
- it doesn't change formatting which doesn't relate to Unstable formatting for chained calls #15435
- IMO,
For naming, another variable is already named as printedNodes
. I'm sorry but probably my mistake (group.some(willBreak)
, which is not correct) confused you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fisker Could you respond this, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for been busy, will take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just worried you might have missed notification. There's no hurry. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's best to avoid adding more uses of willBreak
. Eventually, the existing use should be somehow removed from the member chain printing code too because it causes #2803.
I found following inconsistency around here and this PR doesn't resolve it. Anyway, this PR resolves idempotency issue #15435. I don't matter closing this PR if member consider it needs discussion. Prettier 3.0.3 --parser typescript Input: new Set()
.add(5)
.add("some text");
new Set()
.add(5)
.add("some text"); Output: new Set().add(5).add("some text");
new Set()
.add(5)
.add("some text"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM from the result.
These changes don't look good prettier/prettier-regression-testing#342 (comment) |
Maybe the empty line only makes sense when the chain is long enough. |
Co-authored-by: fisker Cheung <lionkay@gmail.com>
Description
Fix #15435
Fortunately, this doesn't conflict with #15171.
I actually implemented this on the top of #15171 (99d389d) and rebased it into master without seeing any problems.
Checklist
(If changing the API or CLI) I’ve documented the changes I’ve made (in thedocs/
directory).changelog_unreleased/*/XXXX.md
file followingchangelog_unreleased/TEMPLATE.md
.✨Try the playground for this PR✨