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
// 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)

View File

@ -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 {

View File

@ -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 {

View File

@ -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")

6
yq.go
View File

@ -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 {