Skip to content

Commit e5f274b

Browse files
Janthermattiaerre
authored andcommitted
fixing array indentation and also solved the return statements. (#146)
1 parent 3e8b8c1 commit e5f274b

File tree

7 files changed

+66
-20
lines changed

7 files changed

+66
-20
lines changed

src/nodes/TupleExpression.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1+
/* eslint-disable implicit-arrow-linebreak */
12
const {
23
doc: {
3-
builders: { concat, join }
4+
builders: { concat, group, indent, join, line, softline }
45
}
56
} = require('prettier');
67

78
const TupleExpression = {
8-
print: ({ node, path, print }) => {
9-
let doc;
10-
// @TODO: remove hack once solidity-parser-antlr is fixed
11-
if (node.components) {
12-
doc = join(', ', path.map(print, 'components'));
13-
} else {
14-
doc = join(', ', path.map(print, 'elements'));
15-
}
16-
if (node.isArray) {
17-
return concat(['[', doc, ']']);
18-
}
19-
return concat(['(', doc, ')']);
20-
}
9+
// @TODO: remove hack once solidity-parser-antlr is fixed
10+
print: ({ node, path, print }) =>
11+
group(
12+
concat([
13+
node.isArray ? '[' : '(',
14+
indent(
15+
concat([
16+
softline,
17+
join(
18+
concat([',', line]),
19+
path.map(print, node.components ? 'components' : 'elements')
20+
)
21+
])
22+
),
23+
softline,
24+
node.isArray ? ']' : ')'
25+
])
26+
)
2127
};
2228

2329
module.exports = TupleExpression;

tests/Arrays/Arrays.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pragma solidity ^0.5.2;
2+
3+
contract Arrays {
4+
bytes32[] public permissions = [bytes32("addPartner"), bytes32("removePartner"), bytes32("addGroup"), bytes32("removeGroup"), bytes32("addUserToGroup"), bytes32("removeUserFromGroup"), bytes32("addSolution"), bytes32("removeSolution"), bytes32("addLibrary"), bytes32("removeLibrary"), bytes32("addPermissionToGroup"), bytes32("removePermissionFromGroup")];
5+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Arrays.sol 1`] = `
4+
pragma solidity ^0.5.2;
5+
6+
contract Arrays {
7+
bytes32[] public permissions = [bytes32("addPartner"), bytes32("removePartner"), bytes32("addGroup"), bytes32("removeGroup"), bytes32("addUserToGroup"), bytes32("removeUserFromGroup"), bytes32("addSolution"), bytes32("removeSolution"), bytes32("addLibrary"), bytes32("removeLibrary"), bytes32("addPermissionToGroup"), bytes32("removePermissionFromGroup")];
8+
}
9+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10+
pragma solidity ^0.5.2;
11+
12+
contract Arrays {
13+
bytes32[] public permissions = [
14+
bytes32("addPartner"),
15+
bytes32("removePartner"),
16+
bytes32("addGroup"),
17+
bytes32("removeGroup"),
18+
bytes32("addUserToGroup"),
19+
bytes32("removeUserFromGroup"),
20+
bytes32("addSolution"),
21+
bytes32("removeSolution"),
22+
bytes32("addLibrary"),
23+
bytes32("removeLibrary"),
24+
bytes32("addPermissionToGroup"),
25+
bytes32("removePermissionFromGroup")
26+
];
27+
}
28+
29+
`;

tests/Arrays/jsfmt.spec.js

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

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ contract IndexOf {
8787
if (a.length < 1 || b.length < 1 || (b.length > a.length)) {
8888
whatwastheval = -1;
8989
return -1;
90-
} else if (a.length > (2 ** 128 - 1)) // since we have to be able to return -1 (if the char isn't found or input error), this function must return an "int" type with a max length of (2^128 - 1)
90+
} else if (a.length > (
91+
2 ** 128 - 1
92+
)) // since we have to be able to return -1 (if the char isn't found or input error), this function must return an "int" type with a max length of (2^128 - 1)
9193
{
9294
whatwastheval = -1;
9395
return -1;
@@ -97,7 +99,9 @@ contract IndexOf {
9799
if (a[i] == b[0]) // found the first char of b
98100
{
99101
subindex = 1;
100-
while (subindex < b.length && (i + subindex) < a.length && a[i + subindex] == b[subindex]) { // search until the chars don't match or until we reach the end of a or b
102+
while (subindex < b.length && (
103+
i + subindex
104+
) < a.length && a[i + subindex] == b[subindex]) { // search until the chars don't match or until we reach the end of a or b
101105
subindex++;
102106
}
103107
if (subindex == b.length) {

tests/StyleGuide/FunctionDeclaration.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ contract FunctionDeclaration {
8181
{
8282
doSomething();
8383

84-
/* TODO: long return list should split */
8584
return (veryVeryLongReturnArg1,
8685
veryVeryLongReturnArg1,
8786
veryVeryLongReturnArg1);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ contract FunctionDeclaration {
250250
{
251251
doSomething();
252252
253-
/* TODO: long return list should split */
254253
return (veryVeryLongReturnArg1,
255254
veryVeryLongReturnArg1,
256255
veryVeryLongReturnArg1);
@@ -398,8 +397,11 @@ contract FunctionDeclaration {
398397
{
399398
doSomething();
400399
401-
/* TODO: long return list should split */
402-
return (veryVeryLongReturnArg1, veryVeryLongReturnArg1, veryVeryLongReturnArg1);
400+
return (
401+
veryVeryLongReturnArg1,
402+
veryVeryLongReturnArg1,
403+
veryVeryLongReturnArg1
404+
);
403405
}
404406
}
405407

0 commit comments

Comments
 (0)