Skip to content

Commit 05a0508

Browse files
Janthermattiaerre
authored andcommitted
adding commas between arguments and indenting the arguments (#212)
1 parent 2f53681 commit 05a0508

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

src/nodes/InheritanceSpecifier.js

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

7-
const InheritanceSpecifier = {
8-
print: ({ node, path, print }) => {
9-
let parts = [path.call(print, 'baseName')];
7+
const printArguments = (node, path, print) => {
8+
if (node.arguments && node.arguments.length) {
9+
return group(
10+
concat([
11+
'(',
12+
indent(
13+
concat([
14+
softline,
15+
join(concat([',', line]), path.map(print, 'arguments'))
16+
])
17+
),
18+
softline,
19+
')'
20+
])
21+
);
22+
}
1023

11-
if (node.arguments && node.arguments.length) {
12-
parts.push('(');
13-
parts = parts.concat(path.map(print, 'arguments'));
14-
parts.push(')');
15-
}
24+
return '';
25+
};
1626

17-
return concat(parts);
18-
}
27+
const InheritanceSpecifier = {
28+
print: ({ node, path, print }) =>
29+
concat([path.call(print, 'baseName'), printArguments(node, path, print)])
1930
};
2031

2132
module.exports = InheritanceSpecifier;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
contract InheritanceSpecifier is SomeOtherContract(1234,false) {}
2+
contract LongInheritanceSpecifier is SomeOtherContract(123467890,false,0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c) {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`InheritanceSpecifier.sol 1`] = `
4+
contract InheritanceSpecifier is SomeOtherContract(1234,false) {}
5+
contract LongInheritanceSpecifier is SomeOtherContract(123467890,false,0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c) {}
6+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
contract InheritanceSpecifier is SomeOtherContract(1234, false) {}
8+
contract LongInheritanceSpecifier is
9+
SomeOtherContract(
10+
123467890,
11+
false,
12+
0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c
13+
)
14+
{}
15+
16+
`;
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)