Skip to content

Commit

Permalink
hot fix to address feedback from @pcaversaccio
Browse files Browse the repository at this point in the history
  • Loading branch information
Janther committed Dec 24, 2023
1 parent 57ac1c6 commit cf96d07
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prettier-plugin-solidity",
"version": "1.3.0",
"version": "1.3.1",
"description": "A Prettier Plugin for automatically formatting your Solidity code.",
"type": "module",
"main": "./src/index.js",
Expand Down Expand Up @@ -103,7 +103,7 @@
"jest-snapshot-serializer-raw": "^2.0.0",
"jest-watch-typeahead": "^2.2.2",
"lines-and-columns": "^2.0.3",
"prettier": "^3.1.0",
"prettier": "^3.1.1",
"proxyquire": "^2.1.3",
"solc": "^0.8.23-fixed",
"webpack": "^5.88.2",
Expand Down
22 changes: 13 additions & 9 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,19 @@ function parse(text, _parsers, options = _parsers) {
ctx.value = options.singleQuote ? `hex'${value}'` : `hex"${value}"`;
},
Conditional(ctx) {
// We can remove parentheses only because we are sure that the
// `condition` must be a single `bool` value.
while (
ctx.condition.type === 'TupleExpression' &&
!ctx.condition.isArray &&
ctx.condition.components.length === 1 &&
ctx.condition.components[0].type !== 'Conditional'
) {
[ctx.condition] = ctx.condition.components;
// TODO: while the behaviour is not stable, it should be behind the
// experimentalTernaries flag.
if (options.experimentalTernaries) {
// We can remove parentheses only because we are sure that the
// `condition` must be a single `bool` value.
while (
ctx.condition.type === 'TupleExpression' &&
!ctx.condition.isArray &&
ctx.condition.components.length === 1 &&
ctx.condition.components[0].type !== 'Conditional'
) {
[ctx.condition] = ctx.condition.components;
}
}
},
BinaryOperation(ctx) {
Expand Down
31 changes: 16 additions & 15 deletions tests/format/ExperimentalTernaries/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1895,13 +1895,13 @@ contract Conditional {
// multiline conditions and consequents/alternates:
string
storage multilineConditionsConsequentsAndAlternates = isAnAdorableKittyCat() &&
(someReallyLongCondition || moreInThisLongCondition)
storage multilineConditionsConsequentsAndAlternates = (isAnAdorableKittyCat() &&
(someReallyLongCondition || moreInThisLongCondition))
? someReallyLargeExpression
.thatWouldCauseALineBreak()
.willCauseAnIndentButNotParens()
: isNotAnAdorableKittyCat() &&
(someReallyLongCondition || moreInThisLongCondition)
: (isNotAnAdorableKittyCat() &&
(someReallyLongCondition || moreInThisLongCondition))
? bark()
: shortCondition()
? shortConsequent()
Expand All @@ -1910,13 +1910,13 @@ contract Conditional {
.willCauseAnIndentButNotParens();
// Assignment also groups and indents as Variable Declaration:
assignment = isAnAdorableKittyCat() &&
(someReallyLongCondition || moreInThisLongCondition)
assignment = (isAnAdorableKittyCat() &&
(someReallyLongCondition || moreInThisLongCondition))
? someReallyLargeExpression
.thatWouldCauseALineBreak()
.willCauseAnIndentButNotParens()
: isNotAnAdorableKittyCat() &&
(someReallyLongCondition || moreInThisLongCondition)
: (isNotAnAdorableKittyCat() &&
(someReallyLongCondition || moreInThisLongCondition))
? bark()
: shortCondition()
? shortConsequent()
Expand All @@ -1931,32 +1931,33 @@ contract Conditional {
? "two"
: x == 3
? "three"
: x == 5 &&
: (x == 5 &&
y == 7 &&
someOtherThing
.thatIsSoLong
.thatItBreaksTheTestCondition()
.thatItBreaksTheTestCondition())
? "four"
: x == 6
? "six"
: "idk";
// long conditional, short consequent/alternate, not chained - do indent after ?
string storage longConditional = bifornCringerMoshedPerplexSawder ==
string storage longConditional = (bifornCringerMoshedPerplexSawder ==
2 / askTrovenaBeenaDependsRowans &&
glimseGlyphsHazardNoopsTieTie >=
averredBathersBoxroomBuggyNurl().anodyneCondosMalateOverateRetinol()
averredBathersBoxroomBuggyNurl()
.anodyneCondosMalateOverateRetinol())
? "foo"
: "bar";
// long conditional, short consequent/alternate, chained
// (break on short consequents iff in chained ternary and its conditional broke)
string
storage longConditionalChained = bifornCringerMoshedPerplexSawder ==
storage longConditionalChained = (bifornCringerMoshedPerplexSawder ==
2 / askTrovenaBeenaDependsRowans &&
glimseGlyphsHazardNoopsTieTie >=
averredBathersBoxroomBuggyNurl()
.anodyneCondosMalateOverateRetinol()
.anodyneCondosMalateOverateRetinol())
? "foo"
: anotherCondition
? "bar"
Expand All @@ -1977,7 +1978,7 @@ contract Conditional {
);
// Conditional as a condition
(foo ? 1 : bar) ? 3 : 4;
(((foo ? 1 : bar))) ? 3 : 4;
(
isCat()
? meow()
Expand Down

0 comments on commit cf96d07

Please sign in to comment.