Skip to content

Commit f481547

Browse files
committed
Merge remote-tracking branch 'origin/main' into v2
# Conflicts: # package-lock.json # package.json # tests/format/Comments/__snapshots__/format.test.js.snap # tests/format/InheritanceSpecifier/__snapshots__/format.test.js.snap
2 parents 8cae601 + 0af6913 commit f481547

File tree

13 files changed

+374
-52
lines changed

13 files changed

+374
-52
lines changed

FUNDING.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

funding.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"drips": {
3+
"ethereum": { "ownedBy": "0x2E4BE2aEd637E1EbC712f8169f25f0b48e1cbb58" }
4+
},
5+
"opRetro": {
6+
"projectId": "0xc6cac7cd3793888032cc8a9e5aef92550beeec2598f86f1ec6972ffd5b82a990"
7+
}
8+
}

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"c8": "^10.1.3",
9292
"cross-env": "^7.0.3",
9393
"eslint": "^9.25.1",
94-
"eslint-config-prettier": "10.1.2",
94+
"eslint-config-prettier": "^10.1.2",
9595
"esm-utils": "^4.3.0",
9696
"jest": "^29.7.0",
9797
"jest-light-runner": "^0.7.8",
@@ -109,7 +109,7 @@
109109
},
110110
"dependencies": {
111111
"@nomicfoundation/slang": "1.0.0",
112-
"@solidity-parser/parser": "^0.19.0",
112+
"@solidity-parser/parser": "^0.20.1",
113113
"semver": "^7.7.1"
114114
},
115115
"peerDependencies": {

src/comments/handlers/handleContractDefinitionComments.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ function handleContractDefinitionComments({
2727
);
2828

2929
// The comment is behind the start of the Block `{}` or behind a base contract
30-
if (followingNode?.type === 'InheritanceSpecifier' || nextCharacter === '{') {
30+
if (
31+
(followingNode &&
32+
(followingNode.type === 'InheritanceSpecifier' ||
33+
followingNode === enclosingNode.storageLayout)) ||
34+
nextCharacter === '{'
35+
) {
3136
// In this scenario the comment belongs to a base contract.
3237
// contract A is B, /* comment for B */ C /* comment for C */ {}
33-
if (precedingNode?.type === 'InheritanceSpecifier') {
38+
if (
39+
precedingNode &&
40+
(precedingNode.type === 'InheritanceSpecifier' ||
41+
precedingNode === enclosingNode.storageLayout)
42+
) {
3443
addTrailingComment(precedingNode, comment);
3544
return true;
3645
}

src/nodes/ContractDefinition.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,37 @@ import {
66
printSeparatedList
77
} from '../common/printer-helpers.js';
88

9-
const { group, line, hardline } = doc.builders;
9+
const { group, hardline, ifBreak, line, softline } = doc.builders;
1010

11-
const inheritance = (node, path, print) =>
12-
node.baseContracts.length > 0
13-
? [
14-
' is',
15-
printSeparatedList(path.map(print, 'baseContracts'), {
16-
firstSeparator: line
17-
})
18-
]
19-
: line;
11+
const specifiers = (node, path, print) => {
12+
const document = [];
13+
if (node.baseContracts.length > 0) {
14+
document.push([
15+
'is',
16+
printSeparatedList(path.map(print, 'baseContracts'), {
17+
firstSeparator: line
18+
})
19+
]);
20+
}
21+
if (node.storageLayout) {
22+
document.push([
23+
'layout at',
24+
printSeparatedItem(path.call(print, 'storageLayout'), {
25+
firstSeparator: line
26+
})
27+
]);
28+
}
29+
if (document.length === 0) return line;
30+
if (document.length === 1) return [' ', document];
31+
const groupId = Symbol('ContractSpecifiers.inheritance');
32+
return printSeparatedList(
33+
[group(document[0], { id: groupId }), document[1]],
34+
{
35+
firstSeparator: line,
36+
separator: ifBreak('', softline, { groupId })
37+
}
38+
);
39+
};
2040

2141
const body = (node, path, options, print) => {
2242
const comments = printComments(node, path, options);
@@ -34,7 +54,7 @@ export const ContractDefinition = {
3454
node.kind === 'abstract' ? 'abstract contract' : node.kind,
3555
' ',
3656
node.name,
37-
inheritance(node, path, print),
57+
specifiers(node, path, print),
3858
'{'
3959
]),
4060
body(node, path, options, print),

tests/format/Comments/Comments.sol

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ contract Comments4 is Interface1, Interface2, Interface3, Interface4, Interface5
3838
// solhint-disable-previous-line no-empty-blocks
3939
}
4040

41+
contract Comments4a is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 /*why we used Interface6*/ layout /*where should this go?*/at 123/*why we used this layout*/ {
42+
// solhint-disable-previous-line no-empty-blocks
43+
}
44+
45+
contract Comments4b is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 /*why we used Interface6*/ layout /*where should this go?*/at 123 + 456/*why we used this layout*/ {
46+
// solhint-disable-previous-line no-empty-blocks
47+
}
48+
49+
contract Comments4c is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 /*why we used Interface6*/ layout /*where should this go?*/at f(123 + 456)/*why we used this layout*/ {
50+
// solhint-disable-previous-line no-empty-blocks
51+
}
52+
4153
contract Comments5 /*nice name*/ {
4254
// solhint-disable-previous-line no-empty-blocks
4355
}

tests/format/Comments/__snapshots__/format.test.js.snap

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ contract Comments4 is Interface1, Interface2, Interface3, Interface4, Interface5
4646
// solhint-disable-previous-line no-empty-blocks
4747
}
4848
49+
contract Comments4a is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 /*why we used Interface6*/ layout /*where should this go?*/at 123/*why we used this layout*/ {
50+
// solhint-disable-previous-line no-empty-blocks
51+
}
52+
53+
contract Comments4b is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 /*why we used Interface6*/ layout /*where should this go?*/at 123 + 456/*why we used this layout*/ {
54+
// solhint-disable-previous-line no-empty-blocks
55+
}
56+
57+
contract Comments4c is Interface1, Interface2, Interface3, Interface4, Interface5, Interface6 /*why we used Interface6*/ layout /*where should this go?*/at f(123 + 456)/*why we used this layout*/ {
58+
// solhint-disable-previous-line no-empty-blocks
59+
}
60+
4961
contract Comments5 /*nice name*/ {
5062
// solhint-disable-previous-line no-empty-blocks
5163
}
@@ -221,7 +233,46 @@ contract Comments4 is
221233
// solhint-disable-previous-line no-empty-blocks
222234
}
223235
224-
contract Comments5 /*nice name*/ {
236+
contract Comments4a
237+
is
238+
Interface1,
239+
Interface2,
240+
Interface3,
241+
Interface4,
242+
Interface5,
243+
Interface6 /*why we used Interface6*/ /*where should this go?*/
244+
layout at 123 /*why we used this layout*/
245+
{
246+
// solhint-disable-previous-line no-empty-blocks
247+
}
248+
249+
contract Comments4b
250+
is
251+
Interface1,
252+
Interface2,
253+
Interface3,
254+
Interface4,
255+
Interface5,
256+
Interface6 /*why we used Interface6*/ /*where should this go?*/
257+
layout at 123 + 456 /*why we used this layout*/
258+
{
259+
// solhint-disable-previous-line no-empty-blocks
260+
}
261+
262+
contract Comments4c
263+
is
264+
Interface1,
265+
Interface2,
266+
Interface3,
267+
Interface4,
268+
Interface5,
269+
Interface6 /*why we used Interface6*/ /*where should this go?*/
270+
layout at f(123 + 456) /*why we used this layout*/
271+
{
272+
// solhint-disable-previous-line no-empty-blocks
273+
}
274+
275+
/*nice name*/ contract Comments5 {
225276
// solhint-disable-previous-line no-empty-blocks
226277
}
227278
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
11
contract ContractDefinition is Contract1, Contract2, Contract3, Contract4, Contract5 {
22
}
3+
4+
contract StorageLayoutSpecifier layout at 123 {
5+
}
6+
7+
contract StorageLayoutSpecifier1 layout at 1234567890 * 1234567890 - 1234567890 / 1234567890 {
8+
}
9+
10+
contract StorageLayoutSpecifier2 layout at veryVeryLongFunction(12345678901234567890 * 12345678901234567890 - 12345678901234567890 / 12345678901234567890 + 12345678901234567890 - 12345678901234567890) {
11+
}
12+
13+
contract StorageLayoutSpecifier3 is Contract1 layout at 123 {
14+
}
15+
16+
contract StorageLayoutSpecifier4 is Contract1, Contract2, Contract3, Contract4, Contract5 layout at 123{
17+
}
18+
19+
contract StorageLayoutSpecifier5 is Contract1, Contract2, Contract3, Contract4, Contract5 layout at 1234567890 * 1234567890 - 1234567890 / 1234567890{
20+
}
21+
22+
contract StorageLayoutSpecifier6 is Contract1, Contract2, Contract3, Contract4, Contract5 layout at veryVeryLongFunction(12345678901234567890 * 12345678901234567890 - 12345678901234567890 / 12345678901234567890 + 12345678901234567890 - 12345678901234567890){
23+
}
24+
25+
contract StorageLayoutSpecifier7 is Contract1, Contract2, Contract3, Contract4, Contract5, Contract6, Contract7 layout at 123{
26+
}
27+
28+
contract StorageLayoutSpecifier8 is Contract1, Contract2, Contract3, Contract4, Contract5, Contract6, Contract7 layout at 1234567890 * 1234567890 - 1234567890 / 1234567890{
29+
}
30+
31+
contract StorageLayoutSpecifier9 is Contract1, Contract2, Contract3, Contract4, Contract5, Contract6, Contract7 layout at veryVeryLongFunction(12345678901234567890 * 12345678901234567890 - 12345678901234567890 / 12345678901234567890 + 12345678901234567890 - 12345678901234567890){
32+
}
33+
34+
contract InheritanceSpecifier1 is SomeOtherContract(1234,false) {}
35+
36+
contract InheritanceSpecifier2 is SomeOtherContract(1234,false) layout at 123 {}
37+
38+
contract InheritanceSpecifier3 is SomeOtherContract(1234,false) layout at 1234567890 * 1234567890 - 1234567890 / 1234567890 {}
39+
40+
contract InheritanceSpecifier4 is SomeOtherContract(1234,false) layout at veryVeryLongFunction(12345678901234567890 * 12345678901234567890 - 12345678901234567890 / 12345678901234567890 + 12345678901234567890 - 12345678901234567890) {}
41+
42+
contract LongInheritanceSpecifier1 is SomeOtherContract(123467890,false,0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c) {}
43+
44+
contract LongInheritanceSpecifier2 is SomeOtherContract(123467890,false,0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c) layout at 123 {}
45+
46+
contract LongInheritanceSpecifier3 is SomeOtherContract(123467890,false,0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c) layout at 1234567890 * 1234567890 - 1234567890 / 1234567890 {}
47+
48+
contract LongInheritanceSpecifier4 is SomeOtherContract(123467890,false,0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c) layout at veryVeryLongFunction(12345678901234567890 * 12345678901234567890 - 12345678901234567890 / 12345678901234567890 + 12345678901234567890 - 12345678901234567890){}

0 commit comments

Comments
 (0)