Skip to content
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

Break long member and method chain #15171

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

seiyab
Copy link
Sponsor Contributor

@seiyab seiyab commented Jul 29, 2023

Description

Fixes #2548.

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

Comment on lines 107 to 108
path.call((object) => rec(object), "object");
printedNodes.push({

This comment was marked as outdated.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

I reverted this change because objectDoc doesn't look necessary here.

path,
options,
print,
printedNodes.at(-1)?.printed,

This comment was marked as resolved.

Copy link
Sponsor Contributor Author

@seiyab seiyab Jul 29, 2023

Choose a reason for hiding this comment

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

Outdated. This should be resolved.

Comment on lines -275 to +268
expect(() =>
asyncRequest({ type: "foo", url: "/test-endpoint" })
).not.toThrowError();
expect(() => asyncRequest({ type: "foo", url: "/test-endpoint" })).not
.toThrowError();
Copy link
Sponsor Contributor Author

@seiyab seiyab Jul 29, 2023

Choose a reason for hiding this comment

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

It looks to get worse to read.
Currently, I consider this to be another issue.

This comment was marked as outdated.


/**
* @param {AstPath} path
* @param {*} objectDoc
Copy link
Sponsor Contributor Author

@seiyab seiyab Jul 29, 2023

Choose a reason for hiding this comment

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

I want to put "Doc" type here but it requires too redundant check like:

- objectDoc.label?.memberChain
+ typeof objectDoc === "object" && "label" in objectDoc &&  typeof objectDoc.label === "object" &&  "memberChain" in objectDoc.label && objectDoc.label?.memberChain

Adding @property {*} [label] in Doc (it should be right), it get a bit better:

- objectDoc.label?.memberChain
+ typeof objectDoc === "object" && "label" in objectDoc &&  objectDoc.label?.memberChain

But I think this might still make developers to avoid typing.
Defining @typedef {Partial<DocObject> & (string | DocObject | DocArray)} LooseDoc, or just defining Doc as it make just objectDoc.label?.memberChain works.
I'd like to hear member's opinion

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

I mean that I will open a discussion or an issue if it is worth to discuss, or open a PR if it looks better than the current one.

@seiyab seiyab changed the title 2548 long long member and method chain Break long member and method chain Jul 29, 2023
@seiyab seiyab marked this pull request as ready for review July 29, 2023 14:08
@seiyab
Copy link
Sponsor Contributor Author

seiyab commented Jul 30, 2023

Maybe I accidentally hit another independent issue about idempotency...

-   .Even// comment<LF>
+   .Even // comment<LF>

@seiyab
Copy link
Sponsor Contributor Author

seiyab commented Aug 15, 2023

I consider it ready for review.
(Just for a reminder. I'm patiently waiting for review.)

@seiyab seiyab requested a review from fisker August 25, 2023 13:43
@fisker
Copy link
Member

fisker commented Aug 25, 2023

Sorry for the long delay, I'll take a look ASAP.

.Even // comment
.if.Prettier.does.not.format.all.code["100%"].the.way["you’d"].like["it’s"]
.worth.the.sacrifice.given.the.unique.benefits.of.Prettier["don’t"].you
.think?.();
Copy link
Member

Choose a reason for hiding this comment

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

Can you find some real world case? These tests doesn't make sense to me at all. Nobody write code like this.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

I see. I'll consider a more practical test case. This is just a test case that is so long chain and not likely to have a copyright / license issue.

"YAML",
)
.it.removes.all.original.styling.and.ensures.that.all.outputted.code.conforms
.to.a.consistent.style(see, this, blogpost);
Copy link
Member

Choose a reason for hiding this comment

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

This indention seems unnessary.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

I'll fix it.

@seiyab
Copy link
Sponsor Contributor Author

seiyab commented Sep 4, 2023

Progress
I'm still working on this.
It'll take for a while because it looks harder than I had thought and I get busier a bit now.

@seiyab
Copy link
Sponsor Contributor Author

seiyab commented Sep 18, 2023

Finally it looks to "work".
But I'm not sure whether the introduced complexity is reasonable to fix the bug.
I intend to look for simpler way. This might be more costly than leaving the bug existing.

@seiyab
Copy link
Sponsor Contributor Author

seiyab commented Sep 21, 2023

I give up to make it easier to read.
I consider it's ready for review.

@seiyab seiyab requested a review from fisker September 21, 2023 13:36
@seiyab seiyab mentioned this pull request Oct 16, 2023
4 tasks
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.

Long chaining property?
2 participants