diff --git a/pkg/yqlib/data_navigator.go b/pkg/yqlib/data_navigator.go index cfbfece..440331c 100644 --- a/pkg/yqlib/data_navigator.go +++ b/pkg/yqlib/data_navigator.go @@ -40,7 +40,7 @@ func (n *navigator) doTraverse(value *yaml.Node, head string, tail []string, pat // ignore errors here, we are deep splatting so we may accidently give a string key // to an array sequence if len(tail) > 0 { - n.recurse(value, tail[0], tail[1:], pathStack) + _ = n.recurse(value, tail[0], tail[1:], pathStack) } return errorDeepSplatting } @@ -78,7 +78,7 @@ func (n *navigator) recurse(value *yaml.Node, head string, tail []string, pathSt case yaml.AliasNode: log.Debug("its an alias!") DebugNode(value.Alias) - if n.navigationStrategy.FollowAlias(NewNodeContext(value, head, tail, pathStack)) == true { + if n.navigationStrategy.FollowAlias(NewNodeContext(value, head, tail, pathStack)) { log.Debug("following the alias") return n.recurse(value.Alias, head, tail, pathStack) } @@ -98,7 +98,7 @@ func (n *navigator) recurseMap(value *yaml.Node, head string, tail []string, pat n.navigationStrategy.DebugVisitedNodes() log.Debug("should I traverse? %v, %v", head, pathStackToString(newPathStack)) DebugNode(value) - if n.navigationStrategy.ShouldTraverse(NewNodeContext(contents[indexInMap+1], head, tail, newPathStack), contents[indexInMap].Value) == true { + if n.navigationStrategy.ShouldTraverse(NewNodeContext(contents[indexInMap+1], head, tail, newPathStack), contents[indexInMap].Value) { log.Debug("recurseMap: Going to traverse") traversedEntry = true // contents[indexInMap+1] = n.getOrReplace(contents[indexInMap+1], guessKind(head, tail, contents[indexInMap+1].Kind)) @@ -116,7 +116,7 @@ func (n *navigator) recurseMap(value *yaml.Node, head string, tail []string, pat return errorVisiting } - if traversedEntry == true || head == "*" || head == "**" || n.navigationStrategy.AutoCreateMap(NewNodeContext(value, head, tail, pathStack)) == false { + if traversedEntry || head == "*" || head == "**" || !n.navigationStrategy.AutoCreateMap(NewNodeContext(value, head, tail, pathStack)) { return nil } @@ -156,7 +156,7 @@ func (n *navigator) visitMatchingEntries(node *yaml.Node, head string, tail []st // if we don't find a match directly on this node first. errorVisitedDirectEntries := n.visitDirectMatchingEntries(node, head, tail, pathStack, visit) - if errorVisitedDirectEntries != nil || n.navigationStrategy.FollowAlias(NewNodeContext(node, head, tail, pathStack)) == false { + if errorVisitedDirectEntries != nil || !n.navigationStrategy.FollowAlias(NewNodeContext(node, head, tail, pathStack)) { return errorVisitedDirectEntries } return n.visitAliases(contents, head, tail, pathStack, visit) diff --git a/pkg/yqlib/delete_navigation_strategy.go b/pkg/yqlib/delete_navigation_strategy.go index b4f95c3..fc83c9e 100644 --- a/pkg/yqlib/delete_navigation_strategy.go +++ b/pkg/yqlib/delete_navigation_strategy.go @@ -38,7 +38,7 @@ func deleteFromMap(pathParser PathParser, contents []*yaml.Node, pathStack []int for index := 0; index < len(contents); index = index + 2 { keyNode := contents[index] valueNode := contents[index+1] - if pathParser.MatchesNextPathElement(NewNodeContext(keyNode, pathElementToDelete, []string{}, pathStack), keyNode.Value) == false { + if !pathParser.MatchesNextPathElement(NewNodeContext(keyNode, pathElementToDelete, []string{}, pathStack), keyNode.Value) { log.Debug("adding node %v", keyNode.Value) newContents = append(newContents, keyNode, valueNode) } else { diff --git a/pkg/yqlib/lib.go b/pkg/yqlib/lib.go index 8429a12..e455d7f 100644 --- a/pkg/yqlib/lib.go +++ b/pkg/yqlib/lib.go @@ -25,7 +25,10 @@ func DebugNode(value *yaml.Node) { } else if log.IsEnabledFor(logging.DEBUG) { buf := new(bytes.Buffer) encoder := yaml.NewEncoder(buf) - encoder.Encode(value) + errorEncoding := encoder.Encode(value) + if errorEncoding != nil { + log.Error("Error debugging node, %v", errorEncoding.Error()) + } encoder.Close() log.Debug("Tag: %v", value.Tag) log.Debug("%v", buf.String()) @@ -94,8 +97,7 @@ type YqLib interface { } type lib struct { - navigator DataNavigator - parser PathParser + parser PathParser } func NewYqLib() YqLib { diff --git a/pkg/yqlib/update_navigation_strategy.go b/pkg/yqlib/update_navigation_strategy.go index 8eea906..e6be8b7 100644 --- a/pkg/yqlib/update_navigation_strategy.go +++ b/pkg/yqlib/update_navigation_strategy.go @@ -12,7 +12,7 @@ func UpdateNavigationStrategy(updateCommand UpdateCommand, autoCreate bool) Navi visit: func(nodeContext NodeContext) error { node := nodeContext.Node changesToApply := updateCommand.Value - if updateCommand.Overwrite == true || node.Value == "" { + if updateCommand.Overwrite || node.Value == "" { log.Debug("going to update") DebugNode(node) log.Debug("with") diff --git a/yq.go b/yq.go index 021784c..c36ba59 100644 --- a/yq.go +++ b/yq.go @@ -434,7 +434,7 @@ func mergeProperties(cmd *cobra.Command, args []string) error { for _, fileToMerge := range filesToMerge { matchingNodes, errorProcessingFile := readYamlFile(fileToMerge, "**", false, 0) - if errorProcessingFile != nil && (allowEmptyFlag == false || !strings.HasPrefix(errorProcessingFile.Error(), "Could not process document index")) { + if errorProcessingFile != nil && (!allowEmptyFlag || !strings.HasPrefix(errorProcessingFile.Error(), "Could not process document index")) { return errorProcessingFile } for _, matchingNode := range matchingNodes { @@ -464,9 +464,9 @@ func newProperty(cmd *cobra.Command, args []string) error { var encoder = yaml.NewEncoder(cmd.OutOrStdout()) encoder.SetIndent(2) - encoder.Encode(&newNode) + errorEncoding := encoder.Encode(&newNode) encoder.Close() - return nil + return errorEncoding } func prefixProperty(cmd *cobra.Command, args []string) error {