Skip to content

Commit

Permalink
Format empty structs correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Feb 1, 2023
1 parent a8cf709 commit bc1b8d7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/nodes/StructDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ const {
const { printSeparatedList } = require('../common/printer-helpers');

const StructDefinition = {
print: ({ node, path, print }) => [
'struct ',
node.name,
' {',
printSeparatedList(path.map(print, 'members'), {
firstSeparator: hardline,
separator: [';', hardline],
lastSeparator: [';', hardline]
}),
'}'
]
print: ({ node, path, print }) => {
const parts = ['struct ', node.name, ' {'];

if (node.members.length > 0) {
parts.push(
printSeparatedList(path.map(print, 'members'), {
firstSeparator: hardline,
separator: [';', hardline],
lastSeparator: [';', hardline]
})
);
}

parts.push('}');

return parts;
}
};

module.exports = StructDefinition;
1 change: 1 addition & 0 deletions tests/format/Issues/Issue799.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
struct EmptyStruct {}
14 changes: 14 additions & 0 deletions tests/format/Issues/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,17 @@ contract Issue564 {
================================================================================
`;

exports[`Issue799.sol format 1`] = `
====================================options=====================================
parsers: ["solidity-parse"]
printWidth: 80
| printWidth
=====================================input======================================
struct EmptyStruct {}
=====================================output=====================================
struct EmptyStruct {}
================================================================================
`;

0 comments on commit bc1b8d7

Please sign in to comment.