Fixed linting errors

This commit is contained in:
Mike Farah 2020-01-09 21:27:52 +11:00
parent 924eb6c462
commit 0621307391
5 changed files with 15 additions and 13 deletions

View File

@ -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 // ignore errors here, we are deep splatting so we may accidently give a string key
// to an array sequence // to an array sequence
if len(tail) > 0 { if len(tail) > 0 {
n.recurse(value, tail[0], tail[1:], pathStack) _ = n.recurse(value, tail[0], tail[1:], pathStack)
} }
return errorDeepSplatting return errorDeepSplatting
} }
@ -78,7 +78,7 @@ func (n *navigator) recurse(value *yaml.Node, head string, tail []string, pathSt
case yaml.AliasNode: case yaml.AliasNode:
log.Debug("its an alias!") log.Debug("its an alias!")
DebugNode(value.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") log.Debug("following the alias")
return n.recurse(value.Alias, head, tail, pathStack) 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() n.navigationStrategy.DebugVisitedNodes()
log.Debug("should I traverse? %v, %v", head, pathStackToString(newPathStack)) log.Debug("should I traverse? %v, %v", head, pathStackToString(newPathStack))
DebugNode(value) 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") log.Debug("recurseMap: Going to traverse")
traversedEntry = true traversedEntry = true
// contents[indexInMap+1] = n.getOrReplace(contents[indexInMap+1], guessKind(head, tail, contents[indexInMap+1].Kind)) // 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 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 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. // if we don't find a match directly on this node first.
errorVisitedDirectEntries := n.visitDirectMatchingEntries(node, head, tail, pathStack, visit) 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 errorVisitedDirectEntries
} }
return n.visitAliases(contents, head, tail, pathStack, visit) return n.visitAliases(contents, head, tail, pathStack, visit)

View File

@ -38,7 +38,7 @@ func deleteFromMap(pathParser PathParser, contents []*yaml.Node, pathStack []int
for index := 0; index < len(contents); index = index + 2 { for index := 0; index < len(contents); index = index + 2 {
keyNode := contents[index] keyNode := contents[index]
valueNode := contents[index+1] 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) log.Debug("adding node %v", keyNode.Value)
newContents = append(newContents, keyNode, valueNode) newContents = append(newContents, keyNode, valueNode)
} else { } else {

View File

@ -25,7 +25,10 @@ func DebugNode(value *yaml.Node) {
} else if log.IsEnabledFor(logging.DEBUG) { } else if log.IsEnabledFor(logging.DEBUG) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
encoder := yaml.NewEncoder(buf) encoder := yaml.NewEncoder(buf)
encoder.Encode(value) errorEncoding := encoder.Encode(value)
if errorEncoding != nil {
log.Error("Error debugging node, %v", errorEncoding.Error())
}
encoder.Close() encoder.Close()
log.Debug("Tag: %v", value.Tag) log.Debug("Tag: %v", value.Tag)
log.Debug("%v", buf.String()) log.Debug("%v", buf.String())
@ -94,8 +97,7 @@ type YqLib interface {
} }
type lib struct { type lib struct {
navigator DataNavigator parser PathParser
parser PathParser
} }
func NewYqLib() YqLib { func NewYqLib() YqLib {

View File

@ -12,7 +12,7 @@ func UpdateNavigationStrategy(updateCommand UpdateCommand, autoCreate bool) Navi
visit: func(nodeContext NodeContext) error { visit: func(nodeContext NodeContext) error {
node := nodeContext.Node node := nodeContext.Node
changesToApply := updateCommand.Value changesToApply := updateCommand.Value
if updateCommand.Overwrite == true || node.Value == "" { if updateCommand.Overwrite || node.Value == "" {
log.Debug("going to update") log.Debug("going to update")
DebugNode(node) DebugNode(node)
log.Debug("with") log.Debug("with")

6
yq.go
View File

@ -434,7 +434,7 @@ func mergeProperties(cmd *cobra.Command, args []string) error {
for _, fileToMerge := range filesToMerge { for _, fileToMerge := range filesToMerge {
matchingNodes, errorProcessingFile := readYamlFile(fileToMerge, "**", false, 0) 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 return errorProcessingFile
} }
for _, matchingNode := range matchingNodes { for _, matchingNode := range matchingNodes {
@ -464,9 +464,9 @@ func newProperty(cmd *cobra.Command, args []string) error {
var encoder = yaml.NewEncoder(cmd.OutOrStdout()) var encoder = yaml.NewEncoder(cmd.OutOrStdout())
encoder.SetIndent(2) encoder.SetIndent(2)
encoder.Encode(&newNode) errorEncoding := encoder.Encode(&newNode)
encoder.Close() encoder.Close()
return nil return errorEncoding
} }
func prefixProperty(cmd *cobra.Command, args []string) error { func prefixProperty(cmd *cobra.Command, args []string) error {