From 20b51291202846d235c9979bdade24108c058d39 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 3 May 2025 16:34:21 +1000 Subject: [PATCH] Updating golanglint --- .golangci.bck.yml | 38 ++++++++++++++++++ .golangci.yml | 60 ++++++++++++++++++----------- acceptance_tests/load-file.sh | 4 +- cmd/version.go | 2 +- pkg/yqlib/candidate_node.go | 5 ++- pkg/yqlib/data_tree_navigator.go | 2 +- pkg/yqlib/decoder_toml.go | 7 ++-- pkg/yqlib/decoder_xml.go | 7 ++-- pkg/yqlib/encoder_lua.go | 8 +++- pkg/yqlib/encoder_properties.go | 2 +- pkg/yqlib/encoder_shellvariables.go | 2 +- pkg/yqlib/expression_parser.go | 5 ++- pkg/yqlib/expression_postfix.go | 9 +++-- pkg/yqlib/lexer.go | 17 ++++---- pkg/yqlib/operator_delete.go | 7 ++-- pkg/yqlib/operator_keys.go | 9 +++-- pkg/yqlib/operator_load.go | 4 +- pkg/yqlib/operator_multiply.go | 4 +- pkg/yqlib/operator_multiply_test.go | 4 +- pkg/yqlib/operator_omit.go | 7 ++-- pkg/yqlib/operator_path.go | 7 ++-- pkg/yqlib/operator_pick.go | 7 ++-- pkg/yqlib/operator_sort.go | 5 ++- pkg/yqlib/operator_strings.go | 2 +- pkg/yqlib/operator_style.go | 2 +- pkg/yqlib/operator_traverse_path.go | 7 ++-- pkg/yqlib/printer.go | 2 +- pkg/yqlib/properties_test.go | 5 ++- scripts/devtools.sh | 2 +- 29 files changed, 156 insertions(+), 86 deletions(-) create mode 100644 .golangci.bck.yml diff --git a/.golangci.bck.yml b/.golangci.bck.yml new file mode 100644 index 00000000..c108f703 --- /dev/null +++ b/.golangci.bck.yml @@ -0,0 +1,38 @@ +run: + timeout: 5m +linters: + enable: + - asciicheck + - depguard + - errorlint + - gci + - gochecknoinits + - gofmt + - goimports + - gosec + - gosimple + - staticcheck + - unused + - misspell + - nakedret + - nolintlint + - predeclared + - revive + - unconvert + - unparam +linters-settings: + depguard: + rules: + prevent_unmaintained_packages: + list-mode: lax + files: + - $all + - "!$test" + deny: + - pkg: io/ioutil + desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil" +issues: + exclude-rules: + - linters: + - revive + text: "var-naming" diff --git a/.golangci.yml b/.golangci.yml index c108f703..2a303b8f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,18 +1,11 @@ -run: - timeout: 5m +version: "2" linters: enable: - asciicheck - depguard - errorlint - - gci - gochecknoinits - - gofmt - - goimports - gosec - - gosimple - - staticcheck - - unused - misspell - nakedret - nolintlint @@ -20,19 +13,40 @@ linters: - revive - unconvert - unparam -linters-settings: - depguard: + settings: + depguard: + rules: + prevent_unmaintained_packages: + list-mode: lax + files: + - $all + - '!$test' + deny: + - pkg: io/ioutil + desc: 'replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil' + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling rules: - prevent_unmaintained_packages: - list-mode: lax - files: - - $all - - "!$test" - deny: - - pkg: io/ioutil - desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil" -issues: - exclude-rules: - - linters: - - revive - text: "var-naming" + - linters: + - revive + text: var-naming + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gci + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/acceptance_tests/load-file.sh b/acceptance_tests/load-file.sh index 4a64295c..b76d0e1e 100755 --- a/acceptance_tests/load-file.sh +++ b/acceptance_tests/load-file.sh @@ -3,7 +3,7 @@ testLoadFileNotExist() { result=$(./yq e -n 'load("cat.yml")' 2>&1) assertEquals 1 $? - assertEquals "Error: Failed to load cat.yml: open cat.yml: no such file or directory" "$result" + assertEquals "Error: failed to load cat.yml: open cat.yml: no such file or directory" "$result" } testLoadFileExpNotExist() { @@ -15,7 +15,7 @@ testLoadFileExpNotExist() { testStrLoadFileNotExist() { result=$(./yq e -n 'strload("cat.yml")' 2>&1) assertEquals 1 $? - assertEquals "Error: Failed to load cat.yml: open cat.yml: no such file or directory" "$result" + assertEquals "Error: failed to load cat.yml: open cat.yml: no such file or directory" "$result" } testStrLoadFileExpNotExist() { diff --git a/cmd/version.go b/cmd/version.go index 81e43be6..67eb1aa8 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -45,5 +45,5 @@ func getHumanVersion() string { } // Strip off any single quotes added by the git information. - return strings.Replace(version, "'", "", -1) + return strings.ReplaceAll(version, "'", "") } diff --git a/pkg/yqlib/candidate_node.go b/pkg/yqlib/candidate_node.go index 093d291d..2f268f68 100644 --- a/pkg/yqlib/candidate_node.go +++ b/pkg/yqlib/candidate_node.go @@ -201,13 +201,14 @@ func (n *CandidateNode) SetParent(parent *CandidateNode) { type ValueVisitor func(*CandidateNode) error func (n *CandidateNode) VisitValues(visitor ValueVisitor) error { - if n.Kind == MappingNode { + switch n.Kind { + case MappingNode: for i := 1; i < len(n.Content); i = i + 2 { if err := visitor(n.Content[i]); err != nil { return err } } - } else if n.Kind == SequenceNode { + case SequenceNode: for i := 0; i < len(n.Content); i = i + 1 { if err := visitor(n.Content[i]); err != nil { return err diff --git a/pkg/yqlib/data_tree_navigator.go b/pkg/yqlib/data_tree_navigator.go index 99bece43..7e0c7c72 100644 --- a/pkg/yqlib/data_tree_navigator.go +++ b/pkg/yqlib/data_tree_navigator.go @@ -64,6 +64,6 @@ func (d *dataTreeNavigator) GetMatchingNodes(context Context, expressionNode *Ex if handler != nil { return handler(d, context, expressionNode) } - return Context{}, fmt.Errorf("Unknown operator %v", expressionNode.Operation.OperationType) + return Context{}, fmt.Errorf("unknown operator %v", expressionNode.Operation.OperationType) } diff --git a/pkg/yqlib/decoder_toml.go b/pkg/yqlib/decoder_toml.go index ca193cf1..d67047b8 100644 --- a/pkg/yqlib/decoder_toml.go +++ b/pkg/yqlib/decoder_toml.go @@ -249,11 +249,12 @@ func (dec *tomlDecoder) processTopLevelNode(currentNode *toml.Node) (bool, error var runAgainstCurrentExp bool var err error log.Debug("processTopLevelNode: Going to process %v state is current %v", currentNode.Kind, NodeToString(dec.rootMap)) - if currentNode.Kind == toml.Table { + switch currentNode.Kind { + case toml.Table: runAgainstCurrentExp, err = dec.processTable(currentNode) - } else if currentNode.Kind == toml.ArrayTable { + case toml.ArrayTable: runAgainstCurrentExp, err = dec.processArrayTable(currentNode) - } else { + default: runAgainstCurrentExp, err = dec.decodeKeyValuesIntoMap(dec.rootMap, currentNode) } diff --git a/pkg/yqlib/decoder_xml.go b/pkg/yqlib/decoder_xml.go index 99626bd3..6759c9cd 100644 --- a/pkg/yqlib/decoder_xml.go +++ b/pkg/yqlib/decoder_xml.go @@ -315,13 +315,14 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error { case xml.Comment: commentStr := string(xml.CharData(se)) - if elem.state == "started" { + switch elem.state { + case "started": applyFootComment(elem, commentStr) - } else if elem.state == "chardata" { + case "chardata": log.Debug("got a line comment for (%v) %v: [%v]", elem.state, elem.label, commentStr) elem.n.LineComment = joinComments([]string{elem.n.LineComment, commentStr}, " ") - } else { + default: log.Debug("got a head comment for (%v) %v: [%v]", elem.state, elem.label, commentStr) elem.n.HeadComment = joinComments([]string{elem.n.HeadComment, commentStr}, " ") } diff --git a/pkg/yqlib/encoder_lua.go b/pkg/yqlib/encoder_lua.go index 6fa85a57..4e3ce89b 100644 --- a/pkg/yqlib/encoder_lua.go +++ b/pkg/yqlib/encoder_lua.go @@ -167,10 +167,14 @@ func needsQuoting(s string) bool { // [%a_][%w_]* for i, c := range s { if i == 0 { + // keeping for legacy reasons, upgraded linter + //nolint:staticcheck if !((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') { return true } } else { + // keeping for legacy reasons, upgraded linter + //nolint:staticcheck if !((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_') { return true } @@ -299,10 +303,10 @@ func (le *luaEncoder) encodeAny(writer io.Writer, node *CandidateNode) error { return writeString(writer, node.Value) } default: - return fmt.Errorf("Lua encoder NYI -- %s", node.Tag) + return fmt.Errorf("lua encoder NYI -- %s", node.Tag) } default: - return fmt.Errorf("Lua encoder NYI -- %s", node.Tag) + return fmt.Errorf("lua encoder NYI -- %s", node.Tag) } } diff --git a/pkg/yqlib/encoder_properties.go b/pkg/yqlib/encoder_properties.go index 460a4496..21dedf36 100644 --- a/pkg/yqlib/encoder_properties.go +++ b/pkg/yqlib/encoder_properties.go @@ -107,7 +107,7 @@ func (pe *propertiesEncoder) doEncode(p *properties.Properties, node *CandidateN case AliasNode: return pe.doEncode(p, node.Alias, path, nil) default: - return fmt.Errorf("Unsupported node %v", node.Tag) + return fmt.Errorf("unsupported node %v", node.Tag) } } diff --git a/pkg/yqlib/encoder_shellvariables.go b/pkg/yqlib/encoder_shellvariables.go index d725dae3..9b97c92a 100644 --- a/pkg/yqlib/encoder_shellvariables.go +++ b/pkg/yqlib/encoder_shellvariables.go @@ -75,7 +75,7 @@ func (pe *shellVariablesEncoder) doEncode(w *io.Writer, node *CandidateNode, pat case AliasNode: return pe.doEncode(w, node.Alias, path) default: - return fmt.Errorf("Unsupported node %v", node.Tag) + return fmt.Errorf("unsupported node %v", node.Tag) } } diff --git a/pkg/yqlib/expression_parser.go b/pkg/yqlib/expression_parser.go index 47226290..622fb416 100644 --- a/pkg/yqlib/expression_parser.go +++ b/pkg/yqlib/expression_parser.go @@ -50,14 +50,15 @@ func (p *expressionParserImpl) createExpressionTree(postFixPath []*Operation) (* log.Debugf("pathTree %v ", Operation.toString()) if Operation.OperationType.NumArgs > 0 { numArgs := Operation.OperationType.NumArgs - if numArgs == 1 { + switch numArgs { + case 1: if len(stack) < 1 { return nil, fmt.Errorf("'%v' expects 1 arg but received none", strings.TrimSpace(Operation.StringValue)) } remaining, rhs := stack[:len(stack)-1], stack[len(stack)-1] newNode.RHS = rhs stack = remaining - } else if numArgs == 2 { + case 2: if len(stack) < 2 { return nil, fmt.Errorf("'%v' expects 2 args but there is %v", strings.TrimSpace(Operation.StringValue), len(stack)) } diff --git a/pkg/yqlib/expression_postfix.go b/pkg/yqlib/expression_postfix.go index fa7afa33..6972999b 100644 --- a/pkg/yqlib/expression_postfix.go +++ b/pkg/yqlib/expression_postfix.go @@ -26,11 +26,12 @@ func popOpToResult(opStack []*token, result []*Operation) ([]*token, []*Operatio } func validateNoOpenTokens(token *token) error { - if token.TokenType == openCollect { + switch token.TokenType { + case openCollect: return fmt.Errorf(("bad expression, could not find matching `]`")) - } else if token.TokenType == openCollectObject { + case openCollectObject: return fmt.Errorf(("bad expression, could not find matching `}`")) - } else if token.TokenType == openBracket { + case openBracket: return fmt.Errorf(("bad expression, could not find matching `)`")) } return nil @@ -64,7 +65,7 @@ func (p *expressionPostFixerImpl) ConvertToPostfix(infixTokens []*token) ([]*Ope opStack, result = popOpToResult(opStack, result) } if len(opStack) == 0 { - return nil, errors.New("Bad path expression, got close collect brackets without matching opening bracket") + return nil, errors.New("bad path expression, got close collect brackets without matching opening bracket") } // now we should have [ as the last element on the opStack, get rid of it opStack = opStack[0 : len(opStack)-1] diff --git a/pkg/yqlib/lexer.go b/pkg/yqlib/lexer.go index cc6841b3..8e04761d 100644 --- a/pkg/yqlib/lexer.go +++ b/pkg/yqlib/lexer.go @@ -31,24 +31,25 @@ type token struct { } func (t *token) toString(detail bool) string { - if t.TokenType == operationToken { + switch t.TokenType { + case operationToken: if detail { return fmt.Sprintf("%v (%v)", t.Operation.toString(), t.Operation.OperationType.Precedence) } return t.Operation.toString() - } else if t.TokenType == openBracket { + case openBracket: return "(" - } else if t.TokenType == closeBracket { + case closeBracket: return ")" - } else if t.TokenType == openCollect { + case openCollect: return "[" - } else if t.TokenType == closeCollect { + case closeCollect: return "]" - } else if t.TokenType == openCollectObject { + case openCollectObject: return "{" - } else if t.TokenType == closeCollectObject { + case closeCollectObject: return "}" - } else if t.TokenType == traverseArrayCollect { + case traverseArrayCollect: return ".[" } diff --git a/pkg/yqlib/operator_delete.go b/pkg/yqlib/operator_delete.go index 653a40cd..16ee77d5 100644 --- a/pkg/yqlib/operator_delete.go +++ b/pkg/yqlib/operator_delete.go @@ -26,11 +26,12 @@ func deleteChildOperator(d *dataTreeNavigator, context Context, expressionNode * candidatePath := candidate.GetPath() childPath := candidatePath[len(candidatePath)-1] - if parentNode.Kind == MappingNode { + switch parentNode.Kind { + case MappingNode: deleteFromMap(candidate.Parent, childPath) - } else if parentNode.Kind == SequenceNode { + case SequenceNode: deleteFromArray(candidate.Parent, childPath) - } else { + default: return Context{}, fmt.Errorf("cannot delete nodes from parent of tag %v", parentNode.Tag) } } diff --git a/pkg/yqlib/operator_keys.go b/pkg/yqlib/operator_keys.go index 1e58ed1c..e95afacf 100644 --- a/pkg/yqlib/operator_keys.go +++ b/pkg/yqlib/operator_keys.go @@ -45,12 +45,13 @@ func keysOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Con candidate := el.Value.(*CandidateNode) var targetNode *CandidateNode - if candidate.Kind == MappingNode { + switch candidate.Kind { + case MappingNode: targetNode = getMapKeys(candidate) - } else if candidate.Kind == SequenceNode { + case SequenceNode: targetNode = getIndices(candidate) - } else { - return Context{}, fmt.Errorf("Cannot get keys of %v, keys only works for maps and arrays", candidate.Tag) + default: + return Context{}, fmt.Errorf("cannot get keys of %v, keys only works for maps and arrays", candidate.Tag) } results.PushBack(targetNode) diff --git a/pkg/yqlib/operator_load.go b/pkg/yqlib/operator_load.go index f30ee352..970b9e5b 100644 --- a/pkg/yqlib/operator_load.go +++ b/pkg/yqlib/operator_load.go @@ -82,7 +82,7 @@ func loadStringOperator(d *dataTreeNavigator, context Context, expressionNode *E contentsCandidate, err := loadString(filename) if err != nil { - return Context{}, fmt.Errorf("Failed to load %v: %w", filename, err) + return Context{}, fmt.Errorf("failed to load %v: %w", filename, err) } results.PushBack(contentsCandidate) @@ -118,7 +118,7 @@ func loadOperator(d *dataTreeNavigator, context Context, expressionNode *Express contentsCandidate, err := loadWithDecoder(filename, loadPrefs.decoder) if err != nil { - return Context{}, fmt.Errorf("Failed to load %v: %w", filename, err) + return Context{}, fmt.Errorf("failed to load %v: %w", filename, err) } results.PushBack(contentsCandidate) diff --git a/pkg/yqlib/operator_multiply.go b/pkg/yqlib/operator_multiply.go index bf2387a0..73e9a6c9 100644 --- a/pkg/yqlib/operator_multiply.go +++ b/pkg/yqlib/operator_multiply.go @@ -154,9 +154,9 @@ func repeatString(lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error if err != nil { return nil, err } else if count < 0 { - return nil, fmt.Errorf("Cannot repeat string by a negative number (%v)", count) + return nil, fmt.Errorf("cannot repeat string by a negative number (%v)", count) } else if count > 10000000 { - return nil, fmt.Errorf("Cannot repeat string by more than 100 million (%v)", count) + return nil, fmt.Errorf("cannot repeat string by more than 100 million (%v)", count) } target.Value = strings.Repeat(stringNode.Value, count) diff --git a/pkg/yqlib/operator_multiply_test.go b/pkg/yqlib/operator_multiply_test.go index e2c7063e..49a3b6eb 100644 --- a/pkg/yqlib/operator_multiply_test.go +++ b/pkg/yqlib/operator_multiply_test.go @@ -206,7 +206,7 @@ var multiplyOperatorScenarios = []expressionScenario{ skipDoc: true, document: `n: -4`, expression: `"banana" * .n`, - expectedError: "Cannot repeat string by a negative number (-4)", + expectedError: "cannot repeat string by a negative number (-4)", }, { description: "Multiply string X by more than 100 million", @@ -214,7 +214,7 @@ var multiplyOperatorScenarios = []expressionScenario{ skipDoc: true, document: `n: 100000001`, expression: `"banana" * .n`, - expectedError: "Cannot repeat string by more than 100 million (100000001)", + expectedError: "cannot repeat string by more than 100 million (100000001)", }, { description: "Multiply int node X string", diff --git a/pkg/yqlib/operator_omit.go b/pkg/yqlib/operator_omit.go index 45ad7ce9..36549362 100644 --- a/pkg/yqlib/operator_omit.go +++ b/pkg/yqlib/operator_omit.go @@ -58,11 +58,12 @@ func omitOperator(d *dataTreeNavigator, context Context, expressionNode *Express var replacement *CandidateNode - if node.Kind == MappingNode { + switch node.Kind { + case MappingNode: replacement = omitMap(node, indicesToOmit) - } else if node.Kind == SequenceNode { + case SequenceNode: replacement = omitSequence(node, indicesToOmit) - } else { + default: log.Debugf("Omit from type %v (%v) is noop", node.Tag, node.GetNicePath()) return context, nil } diff --git a/pkg/yqlib/operator_path.go b/pkg/yqlib/operator_path.go index a3a687c3..3fb8f8da 100644 --- a/pkg/yqlib/operator_path.go +++ b/pkg/yqlib/operator_path.go @@ -22,15 +22,16 @@ func getPathArrayFromNode(funcName string, node *CandidateNode) ([]interface{}, path := make([]interface{}, len(node.Content)) for i, childNode := range node.Content { - if childNode.Tag == "!!str" { + switch childNode.Tag { + case "!!str": path[i] = childNode.Value - } else if childNode.Tag == "!!int" { + case "!!int": number, err := parseInt(childNode.Value) if err != nil { return nil, fmt.Errorf("%v: could not parse %v as an int: %w", funcName, childNode.Value, err) } path[i] = number - } else { + default: return nil, fmt.Errorf("%v: expected either a !!str or !!int in the path, found %v instead", funcName, childNode.Tag) } diff --git a/pkg/yqlib/operator_pick.go b/pkg/yqlib/operator_pick.go index 2e223ea0..04700435 100644 --- a/pkg/yqlib/operator_pick.go +++ b/pkg/yqlib/operator_pick.go @@ -64,15 +64,16 @@ func pickOperator(d *dataTreeNavigator, context Context, expressionNode *Express node := el.Value.(*CandidateNode) var replacement *CandidateNode - if node.Kind == MappingNode { + switch node.Kind { + case MappingNode: replacement = pickMap(node, indicesToPick) - } else if node.Kind == SequenceNode { + case SequenceNode: replacement, err = pickSequence(node, indicesToPick) if err != nil { return Context{}, err } - } else { + default: return Context{}, fmt.Errorf("cannot pick indices from type %v (%v)", node.Tag, node.GetNicePath()) } diff --git a/pkg/yqlib/operator_sort.go b/pkg/yqlib/operator_sort.go index c76b9846..43df7818 100644 --- a/pkg/yqlib/operator_sort.go +++ b/pkg/yqlib/operator_sort.go @@ -47,11 +47,12 @@ func sortByOperator(d *dataTreeNavigator, context Context, expressionNode *Expre sort.Stable(sortableArray) sortedList := candidate.CopyWithoutContent() - if candidate.Kind == MappingNode { + switch candidate.Kind { + case MappingNode: for _, sortedNode := range sortableArray { sortedList.AddKeyValueChild(sortedNode.Node.Key, sortedNode.Node) } - } else if candidate.Kind == SequenceNode { + case SequenceNode: for _, sortedNode := range sortableArray { sortedList.AddChild(sortedNode.Node) } diff --git a/pkg/yqlib/operator_strings.go b/pkg/yqlib/operator_strings.go index c9bb9e4a..090325cf 100644 --- a/pkg/yqlib/operator_strings.go +++ b/pkg/yqlib/operator_strings.go @@ -410,7 +410,7 @@ func extractMatchArguments(d *dataTreeNavigator, context Context, expressionNode return nil, matchPrefs, fmt.Errorf(`'i' is not a valid option for match. To ignore case, use an expression like match("(?i)cat")`) } if len(paramText) > 0 { - return nil, matchPrefs, fmt.Errorf(`Unrecognised match params '%v', please see docs at https://mikefarah.gitbook.io/yq/operators/string-operators`, paramText) + return nil, matchPrefs, fmt.Errorf(`unrecognised match params '%v', please see docs at https://mikefarah.gitbook.io/yq/operators/string-operators`, paramText) } } diff --git a/pkg/yqlib/operator_style.go b/pkg/yqlib/operator_style.go index 37aad865..a65d95bd 100644 --- a/pkg/yqlib/operator_style.go +++ b/pkg/yqlib/operator_style.go @@ -19,7 +19,7 @@ func parseStyle(customStyle string) (Style, error) { } else if customStyle == "flow" { return FlowStyle, nil } else if customStyle != "" { - return 0, fmt.Errorf("Unknown style %v", customStyle) + return 0, fmt.Errorf("unknown style %v", customStyle) } return 0, nil } diff --git a/pkg/yqlib/operator_traverse_path.go b/pkg/yqlib/operator_traverse_path.go index 4f46b983..903ae323 100644 --- a/pkg/yqlib/operator_traverse_path.go +++ b/pkg/yqlib/operator_traverse_path.go @@ -135,12 +135,13 @@ func traverseArrayIndices(context Context, matchingNode *CandidateNode, indicesT } } - if matchingNode.Kind == AliasNode { + switch matchingNode.Kind { + case AliasNode: matchingNode = matchingNode.Alias return traverseArrayIndices(context, matchingNode, indicesToTraverse, prefs) - } else if matchingNode.Kind == SequenceNode { + case SequenceNode: return traverseArrayWithIndices(matchingNode, indicesToTraverse, prefs) - } else if matchingNode.Kind == MappingNode { + case MappingNode: return traverseMapWithIndices(context, matchingNode, indicesToTraverse, prefs) } log.Debugf("OperatorArrayTraverse skipping %v as its a %v", matchingNode, matchingNode.Tag) diff --git a/pkg/yqlib/printer.go b/pkg/yqlib/printer.go index 61f653a8..5c11e39d 100644 --- a/pkg/yqlib/printer.go +++ b/pkg/yqlib/printer.go @@ -132,7 +132,7 @@ func (p *resultsPrinter) PrintResults(matchingNodes *list.List) error { tempBufferBytes := tempBuffer.Bytes() if bytes.IndexByte(tempBufferBytes, 0) != -1 { return fmt.Errorf( - "Can't serialize value because it contains NUL char and you are using NUL separated output", + "can't serialize value because it contains NUL char and you are using NUL separated output", ) } if _, err := writer.Write(tempBufferBytes); err != nil { diff --git a/pkg/yqlib/properties_test.go b/pkg/yqlib/properties_test.go index da445b33..4f2ba8e6 100644 --- a/pkg/yqlib/properties_test.go +++ b/pkg/yqlib/properties_test.go @@ -319,10 +319,11 @@ func documentUnwrappedEncodePropertyScenario(w *bufio.Writer, s formatScenario) prefs := NewDefaultPropertiesPreferences() useArrayBracketsFlag := "" useCustomSeparatorFlag := "" - if s.scenarioType == "encode-array-brackets" { + switch s.scenarioType { + case "encode-array-brackets": useArrayBracketsFlag = " --properties-array-brackets" prefs.UseArrayBrackets = true - } else if s.scenarioType == "encode-custom-separator" { + case "encode-custom-separator": prefs.KeyValueSeparator = " :@ " useCustomSeparatorFlag = ` --properties-separator=" :@ "` } diff --git a/scripts/devtools.sh b/scripts/devtools.sh index 2cf7ab64..e162a893 100755 --- a/scripts/devtools.sh +++ b/scripts/devtools.sh @@ -1,5 +1,5 @@ #!/bin/sh set -ex go mod download golang.org/x/tools@latest -curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.8 +curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.1.5 curl -sSfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s