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 after equal on assignment if rhs is await/yield expression #15204

Conversation

seiyab
Copy link
Sponsor Contributor

@seiyab seiyab commented Aug 3, 2023

Description

Works on #15196.

Feel free to stop this if it needs more discussions.

Fixes #15208

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

@seiyab seiyab changed the title 15196 break after equal on assignment if rhs is await expression Break after equal on assignment if rhs is await expression Aug 3, 2023
@@ -0,0 +1,9 @@
async function f() {
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.

This is because Flow yields error on top-level await.

@@ -205,7 +205,7 @@ function shouldBreakAfterOperator(path, options, print, hasShortKey) {
let node = rightNode;
const propertiesForPath = [];
for (;;) {
if (node.type === "UnaryExpression") {
if (node.type === "UnaryExpression" || node.type === "AwaitExpression") {
Copy link
Member

Choose a reason for hiding this comment

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

If we are doing this, I think we should treat yield the sameway, though it's not very common to be on RHS.

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.

Ah, I agree with you,thank you.
Maybe typeof too?

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 noticed typeof already breaks after =.
I try to work on yield.

@seiyab seiyab marked this pull request as ready for review August 5, 2023 05:24
@seiyab seiyab requested a review from fisker August 5, 2023 05:25
const longlonglonglonglonglonglong1 = yield qwertyuiop(asdfghjkl, zxcvbnm, qwertyuiop, asdfghjkl);
const longlonglonglonglonglonglong2 = yield { qwertyuiop: 1234567890, asdfghjkl: 1234567890, zxcvbnm: 123456789 };

const x = yield;
Copy link
Member

Choose a reason for hiding this comment

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

one test for yield* ... please.

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 have missed it, thank you for feedback.

Copy link
Member

@fisker fisker left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@fisker fisker changed the title Break after equal on assignment if rhs is await expression Break after equal on assignment if rhs is await/yield expression Aug 5, 2023
@sosukesuzuki sosukesuzuki merged commit bf0b304 into prettier:main Aug 6, 2023
29 checks passed
@aarongoldenthal
Copy link

aarongoldenthal commented Aug 20, 2023

While this change is definitely the better formatting option, changing this type of formatting is a breaking change.

@k4rli
Copy link

k4rli commented Aug 21, 2023

Definitely a breaking change since it can affect much of codebase. Is there a way to use the old way?

@seiyab
Copy link
Sponsor Contributor Author

seiyab commented Aug 21, 2023

There isn't way to avoid this on 3.0.2.
Prettier have usually changed format as a patch release.

Examples

Add parentheses for TypeofTypeAnnotation to improve readability

// Input
type A = (typeof node.children)[];

// Prettier 2.8.4
type A = typeof node.children[];

// Prettier 2.8.5
type A = (typeof node.children)[];

Break the LHS of type alias that has complex type parameters

// Input
type FieldLayoutWith<
  T extends string,
  S extends unknown = { width: string }
> = {
  type: T;
  code: string;
  size: S;
};

// Prettier 2.3.0
type FieldLayoutWith<T extends string, S extends unknown = { width: string }> =
  {
    type: T;
    code: string;
    size: S;
  };

// Prettier 2.3.1
type FieldLayoutWith<
  T extends string,
  S extends unknown = { width: string }
> = {
  type: T;
  code: string;
  size: S;
};

Personally, I automatically format only changed files to avoid changing huge amount of files by updating Prettier. https://stackoverflow.com/q/47610213/13195622
I hope it helps.

@seiyab seiyab deleted the 15196-break-after-eq-on-assignment-if-rhs-is-await branch August 22, 2023 02:15
medikoo pushed a commit to medikoo/prettier-elastic that referenced this pull request Feb 15, 2024
…ttier#15204)

* add as-is test

* break after equal on assignment if rhs is wait

Discussion: prettier#15196

* rename test file

* add as-is test

* treat YieldExpression

* add tests

* add changelog

* fix a bug

* add test for delegated yield
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.

line breaks after assignment instead of between parentheses / around parameters
5 participants