Skip to content

Commit fe4ec01

Browse files
authored
Assignment in the same line (#520)
* Variable declaration with initial values behaves similarly to variable assignment * lint
1 parent 594c158 commit fe4ec01

File tree

7 files changed

+97
-98
lines changed

7 files changed

+97
-98
lines changed

src/nodes/VariableDeclarationStatement.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const {
22
doc: {
3-
builders: { group, indent, line }
3+
builders: { group }
44
}
55
} = require('prettier/standalone');
66

@@ -9,9 +9,7 @@ const printSeparatedList = require('./print-separated-list');
99
const embraceVariables = (doc, embrace) => (embrace ? ['(', doc, ')'] : doc);
1010

1111
const initialValue = (node, path, print) =>
12-
node.initialValue
13-
? group([' =', indent([line, path.call(print, 'initialValue')])])
14-
: '';
12+
node.initialValue ? [' = ', path.call(print, 'initialValue')] : '';
1513

1614
const VariableDeclarationStatement = {
1715
print: ({ node, path, print }) => {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ contract Arrays {
4444
];
4545
4646
function a() {
47-
Outcome.OutcomeItem[] memory outcomeFrom =
48-
abi.decode(fromPart.outcome, (Outcome.OutcomeItem[]));
47+
Outcome.OutcomeItem[] memory outcomeFrom = abi.decode(
48+
fromPart.outcome,
49+
(Outcome.OutcomeItem[])
50+
);
4951
}
5052
}
5153

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ pragma solidity ^0.4.24;
3838
3939
contract Conditional {
4040
function foo() {
41-
address contextAddress =
42-
longAddress_ == address(0) ? msg.sender : currentContextAddress_;
41+
address contextAddress = longAddress_ == address(0)
42+
? msg.sender
43+
: currentContextAddress_;
4344
asset == ETH
4445
? require(
4546
address(uint160(msg.sender)).send(quantity),

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

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ contract FunctionCalls {
5151
=====================================output=====================================
5252
contract FunctionCalls {
5353
function foo() {
54-
address veryLongValidatorAddress =
55-
veryVeryVeryLongSignature.popLast20Bytes();
54+
address veryLongValidatorAddress = veryVeryVeryLongSignature
55+
.popLast20Bytes();
5656
}
5757
5858
function foo() {
@@ -68,44 +68,43 @@ contract FunctionCalls {
6868
view
6969
returns (bool)
7070
{
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-
)
71+
address signer = _hashTypedDataV1(
72+
keccak256(
73+
abi.encode(
74+
TYPEHASH,
75+
req.from,
76+
req.to,
77+
req.value,
78+
req.gas,
79+
req.nonce,
80+
keccak256(req.data)
8381
)
84-
)._hashTypedDataV2(
85-
keccak256(
86-
abi.encode(
87-
TYPEHASH,
88-
req.from,
89-
req.to,
90-
req.value,
91-
req.gas,
92-
req.nonce,
93-
keccak256(req.data)
94-
)
82+
)
83+
)._hashTypedDataV2(
84+
keccak256(
85+
abi.encode(
86+
TYPEHASH,
87+
req.from,
88+
req.to,
89+
req.value,
90+
req.gas,
91+
req.nonce,
92+
keccak256(req.data)
9593
)
96-
)._hashTypedDataV3(
97-
keccak256(
98-
abi.encode(
99-
TYPEHASH,
100-
req.from,
101-
req.to,
102-
req.value,
103-
req.gas,
104-
req.nonce,
105-
keccak256(req.data)
106-
)
94+
)
95+
)._hashTypedDataV3(
96+
keccak256(
97+
abi.encode(
98+
TYPEHASH,
99+
req.from,
100+
req.to,
101+
req.value,
102+
req.gas,
103+
req.nonce,
104+
keccak256(req.data)
107105
)
108-
).recover(signature);
106+
)
107+
).recover(signature);
109108
signer = _hashTypedDataV1(
110109
keccak256(
111110
abi.encode(
@@ -200,8 +199,8 @@ contract FunctionCalls {
200199
=====================================output=====================================
201200
contract FunctionCalls {
202201
function foo() {
203-
address veryLongValidatorAddress =
204-
veryVeryVeryLongSignature.popLast20Bytes();
202+
address veryLongValidatorAddress = veryVeryVeryLongSignature
203+
.popLast20Bytes();
205204
}
206205
207206
function foo() {
@@ -217,44 +216,43 @@ contract FunctionCalls {
217216
view
218217
returns (bool)
219218
{
220-
address signer =
221-
_hashTypedDataV1(
222-
keccak256(
223-
abi.encode(
224-
TYPEHASH,
225-
req.from,
226-
req.to,
227-
req.value,
228-
req.gas,
229-
req.nonce,
230-
keccak256(req.data)
231-
)
219+
address signer = _hashTypedDataV1(
220+
keccak256(
221+
abi.encode(
222+
TYPEHASH,
223+
req.from,
224+
req.to,
225+
req.value,
226+
req.gas,
227+
req.nonce,
228+
keccak256(req.data)
232229
)
233-
)._hashTypedDataV2(
234-
keccak256(
235-
abi.encode(
236-
TYPEHASH,
237-
req.from,
238-
req.to,
239-
req.value,
240-
req.gas,
241-
req.nonce,
242-
keccak256(req.data)
243-
)
230+
)
231+
)._hashTypedDataV2(
232+
keccak256(
233+
abi.encode(
234+
TYPEHASH,
235+
req.from,
236+
req.to,
237+
req.value,
238+
req.gas,
239+
req.nonce,
240+
keccak256(req.data)
244241
)
245-
)._hashTypedDataV3(
246-
keccak256(
247-
abi.encode(
248-
TYPEHASH,
249-
req.from,
250-
req.to,
251-
req.value,
252-
req.gas,
253-
req.nonce,
254-
keccak256(req.data)
255-
)
242+
)
243+
)._hashTypedDataV3(
244+
keccak256(
245+
abi.encode(
246+
TYPEHASH,
247+
req.from,
248+
req.to,
249+
req.value,
250+
req.gas,
251+
req.nonce,
252+
keccak256(req.data)
256253
)
257-
).recover(signature);
254+
)
255+
).recover(signature);
258256
signer = _hashTypedDataV1(
259257
keccak256(
260258
abi.encode(

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ contract Issue289 {
5757
=====================================output=====================================
5858
contract Issue289 {
5959
function f() {
60-
address[] storage proposalValidators =
61-
ethProposals[_blockNumber][_proposalId].proposalValidators;
60+
address[] storage proposalValidators = ethProposals[_blockNumber][
61+
_proposalId
62+
]
63+
.proposalValidators;
6264
}
6365
}
6466

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ contract SplittableCommodity is MintableCommodity {
8787
address _to,
8888
uint256 _amount
8989
) public whenNotPaused {
90-
address supplierProxy =
91-
IContractRegistry(contractRegistry).getLatestProxyAddr("Supplier");
90+
address supplierProxy = IContractRegistry(contractRegistry)
91+
.getLatestProxyAddr("Supplier");
9292
require(
9393
msg.sender ==
9494
IContractRegistry(contractRegistry).getLatestProxyAddr(
@@ -100,15 +100,14 @@ contract SplittableCommodity is MintableCommodity {
100100
101101
commodities[_tokenId].value = commodities[_tokenId].value.sub(_amount);
102102
103-
CommodityLib.Commodity memory _commodity =
104-
CommodityLib.Commodity({
105-
category: uint64(1),
106-
timeRegistered: uint64(now), // solium-disable-line
107-
parentId: _tokenId,
108-
value: _amount,
109-
locked: false,
110-
misc: commodities[_tokenId].misc
111-
});
103+
CommodityLib.Commodity memory _commodity = CommodityLib.Commodity({
104+
category: uint64(1),
105+
timeRegistered: uint64(now), // solium-disable-line
106+
parentId: _tokenId,
107+
value: _amount,
108+
locked: false,
109+
misc: commodities[_tokenId].misc
110+
});
112111
uint256 newCRCId = commodities.push(_commodity).sub(1);
113112
require(
114113
newCRCId <= 18446744073709551616,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,9 +1483,8 @@ library strings {
14831483
pure
14841484
returns (uint256 cnt)
14851485
{
1486-
uint256 ptr =
1487-
findPtr(self._len, self._ptr, needle._len, needle._ptr) +
1488-
needle._len;
1486+
uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) +
1487+
needle._len;
14891488
while (ptr <= self._ptr + self._len) {
14901489
cnt++;
14911490
ptr =

0 commit comments

Comments
 (0)