Skip to content

Commit

Permalink
Assignment in the same line (#520)
Browse files Browse the repository at this point in the history
* Variable declaration with initial values behaves similarly to variable assignment

* lint
  • Loading branch information
Janther authored Jun 5, 2021
1 parent 594c158 commit fe4ec01
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 98 deletions.
6 changes: 2 additions & 4 deletions src/nodes/VariableDeclarationStatement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
doc: {
builders: { group, indent, line }
builders: { group }
}
} = require('prettier/standalone');

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

const initialValue = (node, path, print) =>
node.initialValue
? group([' =', indent([line, path.call(print, 'initialValue')])])
: '';
node.initialValue ? [' = ', path.call(print, 'initialValue')] : '';

const VariableDeclarationStatement = {
print: ({ node, path, print }) => {
Expand Down
6 changes: 4 additions & 2 deletions tests/Arrays/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ contract Arrays {
];
function a() {
Outcome.OutcomeItem[] memory outcomeFrom =
abi.decode(fromPart.outcome, (Outcome.OutcomeItem[]));
Outcome.OutcomeItem[] memory outcomeFrom = abi.decode(
fromPart.outcome,
(Outcome.OutcomeItem[])
);
}
}
Expand Down
5 changes: 3 additions & 2 deletions tests/Conditional/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ pragma solidity ^0.4.24;
contract Conditional {
function foo() {
address contextAddress =
longAddress_ == address(0) ? msg.sender : currentContextAddress_;
address contextAddress = longAddress_ == address(0)
? msg.sender
: currentContextAddress_;
asset == ETH
? require(
address(uint160(msg.sender)).send(quantity),
Expand Down
146 changes: 72 additions & 74 deletions tests/FunctionCalls/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ contract FunctionCalls {
=====================================output=====================================
contract FunctionCalls {
function foo() {
address veryLongValidatorAddress =
veryVeryVeryLongSignature.popLast20Bytes();
address veryLongValidatorAddress = veryVeryVeryLongSignature
.popLast20Bytes();
}
function foo() {
Expand All @@ -68,44 +68,43 @@ contract FunctionCalls {
view
returns (bool)
{
address signer =
_hashTypedDataV1(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
address signer = _hashTypedDataV1(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)._hashTypedDataV2(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)._hashTypedDataV2(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)._hashTypedDataV3(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)._hashTypedDataV3(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
).recover(signature);
)
).recover(signature);
signer = _hashTypedDataV1(
keccak256(
abi.encode(
Expand Down Expand Up @@ -200,8 +199,8 @@ contract FunctionCalls {
=====================================output=====================================
contract FunctionCalls {
function foo() {
address veryLongValidatorAddress =
veryVeryVeryLongSignature.popLast20Bytes();
address veryLongValidatorAddress = veryVeryVeryLongSignature
.popLast20Bytes();
}
function foo() {
Expand All @@ -217,44 +216,43 @@ contract FunctionCalls {
view
returns (bool)
{
address signer =
_hashTypedDataV1(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
address signer = _hashTypedDataV1(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)._hashTypedDataV2(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)._hashTypedDataV2(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)._hashTypedDataV3(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
)
)._hashTypedDataV3(
keccak256(
abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
)
).recover(signature);
)
).recover(signature);
signer = _hashTypedDataV1(
keccak256(
abi.encode(
Expand Down
6 changes: 4 additions & 2 deletions tests/Issues/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ contract Issue289 {
=====================================output=====================================
contract Issue289 {
function f() {
address[] storage proposalValidators =
ethProposals[_blockNumber][_proposalId].proposalValidators;
address[] storage proposalValidators = ethProposals[_blockNumber][
_proposalId
]
.proposalValidators;
}
}
Expand Down
21 changes: 10 additions & 11 deletions tests/SplittableCommodity/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ contract SplittableCommodity is MintableCommodity {
address _to,
uint256 _amount
) public whenNotPaused {
address supplierProxy =
IContractRegistry(contractRegistry).getLatestProxyAddr("Supplier");
address supplierProxy = IContractRegistry(contractRegistry)
.getLatestProxyAddr("Supplier");
require(
msg.sender ==
IContractRegistry(contractRegistry).getLatestProxyAddr(
Expand All @@ -100,15 +100,14 @@ contract SplittableCommodity is MintableCommodity {
commodities[_tokenId].value = commodities[_tokenId].value.sub(_amount);
CommodityLib.Commodity memory _commodity =
CommodityLib.Commodity({
category: uint64(1),
timeRegistered: uint64(now), // solium-disable-line
parentId: _tokenId,
value: _amount,
locked: false,
misc: commodities[_tokenId].misc
});
CommodityLib.Commodity memory _commodity = CommodityLib.Commodity({
category: uint64(1),
timeRegistered: uint64(now), // solium-disable-line
parentId: _tokenId,
value: _amount,
locked: false,
misc: commodities[_tokenId].misc
});
uint256 newCRCId = commodities.push(_commodity).sub(1);
require(
newCRCId <= 18446744073709551616,
Expand Down
5 changes: 2 additions & 3 deletions tests/strings/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1483,9 +1483,8 @@ library strings {
pure
returns (uint256 cnt)
{
uint256 ptr =
findPtr(self._len, self._ptr, needle._len, needle._ptr) +
needle._len;
uint256 ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) +
needle._len;
while (ptr <= self._ptr + self._len) {
cnt++;
ptr =
Expand Down

0 comments on commit fe4ec01

Please sign in to comment.