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

Avoid having small right operand on its own line #180

Merged
merged 1 commit into from
Mar 2, 2020

Conversation

jablko
Copy link
Contributor

@jablko jablko commented Aug 3, 2019

Would you consider grouping the right operand, like language-js, "to avoid having a small right part like -1 be on its own line"?

@codecov
Copy link

codecov bot commented Aug 3, 2019

Codecov Report

Merging #180 into master will decrease coverage by 0.31%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #180      +/-   ##
==========================================
- Coverage      99%   98.68%   -0.32%     
==========================================
  Files          74       74              
  Lines         601      609       +8     
  Branches       96      100       +4     
==========================================
+ Hits          595      601       +6     
- Misses          6        8       +2
Impacted Files Coverage Δ
src/binary-operator-printers/exponentiation.js 100% <100%> (ø) ⬆️
src/binary-operator-printers/logical.js 100% <100%> (ø) ⬆️
src/binary-operator-printers/comparison.js 100% <100%> (ø) ⬆️
src/binary-operator-printers/arithmetic.js 100% <100%> (ø) ⬆️
src/clean.js 33.33% <0%> (-66.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update df9dc77...083efb7. Read the comment docs.

@Janther
Copy link
Contributor

Janther commented Aug 3, 2019

prettier js formats the following:

veryVeryVeryVeryVeryLongVariableCalledA - veryVeryVeryVeryVeryLongVariableCalledB - 1 -1 -1 - 1 - 1 - 1 - 1;

like,

veryVeryVeryVeryVeryLongVariableCalledA -
  veryVeryVeryVeryVeryLongVariableCalledB -
  1 -
  1 -
  1 -
  1 -
  1 -
  1 -
  1;

have a look at #175 to see other ways prettier js groups ecuations that we are reviewing right now for solidity.

@jablko
Copy link
Contributor Author

jablko commented Aug 4, 2019

My mistake, however it formats

a(veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB) - 1;

like

a(
  veryVeryVeryVeryVeryLongVariableCalledA +
    veryVeryVeryVeryVeryLongVariableCalledB
) - 1;

Would you consider something like the revised version of this pull request, which handles both

veryVeryVeryVeryVeryLongVariableCalledA -
  veryVeryVeryVeryVeryLongVariableCalledB -
  1 -
  1 -
  1 -
  1 -
  1 -
  1 -
  1;

and

a(
  veryVeryVeryVeryVeryLongVariableCalledA +
    veryVeryVeryVeryVeryLongVariableCalledB
) - 1;

?

@Janther
Copy link
Contributor

Janther commented Aug 4, 2019

hahaha this one is a weird one.
If I try this in JS:

s = a(veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB) - 1;

2 - a(veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB) - 1;

a(veryVeryVeryVeryVeryLongVariableCalledA + veryVeryVeryVeryVeryLongVariableCalledB) - 1 + 2;

I get

s =
  a(
    veryVeryVeryVeryVeryLongVariableCalledA +
      veryVeryVeryVeryVeryLongVariableCalledB
  ) - 1;

2 -
  a(
    veryVeryVeryVeryVeryLongVariableCalledA +
      veryVeryVeryVeryVeryLongVariableCalledB
  ) -
  1;

a(
  veryVeryVeryVeryVeryLongVariableCalledA +
    veryVeryVeryVeryVeryLongVariableCalledB
) -
  1 +
  2;

I like having this particular edge case as long as the main rule is not broken, could you add test cases??
testing not only your solution but also combining it in different scenarios to check exactly how it behaves not just in a specific case but also in something broader.

const right = concat([node.operator, line, path.call(print, 'right')]);
const parent = path.getParentNode();
const shouldGroup =
parent.type !== node.type && node.left.type !== node.type;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also document why this particular type mismatch deserves a grouping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Will do!

@jablko jablko force-pushed the patch-3 branch 2 times, most recently from 355fdc4 to 818f52e Compare August 5, 2019 15:51
@jablko
Copy link
Contributor Author

jablko commented Aug 5, 2019

I've rebased on #182: I added tests for

  • single operator/two operands
  • multiple operators
  • arithmetic, comparison, and logical operators
  • no context, assignment, if statement, function call, and return statement

@jablko jablko force-pushed the patch-3 branch 5 times, most recently from a303e72 to 7130b5a Compare August 7, 2019 15:46
@mattiaerre
Copy link
Member

how can we fix this cov report issue? I'll try to reach out to the Codecov team and see what they say

@jablko jablko force-pushed the patch-3 branch 2 times, most recently from 13abec2 to 1a62513 Compare August 13, 2019 16:12
jablko added a commit to jablko/prettier-plugin-solidity that referenced this pull request Aug 13, 2019
jablko added a commit to jablko/prettier-plugin-solidity that referenced this pull request Aug 13, 2019
jablko added a commit to jablko/prettier-plugin-solidity that referenced this pull request Sep 23, 2019
@mattiaerre
Copy link
Member

can you resolve the conflicts here too @jablko ? thanks

@jablko
Copy link
Contributor Author

jablko commented Sep 23, 2019

@mattiaerre Absolutely: Rebased.

@mattiaerre
Copy link
Member

mattiaerre commented Sep 23, 2019

thanks so much @jablko

Copy link
Member

@mattiaerre mattiaerre left a comment

Choose a reason for hiding this comment

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

over to you @jablko

@@ -330,8 +326,7 @@ contract ArithmeticOperators {
veryVeryVeryVeryVeryLongVariableCalledB;
veryVeryVeryVeryVeryLongFunctionCalledA(
veryVeryVeryVeryVeryLongVariableCalledB
) **
c;
)**c;
Copy link
Member

Choose a reason for hiding this comment

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

just noticing that there is no space before ** and after it; is that what we want?

Copy link
Contributor

Choose a reason for hiding this comment

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

this was applied in #174

Copy link
Member

Choose a reason for hiding this comment

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

can we approve this PR?

@mattiaerre mattiaerre merged commit 4203efe into prettier-solidity:master Mar 2, 2020
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.

None yet

3 participants