Skip to content

Commit 404b8e3

Browse files
committed
comments for storage layout
1 parent 07d8f87 commit 404b8e3

3 files changed

Lines changed: 76 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ contract Comments4 is Interface1, Interface2, Interface3, Interface4, Interface5
3838
// solhint-disable-previous-line no-empty-blocks
3939
}
4040

41+
42+
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*/ {
43+
// solhint-disable-previous-line no-empty-blocks
44+
}
45+
46+
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*/ {
47+
// solhint-disable-previous-line no-empty-blocks
48+
}
49+
50+
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*/ {
51+
// solhint-disable-previous-line no-empty-blocks
52+
}
53+
4154
contract Comments5 /*nice name*/ {
4255
// solhint-disable-previous-line no-empty-blocks
4356
}

tests/format/Comments/__snapshots__/jsfmt.spec.js.snap

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

0 commit comments

Comments
 (0)