Skip to content

Commit f974801

Browse files
committed
comments for storage layout
1 parent 48fbf9f commit f974801

3 files changed

Lines changed: 74 additions & 2 deletions

File tree

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
}

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__/jsfmt.spec.js.snap

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ contract Comments4 is Interface1, Interface2, Interface3, Interface4, Interface5
4747
// solhint-disable-previous-line no-empty-blocks
4848
}
4949
50+
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*/ {
51+
// solhint-disable-previous-line no-empty-blocks
52+
}
53+
54+
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*/ {
55+
// solhint-disable-previous-line no-empty-blocks
56+
}
57+
58+
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*/ {
59+
// solhint-disable-previous-line no-empty-blocks
60+
}
61+
5062
contract Comments5 /*nice name*/ {
5163
// solhint-disable-previous-line no-empty-blocks
5264
}
@@ -223,6 +235,45 @@ contract Comments4 is
223235
// solhint-disable-previous-line no-empty-blocks
224236
}
225237
238+
contract Comments4a
239+
is
240+
Interface1,
241+
Interface2,
242+
Interface3,
243+
Interface4,
244+
Interface5,
245+
Interface6 /*why we used Interface6*/ /*where should this go?*/
246+
layout at 123 /*why we used this layout*/
247+
{
248+
// solhint-disable-previous-line no-empty-blocks
249+
}
250+
251+
contract Comments4b
252+
is
253+
Interface1,
254+
Interface2,
255+
Interface3,
256+
Interface4,
257+
Interface5,
258+
Interface6 /*why we used Interface6*/ /*where should this go?*/
259+
layout at 123 + 456 /*why we used this layout*/
260+
{
261+
// solhint-disable-previous-line no-empty-blocks
262+
}
263+
264+
contract Comments4c
265+
is
266+
Interface1,
267+
Interface2,
268+
Interface3,
269+
Interface4,
270+
Interface5,
271+
Interface6 /*why we used Interface6*/ /*where should this go?*/
272+
layout at f(123 + 456) /*why we used this layout*/
273+
{
274+
// solhint-disable-previous-line no-empty-blocks
275+
}
276+
226277
/*nice name*/ contract Comments5 {
227278
// solhint-disable-previous-line no-empty-blocks
228279
}

0 commit comments

Comments
 (0)