Skip to content

Commit c7099f8

Browse files
Janthermattiaerre
authored andcommitted
when having multiple base contracts we split the Base contracts and keep the is keyword in the first line. (#134)
1 parent ee84287 commit c7099f8

File tree

4 files changed

+60
-22
lines changed

4 files changed

+60
-22
lines changed

src/nodes/ContractDefinition.js

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,53 @@
1+
/* eslint-disable implicit-arrow-linebreak */
12
const {
23
doc: {
3-
builders: { concat, indent, join, line }
4+
builders: { concat, group, indent, join, line }
45
}
56
} = require('prettier');
67
const printPreservingEmptyLines = require('./print-preserving-empty-lines');
78

8-
const ContractDefinition = {
9-
print: ({ node, options, path, print }) => {
10-
let parts = [node.kind, ' ', node.name];
11-
12-
if (node.baseContracts.length > 0) {
13-
parts = parts.concat([
14-
' is ',
15-
join(', ', path.map(print, 'baseContracts'))
16-
]);
17-
}
18-
19-
parts.push(' {');
20-
if (node.subNodes.length > 0) {
21-
parts = parts.concat([
22-
indent(line),
23-
indent(printPreservingEmptyLines(path, 'subNodes', options, print)),
24-
line
25-
]);
26-
}
27-
parts.push('}');
9+
const inheritance = (node, path, print) => {
10+
if (node.baseContracts.length > 0) {
11+
return concat([
12+
' is',
13+
indent(
14+
concat([
15+
line,
16+
join(concat([',', line]), path.map(print, 'baseContracts'))
17+
])
18+
)
19+
]);
20+
}
21+
return '';
22+
};
2823

29-
return concat(parts);
24+
const body = (node, path, options, print) => {
25+
if (node.subNodes.length > 0) {
26+
return concat([
27+
indent(line),
28+
indent(printPreservingEmptyLines(path, 'subNodes', options, print)),
29+
line
30+
]);
3031
}
32+
return '';
33+
};
34+
35+
const ContractDefinition = {
36+
print: ({ node, options, path, print }) =>
37+
concat([
38+
group(
39+
concat([
40+
node.kind,
41+
' ',
42+
node.name,
43+
inheritance(node, path, print),
44+
line,
45+
'{'
46+
])
47+
),
48+
body(node, path, options, print),
49+
'}'
50+
])
3151
};
3252

3353
module.exports = ContractDefinition;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
contract ContractDefinition is Contract1, Contract2, Contract3, Contract4, Contract5 {
2+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ContractDefinitions.sol 1`] = `
4+
contract ContractDefinition is Contract1, Contract2, Contract3, Contract4, Contract5 {
5+
}
6+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
contract ContractDefinition is
8+
Contract1,
9+
Contract2,
10+
Contract3,
11+
Contract4,
12+
Contract5
13+
{}
14+
15+
`;
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)