Skip to content

Commit b9de415

Browse files
authored
We indent only if the chain doesn't belong to a variable declaration or a binary operation (#516)
1 parent b620a89 commit b9de415

4 files changed

Lines changed: 261 additions & 3 deletions

File tree

src/nodes/MemberAccess.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,28 @@ const isBeginnigOfChain = (path) => {
1616
return true;
1717
};
1818

19+
const shallIndent = (path) => {
20+
let i = 0;
21+
let elderNode = path.getParentNode(i);
22+
while (elderNode) {
23+
if (
24+
elderNode.type === 'VariableDeclarationStatement' ||
25+
elderNode.type === 'BinaryOperation'
26+
)
27+
return false;
28+
i += 1;
29+
elderNode = path.getParentNode(i);
30+
}
31+
return true;
32+
};
33+
1934
const MemberAccess = {
2035
print: ({ node, path, print }) => {
2136
const doc = [
2237
path.call(print, 'expression'),
23-
indent([softline, '.', node.memberName])
38+
shallIndent(path)
39+
? indent([softline, '.', node.memberName])
40+
: [softline, '.', node.memberName]
2441
];
2542

2643
return isBeginnigOfChain(path) ? group(doc) : doc;

tests/FunctionCalls/FunctionCalls.sol

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,25 @@ contract FunctionCalls {
1616
voted: true,
1717
});
1818
}
19+
function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) {
20+
address signer =
21+
_hashTypedDataV1(
22+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
23+
)
24+
._hashTypedDataV2(
25+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
26+
)._hashTypedDataV3(
27+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
28+
) .recover(signature);
29+
signer =
30+
_hashTypedDataV1(
31+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
32+
)
33+
._hashTypedDataV2(
34+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
35+
)._hashTypedDataV3(
36+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
37+
) .recover(signature);
38+
return _nonces[req.from] == req.nonce && signer == req.from;
39+
}
1940
}

