diff options
| author | Jeff Carr <[email protected]> | 2025-04-04 08:07:06 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-04-04 08:07:06 -0500 |
| commit | 198b217cfaabdf90444068804ede821ab1311df5 (patch) | |
| tree | fec9f10bed1dee1e521bb688169bf314deb3954d /protoReformat.go | |
| parent | 167acab35422259f6c0bd80f92b5b425d6d7f583 (diff) | |
track empty message {}
Diffstat (limited to 'protoReformat.go')
| -rw-r--r-- | protoReformat.go | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/protoReformat.go b/protoReformat.go index 2e9b498..b773d14 100644 --- a/protoReformat.go +++ b/protoReformat.go @@ -109,6 +109,7 @@ func doParse(lines []string) *FormatMsg { if strings.HasPrefix(line, "oneof ") { if strings.Contains(line, "}") { newmsg := basemsg.newMessage(line, comments, FormatMsg_ONEOF) + newmsg.IsEmpty = true newmsg.Footer = "} // blah" comments = "" continue @@ -123,6 +124,7 @@ func doParse(lines []string) *FormatMsg { newmsg := basemsg.newMessage(line, comments, FormatMsg_ENUM) comments = "" if strings.Contains(line, "}") { + newmsg.IsEmpty = true newmsg.Footer = "} // blah" continue } @@ -135,6 +137,7 @@ func doParse(lines []string) *FormatMsg { newmsg := basemsg.newMessage(line, comments, FormatMsg_MESSAGE) comments = "" if strings.Contains(line, "}") { + newmsg.IsEmpty = true newmsg.Footer = "} // blah" continue } @@ -196,6 +199,7 @@ func (msg *FormatMsg) load() { if strings.HasPrefix(line, "oneof ") { newmsg := msg.newMessage(line, "", FormatMsg_ONEOF) if strings.Contains(line, "}") { + newmsg.IsEmpty = true return } newmsg.load() @@ -204,6 +208,7 @@ func (msg *FormatMsg) load() { if strings.HasPrefix(line, "enum ") { newmsg := msg.newMessage(line, "", FormatMsg_ENUM) if strings.Contains(line, "}") { + newmsg.IsEmpty = true return } newmsg.load() @@ -213,6 +218,7 @@ func (msg *FormatMsg) load() { // message inception. search for the architect. don't forget your totem newmsg := msg.newMessage(line, "", FormatMsg_MESSAGE) if strings.Contains(line, "}") { + newmsg.IsEmpty = true return } newmsg.load() @@ -328,7 +334,7 @@ func formatEnum(curmsg *FormatMsg) []string { // newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "enum footer")) newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "enum footer")) if curmsg.PadAfter { - newmsg = append(newmsg, curmsg.formatLineBase("", "PadAfter")) + newmsg = append(newmsg, curmsg.formatPadAfter()) } return newmsg @@ -348,7 +354,7 @@ func formatOneof(curmsg *FormatMsg) []string { // newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "oneof footer")) newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "oneof footer")) if curmsg.PadAfter { - newmsg = append(newmsg, curmsg.formatLineBase("", "PadAfter")) + newmsg = append(newmsg, curmsg.formatPadAfter()) } return newmsg @@ -422,6 +428,13 @@ func (msg *FormatMsg) formatFooter(line string, dbg string) string { return msg.formatLineBase(line, "footer") } +func (msg *FormatMsg) formatPadAfter() string { + if argv.Debug { + return msg.formatLineBase("", "pad after") + } + return "" +} + func (msg *FormatMsg) formatHeader(line string, dbg string) string { if line == "" { if msg.Depth != 0 { @@ -517,6 +530,11 @@ func trimLines(lines []string) []string { func formatMessage(curmsg *FormatMsg) []string { var newmsg []string + if curmsg.IsEmpty { + newmsg = append(newmsg, curmsg.formatLineBase("// isEmpty", "IsEmpty")) + return newmsg + } + // add the notes & comments before the header notes := trimLines(curmsg.Notes) if len(notes) == 0 { @@ -592,18 +610,9 @@ func formatMessage(curmsg *FormatMsg) []string { newmsg = append(newmsg, curmsg.formatFooter(curmsg.Footer, "footer")) if curmsg.PadAfter { - newmsg = append(newmsg, curmsg.formatLineBase("", "PadAfter")) + newmsg = append(newmsg, curmsg.formatPadAfter()) } - /* - if curmsg.Footer == "" { - newmsg = append(newmsg, "// footer was empty") - } else { - // newline := fmt.Sprintf("%s%s", curmsg.padding(1), curmsg.Footer) // +" //footer") - // newmsg = append(newmsg, newline) - newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "msg depth")) - } - */ return newmsg } |
