Skip to content

Commit

Permalink
Linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ackleymi committed May 16, 2024
1 parent 6889cf1 commit 3517c8b
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 125 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ linters-install:
lint: linters-install
golangci-lint run

# An easy way to run the linter without going through the install process -
# docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.57.2 golangci-lint run -v
# See https://golangci-lint.run/welcome/install/ for more details.

# ---------------------------------------------------------------
# Targets related to running acceptance tests -

Expand Down
63 changes: 31 additions & 32 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ type Header struct{ FieldMap }

// msgparser contains message parsing vars needed to parse a string into a message.
type msgParser struct {
msg *Message
msg *Message
transportDataDictionary *datadictionary.DataDictionary
appDataDictionary *datadictionary.DataDictionary
rawBytes []byte
fieldIndex int
parsedFieldBytes *TagValue
trailerBytes []byte
foundBody bool
foundTrailer bool
appDataDictionary *datadictionary.DataDictionary
rawBytes []byte
fieldIndex int
parsedFieldBytes *TagValue
trailerBytes []byte
foundBody bool
foundTrailer bool
}

// in the message header, the first 3 tags in the message header must be 8,9,35.
Expand Down Expand Up @@ -169,9 +169,9 @@ func ParseMessageWithDataDictionary(
) (err error) {
// Create msgparser before we go any further.
mp := &msgParser{
msg: msg,
msg: msg,
transportDataDictionary: transportDataDictionary,
appDataDictionary: appDataDictionary,
appDataDictionary: appDataDictionary,
}
mp.msg.rawMessage = rawMessage
mp.rawBytes = rawMessage.Bytes()
Expand Down Expand Up @@ -225,7 +225,6 @@ func doParsing(mp *msgParser) (err error) {
}
mp.msg.Header.add(mp.msg.fields[mp.fieldIndex : mp.fieldIndex+1])


// Start parsing.
mp.fieldIndex++
xmlDataLen := 0
Expand Down Expand Up @@ -308,7 +307,7 @@ func parseGroup(mp *msgParser, tags []Tag) {
mp.foundBody = true
dm := mp.msg.fields[mp.fieldIndex : mp.fieldIndex+1]
fields := getGroupFields(mp.msg, tags, mp.appDataDictionary)

for {
mp.fieldIndex++
mp.parsedFieldBytes = &mp.msg.fields[mp.fieldIndex]
Expand All @@ -327,7 +326,7 @@ func parseGroup(mp *msgParser, tags []Tag) {
// Add the field member to the group.
dm = append(dm, *mp.parsedFieldBytes)
} else if isHeaderField(mp.parsedFieldBytes.tag, mp.transportDataDictionary) {
// Found a header tag for some reason..
// Found a header tag for some reason..
mp.msg.Body.add(dm)
mp.msg.Header.add(mp.msg.fields[mp.fieldIndex : mp.fieldIndex+1])
break
Expand All @@ -348,23 +347,23 @@ func parseGroup(mp *msgParser, tags []Tag) {
dm = mp.msg.fields[mp.fieldIndex : mp.fieldIndex+1]
fields = getGroupFields(mp.msg, searchTags, mp.appDataDictionary)
continue
} else {
if len(tags) > 1 {
searchTags = tags[:len(tags)-1]
}
// Did this tag occur after a nested group and belongs to the parent group.
if isNumInGroupField(mp.msg, searchTags, mp.appDataDictionary) {
// Add the field member to the group.
dm = append(dm, *mp.parsedFieldBytes)
// Continue parsing the parent group.
fields = getGroupFields(mp.msg, searchTags, mp.appDataDictionary)
continue
}
// Add the repeating group.
mp.msg.Body.add(dm)
// Add the next body field.
mp.msg.Body.add(mp.msg.fields[mp.fieldIndex : mp.fieldIndex+1])
}
if len(tags) > 1 {
searchTags = tags[:len(tags)-1]
}
// Did this tag occur after a nested group and belongs to the parent group.
if isNumInGroupField(mp.msg, searchTags, mp.appDataDictionary) {
// Add the field member to the group.
dm = append(dm, *mp.parsedFieldBytes)
// Continue parsing the parent group.
fields = getGroupFields(mp.msg, searchTags, mp.appDataDictionary)
continue
}
// Add the repeating group.
mp.msg.Body.add(dm)
// Add the next body field.
mp.msg.Body.add(mp.msg.fields[mp.fieldIndex : mp.fieldIndex+1])

break
}
}
Expand All @@ -384,7 +383,7 @@ func isNumInGroupField(msg *Message, tags []Tag, appDataDictionary *datadictiona
for idx, tag := range tags {
fd, ok := fields[int(tag)]
if ok {
if idx == len(tags) - 1 {
if idx == len(tags)-1 {
if len(fd.Fields) > 0 {
return true
}
Expand Down Expand Up @@ -417,7 +416,7 @@ func getGroupFields(msg *Message, tags []Tag, appDataDictionary *datadictionary.
for idx, tag := range tags {
fd, ok := fields[int(tag)]
if ok {
if idx == len(tags) - 1 {
if idx == len(tags)-1 {
if len(fd.Fields) > 0 {
return fd.Fields
}
Expand All @@ -438,7 +437,7 @@ func getGroupFields(msg *Message, tags []Tag, appDataDictionary *datadictionary.

// isGroupMember evaluates if this tag belongs to a repeating group.
func isGroupMember(tag Tag, fields []*datadictionary.FieldDef) bool {
for _, f := range fields{
for _, f := range fields {
if f.Tag() == int(tag) {
return true
}
Expand Down
Loading

0 comments on commit 3517c8b

Please sign in to comment.