tests/FunctionCalls/__snapshots__/jsfmt.spec.js.snap

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ contract FunctionCalls {
2525
voted: true,
2626
});
2727
}
28+
function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) {
29+
address signer =
30+
_hashTypedDataV1(
31+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
32+
)
33+
._hashTypedDataV2(
34+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
35+
)._hashTypedDataV3(
36+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
37+
) .recover(signature);
38+
signer =
39+
_hashTypedDataV1(
40+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
41+
)
42+
._hashTypedDataV2(
43+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
44+
)._hashTypedDataV3(
45+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
46+
) .recover(signature);
47+
return _nonces[req.from] == req.nonce && signer == req.from;
48+
}
2849
}
2950
3051
=====================================output=====================================
@@ -41,6 +62,95 @@ contract FunctionCalls {
4162
4263
Voter airbnb = Voter({ weight: 2, voted: true });
4364
}
65+
66+
function verify(ForwardRequest calldata req, bytes calldata signature)
67+
public
68+
view
69+
returns (bool)
70+
{
71+
address signer =
72+
_hashTypedDataV1(
73+
keccak256(
74+
abi.encode(
75+
TYPEHASH,
76+
req.from,
77+
req.to,
78+
req.value,
79+
req.gas,
80+
req.nonce,
81+
keccak256(req.data)
82+
)
83+
)
84+
)
85+
._hashTypedDataV2(
86+
keccak256(
87+
abi.encode(
88+
TYPEHASH,
89+
req.from,
90+
req.to,
91+
req.value,
92+
req.gas,
93+
req.nonce,
94+
keccak256(req.data)
95+
)
96+
)
97+
)
98+
._hashTypedDataV3(
99+
keccak256(
100+
abi.encode(
101+
TYPEHASH,
102+
req.from,
103+
req.to,
104+
req.value,
105+
req.gas,
106+
req.nonce,
107+
keccak256(req.data)
108+
)
109+
)
110+
)
111+
.recover(signature);
112+
signer = _hashTypedDataV1(
113+
keccak256(
114+
abi.encode(
115+
TYPEHASH,
116+
req.from,
117+
req.to,
118+
req.value,
119+
req.gas,
120+
req.nonce,
121+
keccak256(req.data)
122+
)
123+
)
124+
)
125+
._hashTypedDataV2(
126+
keccak256(
127+
abi.encode(
128+
TYPEHASH,
129+
req.from,
130+
req.to,
131+
req.value,
132+
req.gas,
133+
req.nonce,
134+
keccak256(req.data)
135+
)
136+
)
137+
)
138+
._hashTypedDataV3(
139+
keccak256(
140+
abi.encode(
141+
TYPEHASH,
142+
req.from,
143+
req.to,
144+
req.value,
145+
req.gas,
146+
req.nonce,
147+
keccak256(req.data)
148+
)
149+
)
150+
)
151+
.recover(signature);
152+
return _nonces[req.from] == req.nonce && signer == req.from;
153+
}
44154
}
45155
46156
================================================================================
@@ -70,6 +180,27 @@ contract FunctionCalls {
70180
voted: true,
71181
});
72182
}
183+
function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) {
184+
address signer =
185+
_hashTypedDataV1(
186+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
187+
)
188+
._hashTypedDataV2(
189+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
190+
)._hashTypedDataV3(
191+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
192+
) .recover(signature);
193+
signer =
194+
_hashTypedDataV1(
195+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
196+
)
197+
._hashTypedDataV2(
198+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
199+
)._hashTypedDataV3(
200+
keccak256(abi.encode(TYPEHASH, req.from, req.to, req.value, req.gas, req.nonce, keccak256(req.data)))
201+
) .recover(signature);
202+
return _nonces[req.from] == req.nonce && signer == req.from;
203+
}
73204
}
74205
75206
=====================================output=====================================
@@ -86,6 +217,95 @@ contract FunctionCalls {
86217
87218
Voter airbnb = Voter({weight: 2, voted: true});
88219
}
220+
221+
function verify(ForwardRequest calldata req, bytes calldata signature)
222+
public
223+
view
224+
returns (bool)
225+
{
226+
address signer =
227+
_hashTypedDataV1(
228+
keccak256(
229+
abi.encode(
230+
TYPEHASH,
231+
req.from,
232+
req.to,
233+
req.value,
234+
req.gas,
235+
req.nonce,
236+
keccak256(req.data)
237+
)
238+
)
239+
)
240+
._hashTypedDataV2(
241+
keccak256(
242+
abi.encode(
243+
TYPEHASH,
244+
req.from,
245+
req.to,
246+
req.value,
247+
req.gas,
248+
req.nonce,
249+
keccak256(req.data)
250+
)
251+
)
252+
)
253+
._hashTypedDataV3(
254+
keccak256(
255+
abi.encode(
256+
TYPEHASH,
257+
req.from,
258+
req.to,
259+
req.value,
260+
req.gas,
261+
req.nonce,
262+
keccak256(req.data)
263+
)
264+
)
265+
)
266+
.recover(signature);
267+
signer = _hashTypedDataV1(
268+
keccak256(
269+
abi.encode(
270+
TYPEHASH,
271+
req.from,
272+
req.to,
273+
req.value,
274+
req.gas,
275+
req.nonce,
276+
keccak256(req.data)
277+
)
278+
)
279+
)
280+
._hashTypedDataV2(
281+
keccak256(
282+
abi.encode(
283+
TYPEHASH,
284+
req.from,
285+
req.to,
286+
req.value,
287+
req.gas,
288+
req.nonce,
289+
keccak256(req.data)
290+
)
291+
)
292+
)
293+
._hashTypedDataV3(
294+
keccak256(
295+
abi.encode(
296+
TYPEHASH,
297+
req.from,
298+
req.to,
299+
req.value,
300+
req.gas,
301+
req.nonce,
302+
keccak256(req.data)
303+
)
304+
)
305+
)
306+
.recover(signature);
307+
return _nonces[req.from] == req.nonce && signer == req.from;
308+
}
89309
}
90310
91311
================================================================================

tests/Issues/__snapshots__/jsfmt.spec.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ contract Example {
3333
balanceStates[msg.sender][token].balance = balanceStates[msg.sender][
3434
token
3535
]
36-
.balance
37-
.sub(amount);
36+
.balance
37+
.sub(amount);
3838
}
3939
}
4040

0 commit comments

Comments
 (0)