Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 66 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,27 @@
"@babel/code-frame": "^7.26.2",
"c8": "^10.1.3",
"cross-env": "^7.0.3",
"eslint": "^8.47.0",
"eslint": "^8.57.1",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^10.0.1",
"eslint-config-prettier": "^10.1.2",
"eslint-plugin-import": "^2.31.0",
"esm-utils": "^4.3.0",
"esmock": "^2.6.9",
"esmock": "^2.7.0",
"jest": "^29.7.0",
"jest-light-runner": "^0.7.0",
"jest-snapshot-serializer-ansi": "^2.1.0",
"jest-light-runner": "^0.7.8",
"jest-snapshot-serializer-ansi": "^2.2.1",
"jest-snapshot-serializer-raw": "^2.0.0",
"jest-watch-typeahead": "^2.2.2",
"lines-and-columns": "^2.0.4",
"prettier": "^3.3.3",
"prettier": "^3.5.3",
"proxyquire": "^2.1.3",
"solc": "^0.8.28",
"webpack": "^5.97.1",
"solc": "^0.8.29",
"webpack": "^5.99.6",
"webpack-cli": "^6.0.1"
},
"dependencies": {
"@solidity-parser/parser": "^0.19.0",
"semver": "^7.6.3"
"@solidity-parser/parser": "^0.20.1",
"semver": "^7.7.1"
},
"peerDependencies": {
"prettier": ">=2.3.0"
Expand Down
13 changes: 11 additions & 2 deletions src/comments/handlers/handleContractDefinitionComments.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ function handleContractDefinitionComments({
);

// The comment is behind the start of the Block `{}` or behind a base contract
if (followingNode?.type === 'InheritanceSpecifier' || nextCharacter === '{') {
if (
(followingNode &&
(followingNode.type === 'InheritanceSpecifier' ||
followingNode === enclosingNode.storageLayout)) ||
nextCharacter === '{'
) {
// In this scenario the comment belongs to a base contract.
// contract A is B, /* comment for B */ C /* comment for C */ {}
if (precedingNode?.type === 'InheritanceSpecifier') {
if (
precedingNode &&
(precedingNode.type === 'InheritanceSpecifier' ||
precedingNode === enclosingNode.storageLayout)
) {
addTrailingComment(precedingNode, comment);
return true;
}
Expand Down
42 changes: 31 additions & 11 deletions src/nodes/ContractDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,37 @@ import {
printSeparatedList
} from '../common/printer-helpers.js';

const { group, line, hardline } = doc.builders;
const { group, hardline, ifBreak, line, softline } = doc.builders;

const inheritance = (node, path, print) =>
node.baseContracts.length > 0
? [
' is',
printSeparatedList(path.map(print, 'baseContracts'), {
firstSeparator: line
})
]
: line;
const specifiers = (node, path, print) => {
const document = [];
if (node.baseContracts.length > 0) {
document.push([
'is',
printSeparatedList(path.map(print, 'baseContracts'), {
firstSeparator: line
})
]);
}
if (node.storageLayout) {
document.push([
'layout at',
printSeparatedItem(path.call(print, 'storageLayout'), {
firstSeparator: line
})
]);
}
if (document.length === 0) return line;
if (document.length === 1) return [' ', document];
const groupId = Symbol('ContractSpecifiers.inheritance');
return printSeparatedList(
[group(document[0], { id: groupId }), document[1]],
{
firstSeparator: line,
separator: ifBreak('', softline, { groupId })
}
);
};

const body = (node, path, options, print) => {
const comments = printComments(node, path, options);
Expand All @@ -34,7 +54,7 @@ export const ContractDefinition = {
node.kind === 'abstract' ? 'abstract contract' : node.kind,
' ',
node.name,
inheritance(node, path, print),
specifiers(node, path, print),
'{'
]),
body(node, path, options, print),
Expand Down
12 changes: 12 additions & 0 deletions tests/format/Comments/Comments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ contract Comments4 is Interface1, Interface2, Interface3, Interface4, Interface5
// solhint-disable-previous-line no-empty-blocks
}

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*/ {
// solhint-disable-previous-line no-empty-blocks
}

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*/ {
// solhint-disable-previous-line no-empty-blocks
}

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*/ {
// solhint-disable-previous-line no-empty-blocks
}

contract Comments5 /*nice name*/ {
// solhint-disable-previous-line no-empty-blocks
}
Expand Down
Loading