Skip to content

Commit 588bffc

Browse files
Janthermattiaerre
authored andcommitted
Fix for the conditional formating (#132)
1 parent aea5ed8 commit 588bffc

File tree

4 files changed

+71
-8
lines changed

4 files changed

+71
-8
lines changed

src/nodes/Conditional.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
/* eslint-disable implicit-arrow-linebreak */
22
const {
33
doc: {
4-
builders: { join }
4+
builders: { concat, group, indent, line }
55
}
66
} = require('prettier');
77

88
const Conditional = {
99
print: ({ path, print }) =>
10-
join(' ', [
11-
path.call(print, 'condition'),
12-
'?',
13-
path.call(print, 'trueExpression'),
14-
':',
15-
path.call(print, 'falseExpression')
16-
])
10+
group(
11+
concat([
12+
path.call(print, 'condition'),
13+
indent(line),
14+
'? ',
15+
path.call(print, 'trueExpression'),
16+
indent(line),
17+
': ',
18+
path.call(print, 'falseExpression')
19+
])
20+
)
1721
};
1822

1923
module.exports = Conditional;

tests/Conditional/Conditional.sol

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pragma solidity ^0.4.24;
2+
3+
4+
contract Conditional {
5+
function foo() {
6+
address contextAddress = longAddress_ == address(0) ? msg.sender : currentContextAddress_;
7+
}
8+
9+
// TODO: work with a break in the condition level.
10+
// function foo() {
11+
// address contextAddress = veryVeryVeryVeryVeryVeryVeryVeryVeryLongAddress_ == address(0) ? msg.sender : currentContextAddress_;
12+
// }
13+
14+
function bar() {
15+
uint a = true ? 0 : 1;
16+
}
17+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Conditional.sol 1`] = `
4+
pragma solidity ^0.4.24;
5+
6+
7+
contract Conditional {
8+
function foo() {
9+
address contextAddress = longAddress_ == address(0) ? msg.sender : currentContextAddress_;
10+
}
11+
12+
// TODO: work with a break in the condition level.
13+
// function foo() {
14+
// address contextAddress = veryVeryVeryVeryVeryVeryVeryVeryVeryLongAddress_ == address(0) ? msg.sender : currentContextAddress_;
15+
// }
16+
17+
function bar() {
18+
uint a = true ? 0 : 1;
19+
}
20+
}
21+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22+
pragma solidity ^0.4.24;
23+
24+
contract Conditional {
25+
function foo() {
26+
address contextAddress = longAddress_ == address(0)
27+
? msg.sender
28+
: currentContextAddress_;
29+
}
30+
31+
// TODO: work with a break in the condition level.
32+
// function foo() {
33+
// address contextAddress = veryVeryVeryVeryVeryVeryVeryVeryVeryLongAddress_ == address(0) ? msg.sender : currentContextAddress_;
34+
// }
35+
36+
function bar() {
37+
uint a = true ? 0 : 1;
38+
}
39+
}
40+
41+
`;

tests/Conditional/jsfmt.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run_spec(__dirname);

0 commit comments

Comments
 (0)