From 9d60c79609c33c7ab2feaaf0a3399367c216081d Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 11 Nov 2024 14:02:33 +0100 Subject: [PATCH 01/15] update golangci-lint to the last version --- scripts/devtools.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/devtools.sh b/scripts/devtools.sh index 49e7a43a..6fe80caf 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.55.2 +curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.0 wget -O- -nv https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s From 18972b290aa94426cc732d64be700e4d86a4c0e0 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 11 Nov 2024 14:02:55 +0100 Subject: [PATCH 02/15] replace deprecated megacheck with specific linters --- .golangci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 1476b6cc..c1c3894a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,7 +10,9 @@ linters: - gofmt - goimports - gosec - - megacheck + - gosimple + - staticcheck + - unused - misspell - nakedret - nolintlint From 072491c656ec6b04ace658030eb9f4e17f821fd7 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 11 Nov 2024 14:03:08 +0100 Subject: [PATCH 03/15] remove lint exception no longer required --- .golangci.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c1c3894a..c108f703 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -33,13 +33,6 @@ linters-settings: desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil" issues: exclude-rules: - - linters: - - gosec - text: "Implicit memory aliasing in for loop." - path: _test\.go - - linters: - - revive - text: "unexported-return" - linters: - revive text: "var-naming" From 7eef1a454e03084b0515a1a54cf85e6707974e4f Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 11 Nov 2024 14:03:52 +0100 Subject: [PATCH 04/15] exclude lint errors to keep cobra params unchanged --- cmd/evaluate_all_command.go | 2 +- cmd/evaluate_sequence_command.go | 2 +- cmd/root.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/evaluate_all_command.go b/cmd/evaluate_all_command.go index c273cd6c..25009a65 100644 --- a/cmd/evaluate_all_command.go +++ b/cmd/evaluate_all_command.go @@ -12,7 +12,7 @@ func createEvaluateAllCommand() *cobra.Command { Use: "eval-all [expression] [yaml_file1]...", Aliases: []string{"ea"}, Short: "Loads _all_ yaml documents of _all_ yaml files and runs expression once", - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { //nolint:revive if len(args) == 0 { return nil, cobra.ShellCompDirectiveNoFileComp } diff --git a/cmd/evaluate_sequence_command.go b/cmd/evaluate_sequence_command.go index e5641065..16d78e98 100644 --- a/cmd/evaluate_sequence_command.go +++ b/cmd/evaluate_sequence_command.go @@ -13,7 +13,7 @@ func createEvaluateSequenceCommand() *cobra.Command { Use: "eval [expression] [yaml_file1]...", Aliases: []string{"e"}, Short: "(default) Apply the expression to each document in each yaml file in sequence", - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { //nolint:revive if len(args) == 0 { return nil, cobra.ShellCompDirectiveNoFileComp } diff --git a/cmd/root.go b/cmd/root.go index f5d93606..40fb549c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -66,7 +66,7 @@ yq -P -oy sample.json return evaluateSequence(cmd, args) }, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { //nolint:revive cmd.SetOut(cmd.OutOrStdout()) level := logging.WARNING stringFormat := `[%{level}] %{color}%{time:15:04:05}%{color:reset} %{message}` From 3ce266bfa06d994d0a09e816473493c47cfbf813 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 11 Nov 2024 14:04:21 +0100 Subject: [PATCH 05/15] fix parameter order in error type comparison --- pkg/yqlib/decoder_toml.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/yqlib/decoder_toml.go b/pkg/yqlib/decoder_toml.go index d8a6264d..ca193cf1 100644 --- a/pkg/yqlib/decoder_toml.go +++ b/pkg/yqlib/decoder_toml.go @@ -286,7 +286,7 @@ func (dec *tomlDecoder) processTable(currentNode *toml.Node) (bool, error) { } runAgainstCurrentExp, err = dec.decodeKeyValuesIntoMap(tableNodeValue, tableValue) - if err != nil && !errors.Is(io.EOF, err) { + if err != nil && !errors.Is(err, io.EOF) { return false, err } } @@ -343,7 +343,7 @@ func (dec *tomlDecoder) processArrayTable(currentNode *toml.Node) (bool, error) tableValue := dec.parser.Expression() runAgainstCurrentExp, err := dec.decodeKeyValuesIntoMap(tableNodeValue, tableValue) log.Debugf("table node err: %w", err) - if err != nil && !errors.Is(io.EOF, err) { + if err != nil && !errors.Is(err, io.EOF) { return false, err } c := Context{} From f168172bf4e973e0bc55f16f314d338bbdfc94c7 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 11 Nov 2024 14:05:53 +0100 Subject: [PATCH 06/15] remove unused variable parameters from functions --- pkg/yqlib/lexer_participle.go | 4 ++-- pkg/yqlib/operator_assign.go | 2 +- pkg/yqlib/operator_compare.go | 2 +- pkg/yqlib/operator_create_map.go | 2 +- pkg/yqlib/operator_equals.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/yqlib/lexer_participle.go b/pkg/yqlib/lexer_participle.go index 9480952d..870b39cf 100644 --- a/pkg/yqlib/lexer_participle.go +++ b/pkg/yqlib/lexer_participle.go @@ -311,7 +311,7 @@ func opTokenWithPrefs(opType *operationType, assignOpType *operationType, prefer } func expressionOpToken(expression string) yqAction { - return func(rawToken lexer.Token) (*token, error) { + return func(_ lexer.Token) (*token, error) { prefs := expressionOpPreferences{expression: expression} expressionOp := &Operation{OperationType: expressionOpType, Preferences: prefs} return &token{TokenType: operationToken, Operation: expressionOp}, nil @@ -522,7 +522,7 @@ func parentWithLevel() yqAction { } func parentWithDefaultLevel() yqAction { - return func(rawToken lexer.Token) (*token, error) { + return func(_ lexer.Token) (*token, error) { prefs := parentOpPreferences{Level: 1} op := &Operation{OperationType: getParentOpType, Value: getParentOpType.Type, StringValue: getParentOpType.Type, Preferences: prefs} return &token{TokenType: operationToken, Operation: op, CheckForPostTraverse: true}, nil diff --git a/pkg/yqlib/operator_assign.go b/pkg/yqlib/operator_assign.go index 834b9f9e..c9ed2f5b 100644 --- a/pkg/yqlib/operator_assign.go +++ b/pkg/yqlib/operator_assign.go @@ -7,7 +7,7 @@ type assignPreferences struct { } func assignUpdateFunc(prefs assignPreferences) crossFunctionCalculation { - return func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { + return func(_ *dataTreeNavigator, _ Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { if !prefs.OnlyWriteNull || lhs.Tag == "!!null" { lhs.UpdateFrom(rhs, prefs) } diff --git a/pkg/yqlib/operator_compare.go b/pkg/yqlib/operator_compare.go index 44febf22..76a571fb 100644 --- a/pkg/yqlib/operator_compare.go +++ b/pkg/yqlib/operator_compare.go @@ -18,7 +18,7 @@ func compareOperator(d *dataTreeNavigator, context Context, expressionNode *Expr } func compare(prefs compareTypePref) func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { - return func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { + return func(_ *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { log.Debugf("compare cross function") if lhs == nil && rhs == nil { owner := &CandidateNode{} diff --git a/pkg/yqlib/operator_create_map.go b/pkg/yqlib/operator_create_map.go index a7182fc8..63247342 100644 --- a/pkg/yqlib/operator_create_map.go +++ b/pkg/yqlib/operator_create_map.go @@ -53,7 +53,7 @@ func sequenceFor(d *dataTreeNavigator, context Context, matchingNode *CandidateN log.Debugf("**********sequenceFor %v", NodeToString(matchingNode)) mapPairs, err := crossFunction(d, context.ChildContext(matches), expressionNode, - func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { + func(_ *dataTreeNavigator, _ Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { node := &CandidateNode{Kind: MappingNode, Tag: "!!map"} log.Debugf("**********adding key %v and value %v", NodeToString(lhs), NodeToString(rhs)) diff --git a/pkg/yqlib/operator_equals.go b/pkg/yqlib/operator_equals.go index 087f5957..4bcf28dd 100644 --- a/pkg/yqlib/operator_equals.go +++ b/pkg/yqlib/operator_equals.go @@ -6,7 +6,7 @@ func equalsOperator(d *dataTreeNavigator, context Context, expressionNode *Expre } func isEquals(flip bool) func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { - return func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { + return func(_ *dataTreeNavigator, _ Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { value := false log.Debugf("isEquals cross function") if lhs == nil && rhs == nil { From 6908161f1fb6713db8259909c606109770fe7673 Mon Sep 17 00:00:00 2001 From: Marco Vito Moscaritolo Date: Mon, 11 Nov 2024 14:06:04 +0100 Subject: [PATCH 07/15] replace error creation --- pkg/yqlib/operator_error.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/yqlib/operator_error.go b/pkg/yqlib/operator_error.go index 1a2283de..d6a2b67f 100644 --- a/pkg/yqlib/operator_error.go +++ b/pkg/yqlib/operator_error.go @@ -1,7 +1,7 @@ package yqlib import ( - "fmt" + "errors" ) func errorOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { @@ -16,5 +16,5 @@ func errorOperator(d *dataTreeNavigator, context Context, expressionNode *Expres if rhs.MatchingNodes.Len() > 0 { errorMessage = rhs.MatchingNodes.Front().Value.(*CandidateNode).Value } - return Context{}, fmt.Errorf(errorMessage) + return Context{}, errors.New(errorMessage) } From b8607bacb9d5b728431cd7aebe8d9725d4345e3d Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 16 Nov 2024 11:52:42 +1100 Subject: [PATCH 08/15] Prefer not having nolint --- cmd/evaluate_all_command.go | 2 +- cmd/evaluate_sequence_command.go | 2 +- cmd/root.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/evaluate_all_command.go b/cmd/evaluate_all_command.go index 25009a65..ea82abef 100644 --- a/cmd/evaluate_all_command.go +++ b/cmd/evaluate_all_command.go @@ -12,7 +12,7 @@ func createEvaluateAllCommand() *cobra.Command { Use: "eval-all [expression] [yaml_file1]...", Aliases: []string{"ea"}, Short: "Loads _all_ yaml documents of _all_ yaml files and runs expression once", - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { //nolint:revive + ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { return nil, cobra.ShellCompDirectiveNoFileComp } diff --git a/cmd/evaluate_sequence_command.go b/cmd/evaluate_sequence_command.go index 16d78e98..e722415e 100644 --- a/cmd/evaluate_sequence_command.go +++ b/cmd/evaluate_sequence_command.go @@ -13,7 +13,7 @@ func createEvaluateSequenceCommand() *cobra.Command { Use: "eval [expression] [yaml_file1]...", Aliases: []string{"e"}, Short: "(default) Apply the expression to each document in each yaml file in sequence", - ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { //nolint:revive + ValidArgsFunction: func(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { return nil, cobra.ShellCompDirectiveNoFileComp } diff --git a/cmd/root.go b/cmd/root.go index 40fb549c..1a9aba9e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -66,7 +66,7 @@ yq -P -oy sample.json return evaluateSequence(cmd, args) }, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { //nolint:revive + PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { cmd.SetOut(cmd.OutOrStdout()) level := logging.WARNING stringFormat := `[%{level}] %{color}%{time:15:04:05}%{color:reset} %{message}` From f071a25fa90d017ec295093498b79d3b3e1de8f7 Mon Sep 17 00:00:00 2001 From: Vladimir Varankin Date: Wed, 6 Nov 2024 11:12:03 +0100 Subject: [PATCH 09/15] cmd: force no color output when NO_COLOR env presents --- cmd/constant.go | 15 ++++++++++++--- cmd/root.go | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/constant.go b/cmd/constant.go index afc69123..3de2de18 100644 --- a/cmd/constant.go +++ b/cmd/constant.go @@ -1,5 +1,7 @@ package cmd +import "os" + var unwrapScalarFlag = newUnwrapFlag() var unwrapScalar = false @@ -12,9 +14,6 @@ var outputFormat = "" var inputFormat = "" var exitStatus = false -var forceColor = false -var forceNoColor = false -var colorsEnabled = false var indent = 2 var noDocSeparators = false var nullInput = false @@ -23,6 +22,16 @@ var verbose = false var version = false var prettyPrint = false +var forceColor = false +var forceNoColor = false +var colorsEnabled = false + +func init() { + // when NO_COLOR environment variable presents and not an empty string the colored output should be disabled; + // refer to no-color.org + forceNoColor = os.Getenv("NO_COLOR") != "" +} + // can be either "" (off), "extract" or "process" var frontMatter = "" diff --git a/cmd/root.go b/cmd/root.go index 1a9aba9e..450de573 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -182,7 +182,7 @@ yq -P -oy sample.json rootCmd.PersistentFlags().BoolVarP(&exitStatus, "exit-status", "e", false, "set exit status if there are no matches or null or false is returned") rootCmd.PersistentFlags().BoolVarP(&forceColor, "colors", "C", false, "force print with colors") - rootCmd.PersistentFlags().BoolVarP(&forceNoColor, "no-colors", "M", false, "force print with no colors") + rootCmd.PersistentFlags().BoolVarP(&forceNoColor, "no-colors", "M", forceNoColor, "force print with no colors") rootCmd.PersistentFlags().StringVarP(&frontMatter, "front-matter", "f", "", "(extract|process) first input as yaml front-matter. Extract will pull out the yaml content, process will run the expression against the yaml content, leaving the remaining data intact") if err = rootCmd.RegisterFlagCompletionFunc("front-matter", cobra.FixedCompletions([]string{"extract", "process"}, cobra.ShellCompDirectiveNoFileComp)); err != nil { panic(err) From 95e7b35f74210bc5dd2fb49f6d79a66881687f55 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 16 Nov 2024 11:54:58 +1100 Subject: [PATCH 10/15] Fixed spelling of coloured --- cmd/constant.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/constant.go b/cmd/constant.go index 3de2de18..eb6e9aeb 100644 --- a/cmd/constant.go +++ b/cmd/constant.go @@ -27,7 +27,7 @@ var forceNoColor = false var colorsEnabled = false func init() { - // when NO_COLOR environment variable presents and not an empty string the colored output should be disabled; + // when NO_COLOR environment variable presents and not an empty string the coloured output should be disabled; // refer to no-color.org forceNoColor = os.Getenv("NO_COLOR") != "" } From f2cc2ea5a8973683a636f92266d44ff1f4ede914 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 16 Nov 2024 00:53:21 +0000 Subject: [PATCH 11/15] Bump golang from 1.23.2 to 1.23.3 Bumps golang from 1.23.2 to 1.23.3. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- Dockerfile.dev | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6c42e753..4204252f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.23.2 as builder +FROM golang:1.23.3 as builder WORKDIR /go/src/mikefarah/yq diff --git a/Dockerfile.dev b/Dockerfile.dev index 8c407190..5dc23d94 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM golang:1.23.2 +FROM golang:1.23.3 RUN apt-get update && \ apt-get install -y npm && \ From 887b4a560fe3c77eb8ddc79174e5fcb56ea610ab Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 16 Nov 2024 12:04:43 +1100 Subject: [PATCH 12/15] Fixed linting --- cmd/constant.go | 8 -------- cmd/root.go | 4 ++++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/cmd/constant.go b/cmd/constant.go index eb6e9aeb..762897d0 100644 --- a/cmd/constant.go +++ b/cmd/constant.go @@ -1,7 +1,5 @@ package cmd -import "os" - var unwrapScalarFlag = newUnwrapFlag() var unwrapScalar = false @@ -26,12 +24,6 @@ var forceColor = false var forceNoColor = false var colorsEnabled = false -func init() { - // when NO_COLOR environment variable presents and not an empty string the coloured output should be disabled; - // refer to no-color.org - forceNoColor = os.Getenv("NO_COLOR") != "" -} - // can be either "" (off), "extract" or "process" var frontMatter = "" diff --git a/cmd/root.go b/cmd/root.go index 450de573..80ebe8e1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -90,6 +90,10 @@ yq -P -oy sample.json logging.SetBackend(backend) yqlib.InitExpressionParser() + // when NO_COLOR environment variable presents and not an empty string the coloured output should be disabled; + // refer to no-color.org + forceNoColor = os.Getenv("NO_COLOR") != "" + return nil }, } From 58a4d2401f65d0090d87647c9668756d0e1e738f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 16 Nov 2024 01:05:44 +0000 Subject: [PATCH 13/15] Bump golang.org/x/net from 0.30.0 to 0.31.0 Bumps [golang.org/x/net](https://github.com/golang/net) from 0.30.0 to 0.31.0. - [Commits](https://github.com/golang/net/compare/v0.30.0...v0.31.0) --- updated-dependencies: - dependency-name: golang.org/x/net dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 6 +++--- go.sum | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 8d9af9f1..e7318e87 100644 --- a/go.mod +++ b/go.mod @@ -16,8 +16,8 @@ require ( github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/yuin/gopher-lua v1.1.1 - golang.org/x/net v0.30.0 - golang.org/x/text v0.19.0 + golang.org/x/net v0.31.0 + golang.org/x/text v0.20.0 gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 gopkg.in/yaml.v3 v3.0.1 ) @@ -26,7 +26,7 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - golang.org/x/sys v0.26.0 // indirect + golang.org/x/sys v0.27.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect ) diff --git a/go.sum b/go.sum index be150b07..55f11c9f 100644 --- a/go.sum +++ b/go.sum @@ -60,16 +60,16 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M= github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= -golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= -golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= -golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= +golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= +golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= +golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= +golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= From f238f018562f4890ba4433c40903d1a9977dc9b7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 16 Nov 2024 01:06:11 +0000 Subject: [PATCH 14/15] Bump github.com/fatih/color from 1.17.0 to 1.18.0 Bumps [github.com/fatih/color](https://github.com/fatih/color) from 1.17.0 to 1.18.0. - [Release notes](https://github.com/fatih/color/releases) - [Commits](https://github.com/fatih/color/compare/v1.17.0...v1.18.0) --- updated-dependencies: - dependency-name: github.com/fatih/color dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e7318e87..5435fd7c 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/alecthomas/repr v0.4.0 github.com/dimchansky/utfbom v1.1.1 github.com/elliotchance/orderedmap v1.6.0 - github.com/fatih/color v1.17.0 + github.com/fatih/color v1.18.0 github.com/goccy/go-json v0.10.3 github.com/goccy/go-yaml v1.12.0 github.com/jinzhu/copier v0.4.0 diff --git a/go.sum b/go.sum index 55f11c9f..0b31f111 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE= github.com/elliotchance/orderedmap v1.6.0 h1:xjn+kbbKXeDq6v9RVE+WYwRbYfAZKvlWfcJNxM8pvEw= github.com/elliotchance/orderedmap v1.6.0/go.mod h1:wsDwEaX5jEoyhbs7x93zk2H/qv0zwuhg4inXhDkYqys= -github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= -github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= +github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= +github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= From 4af292f0768c9ab183215365a5fb7a12951d149e Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sat, 16 Nov 2024 12:27:00 +1100 Subject: [PATCH 15/15] Fixed handling of nulls with sort_by expressions #2164 --- pkg/yqlib/operator_sort.go | 3 ++- pkg/yqlib/operator_sort_test.go | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/yqlib/operator_sort.go b/pkg/yqlib/operator_sort.go index 106b17ff..942ef46a 100644 --- a/pkg/yqlib/operator_sort.go +++ b/pkg/yqlib/operator_sort.go @@ -69,6 +69,7 @@ func (a sortableNodeArray) Less(i, j int) bool { rhsContext := a[j].CompareContext rhsEl := rhsContext.MatchingNodes.Front() + for lhsEl := lhsContext.MatchingNodes.Front(); lhsEl != nil && rhsEl != nil; lhsEl = lhsEl.Next() { lhs := lhsEl.Value.(*CandidateNode) rhs := rhsEl.Value.(*CandidateNode) @@ -83,7 +84,7 @@ func (a sortableNodeArray) Less(i, j int) bool { rhsEl = rhsEl.Next() } - return false + return lhsContext.MatchingNodes.Len() < rhsContext.MatchingNodes.Len() } func (a sortableNodeArray) compare(lhs *CandidateNode, rhs *CandidateNode, dateTimeLayout string) int { diff --git a/pkg/yqlib/operator_sort_test.go b/pkg/yqlib/operator_sort_test.go index 765317ed..df1bbb0f 100644 --- a/pkg/yqlib/operator_sort_test.go +++ b/pkg/yqlib/operator_sort_test.go @@ -21,6 +21,17 @@ var sortByOperatorScenarios = []expressionScenario{ "D0, P[0], (!!map)::{a: banana}\n", }, }, + { + description: "Sort by with null", + skipDoc: true, + document: "[{a: banana},null,{a: apple}]", + expression: `sort_by(.a)[]`, + expected: []string{ + "D0, P[1], (!!null)::null\n", + "D0, P[2], (!!map)::{a: apple}\n", + "D0, P[0], (!!map)::{a: banana}\n", + }, + }, { description: "Sort by multiple fields", document: "[{a: dog},{a: cat, b: banana},{a: cat, b: apple}]",