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

Added condition for '+' case. #13115

Merged
merged 5 commits into from
Aug 7, 2022
Merged

Added condition for '+' case. #13115

merged 5 commits into from
Aug 7, 2022

Conversation

t-mangoe
Copy link
Contributor

@t-mangoe t-mangoe commented Jul 16, 2022

Description

this PR fixes the issue #13018

Fix #13018

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

@t-mangoe
Copy link
Contributor Author

I am not sure how to update the test, so, if the test needs to be updated, I would appreciate knowing how to update it.
Also, if there are any other areas that need correction, please let me know.

@sosukesuzuki
Copy link
Member

@t-mangoe Thank you for working on this! I've pushed a commit to add tests. If you will contribute to Prettier again, please add tests with to refer my commit.

@fisker
Copy link
Member

fisker commented Jul 16, 2022

should we also do the same to ~ and ++?

@sosukesuzuki
Copy link
Member

sosukesuzuki commented Jul 16, 2022

node.operator.length <= 2 ?

@fisker
Copy link
Member

fisker commented Jul 16, 2022

node.operator.length <= 2 ?

No, just add the UpdateExpression and list operators.

@t-mangoe
Copy link
Contributor Author

t-mangoe commented Aug 6, 2022

@fisker
Thank you for your comment. I added processing for UpdateExpression case. Also, I grouped the target operators into targetUnaryExpressionOperators and targetUpdateExpressionOperators.
With these responses, how do you like it?

@@ -1,3 +1,6 @@
foo(_a).bar().leet();
foo(-a).bar().leet();
foo(+a).bar().leet();
foo(~a).bar().leet();
foo(++a).bar().leet();
Copy link
Member

Choose a reason for hiding this comment

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

I assume we are going to treat a++ the same, please add test for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added tests for a++ and a--.

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, thank you!

@fisker
Copy link
Member

fisker commented Aug 7, 2022

Also, I grouped the target operators into targetUnaryExpressionOperators and targetUpdateExpressionOperators.

Sorry, missed this.

I'd use

const simpleOperators = new Map([
	'UnaryExpression', new Set(['!', '-', '+', '~']),
	// To prevent unexpected operators add in future
	'UpdateExpression', new Set(['++', '--']),
]);

if (simpleOperators.has(node.type) && simpleOperators.get(node.type).has(node.operator)) {
  // ...
}

@fisker fisker merged commit 00ec91b into prettier:main Aug 7, 2022
medikoo pushed a commit to medikoo/prettier-elastic that referenced this pull request Jan 4, 2024
Co-authored-by: Sosuke Suzuki <aosukeke@gmail.com>
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.

Unary + parameter triggers overeager breaking of method chain
3 participants