From 0123b7d7c3fb40dddd4df34e9cd39e467300d5d9 Mon Sep 17 00:00:00 2001 From: Florian Vogt Date: Tue, 28 Nov 2023 21:44:43 +0100 Subject: [PATCH 1/2] Update of dependencies --- encoder/pot.go | 1 - go.mod | 20 +++++++++--------- go.sum | 48 ++++++++++++++++++-------------------------- testdata/unit/go.mod | 2 +- testdata/unit/go.sum | 10 +++++++++ tmpl/keyword.go | 10 ++++----- 6 files changed, 44 insertions(+), 47 deletions(-) create mode 100644 testdata/unit/go.sum diff --git a/encoder/pot.go b/encoder/pot.go index 4305f1f..9cde313 100644 --- a/encoder/pot.go +++ b/encoder/pot.go @@ -26,7 +26,6 @@ func NewPotEncoder(cfg *config.Config, w io.Writer) Encoder { enc.SetWrapWidth(cfg.WrapWidth) enc.SetWriteHeader(!cfg.OmitHeader) enc.SetWriteReferences(!cfg.WriteNoLocation) - enc.SetSort(true) return &potEncoder{cfg: cfg, w: enc} } diff --git a/go.mod b/go.mod index 5bf321c..8e4a8ea 100644 --- a/go.mod +++ b/go.mod @@ -1,25 +1,23 @@ module github.com/vorlif/xspreak -go 1.18 +go 1.19 require ( github.com/mattn/go-zglob v0.0.4 - github.com/sirupsen/logrus v1.9.0 - github.com/spf13/cobra v1.6.1 - github.com/stretchr/testify v1.8.1 - github.com/vorlif/spreak v0.4.0 - golang.org/x/text v0.7.0 - golang.org/x/tools v0.6.0 + github.com/sirupsen/logrus v1.9.3 + github.com/spf13/cobra v1.8.0 + github.com/stretchr/testify v1.8.4 + github.com/vorlif/spreak v0.5.0 + golang.org/x/text v0.14.0 + golang.org/x/tools v0.16.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/inconshreveable/mousetrap v1.0.1 // indirect - github.com/kr/pretty v0.1.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/mod v0.8.0 // indirect + golang.org/x/mod v0.14.0 // indirect golang.org/x/sys v0.5.0 // indirect - gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index e543fc9..fa56105 100644 --- a/go.sum +++ b/go.sum @@ -1,48 +1,38 @@ -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= -github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/mattn/go-zglob v0.0.4 h1:LQi2iOm0/fGgu80AioIJ/1j9w9Oh+9DZ39J4VAGzHQM= github.com/mattn/go-zglob v0.0.4/go.mod h1:MxxjyoXXnMxfIpxTK2GAkw1w8glPsQILx3N5wrKakiY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= -github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/vorlif/spreak v0.4.0 h1:2qUNIoPk8iGtAvMYNL1bCJe6BeKOewIJXKA349rDzB8= -github.com/vorlif/spreak v0.4.0/go.mod h1:6xt/wqWr9j9cnLicoaqGdMUwCmJziJBWNePGXWHbimM= -golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/vorlif/spreak v0.5.0 h1:Y/+S/R0CBn5caG6T2/PC19F9KDoA/nqRMyFvgyZYtp8= +github.com/vorlif/spreak v0.5.0/go.mod h1:vcqv4dB1XgHpxIXhV5C+8EgqlzKfL37Atj2O/bOB1Bw= +golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= +golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= +golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/testdata/unit/go.mod b/testdata/unit/go.mod index e753b05..d3d2108 100644 --- a/testdata/unit/go.mod +++ b/testdata/unit/go.mod @@ -2,4 +2,4 @@ module github.com/vorlif/xspreakunit go 1.18 -require github.com/vorlif/spreak v0.1.2-0.20220511142256-22c219833d0b \ No newline at end of file +require github.com/vorlif/spreak v0.1.2-0.20220511142256-22c219833d0b diff --git a/testdata/unit/go.sum b/testdata/unit/go.sum new file mode 100644 index 0000000..60338c0 --- /dev/null +++ b/testdata/unit/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/vorlif/spreak v0.1.2-0.20220511142256-22c219833d0b h1:oxvJLYsbxUjlVPm7e+RTVJC9pw6UrJQdpQX8dXGc7zk= +github.com/vorlif/spreak v0.1.2-0.20220511142256-22c219833d0b/go.mod h1:/mYnzorAXrvSyN5a81dWy/e1Xhm+0vGOUHIcq8Wif2w= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tmpl/keyword.go b/tmpl/keyword.go index 6e65758..5ceca3a 100644 --- a/tmpl/keyword.go +++ b/tmpl/keyword.go @@ -130,13 +130,13 @@ func DefaultKeywords(name string, isMonolingual bool) []*Keyword { } func (k *Keyword) MaxPosition() int { - start := max(k.SingularPos, -1) - start = max(start, k.PluralPos) - start = max(start, k.ContextPos) - return max(start, k.DomainPos) + start := maxOf(k.SingularPos, -1) + start = maxOf(start, k.PluralPos) + start = maxOf(start, k.ContextPos) + return maxOf(start, k.DomainPos) } -func max(x, y int) int { +func maxOf(x, y int) int { if x > y { return x } From 787907319deb8976c486ff48d0fae77f432bd106 Mon Sep 17 00:00:00 2001 From: Florian Vogt Date: Tue, 28 Nov 2023 21:55:20 +0100 Subject: [PATCH 2/2] Lint adjustments --- Makefile | 2 -- commands/merge.go | 2 +- goextractors/comments.go | 2 +- goextractors/funcreturn.go | 9 +++++---- goextractors/testlib_test.go | 8 ++++---- goextractors/utils.go | 12 +++++++----- testdata/project/globalassign.go | 1 + 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index b096950..c63fa90 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,6 @@ gofmt: lint: - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1 - @echo Running golangci-lint golangci-lint run --fix ./... diff --git a/commands/merge.go b/commands/merge.go index 7a6f740..761e685 100644 --- a/commands/merge.go +++ b/commands/merge.go @@ -33,7 +33,7 @@ func init() { rootCmd.AddCommand(mergeCmd) } -func mergeCmdF(cmd *cobra.Command, args []string) { +func mergeCmdF(cmd *cobra.Command, _ []string) { targetLang, errL := cmd.Flags().GetString("lang") if errL != nil { log.WithError(errL).Fatal("Invalid source file") diff --git a/goextractors/comments.go b/goextractors/comments.go index 1f14403..9a20743 100644 --- a/goextractors/comments.go +++ b/goextractors/comments.go @@ -16,7 +16,7 @@ func NewCommentsExtractor() extractors.Extractor { return &commentsExtractor{} } -func (d *commentsExtractor) Run(ctx context.Context, extractCtx *extractors.Context) ([]result.Issue, error) { +func (d *commentsExtractor) Run(_ context.Context, extractCtx *extractors.Context) ([]result.Issue, error) { util.TrackTime(time.Now(), "Extract comments") for _, pkg := range extractCtx.OriginalPackages { for _, file := range pkg.Syntax { diff --git a/goextractors/funcreturn.go b/goextractors/funcreturn.go index 5b8cde9..094644c 100644 --- a/goextractors/funcreturn.go +++ b/goextractors/funcreturn.go @@ -36,13 +36,14 @@ func (e *funcReturnExtractor) Run(_ context.Context, extractCtx *extractors.Cont extractedResults := make([]etype.Token, len(node.Type.Results.List)) var foundType bool for i, res := range node.Type.Results.List { - if tok, _ := extractCtx.SearchIdentAndToken(res); tok == etype.None { + tok, _ := extractCtx.SearchIdentAndToken(res) + if tok == etype.None { extractedResults[i] = etype.None continue - } else { - extractedResults[i] = tok - foundType = true } + + extractedResults[i] = tok + foundType = true } if !foundType { diff --git a/goextractors/testlib_test.go b/goextractors/testlib_test.go index 22fbf4f..d0b56fc 100644 --- a/goextractors/testlib_test.go +++ b/goextractors/testlib_test.go @@ -8,6 +8,7 @@ import ( "path/filepath" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/vorlif/xspreak/config" @@ -23,11 +24,10 @@ const ( func TestPrintAst(t *testing.T) { fset := token.NewFileSet() // positions are relative to fset f, err := parser.ParseFile(fset, filepath.Join(testdataDir, "funccall.go"), nil, 0) - if err != nil { - panic(err) - } + require.NoError(t, err) - ast.Print(fset, f) + err = ast.Print(fset, f) + assert.NoError(t, err) } func runExtraction(t *testing.T, dir string, testExtractors ...extractors.Extractor) []result.Issue { diff --git a/goextractors/utils.go b/goextractors/utils.go index 1bc17c0..db01e48 100644 --- a/goextractors/utils.go +++ b/goextractors/utils.go @@ -32,13 +32,15 @@ func searchSelector(expr interface{}) *ast.SelectorExpr { } func calculatePosIdx(first, second int) int { - if first > 0 && second > 0 { - return first * second - } else if first > 0 { + if first > 0 { + if second > 0 { + return first * second + } + return first - } else { - return second } + + return second } type searchCollector struct { diff --git a/testdata/project/globalassign.go b/testdata/project/globalassign.go index a24fc44..81c5725 100644 --- a/testdata/project/globalassign.go +++ b/testdata/project/globalassign.go @@ -5,6 +5,7 @@ import ( ) // TRANSLATORS: Name of the app +// //goland:noinspection GoVarAndConstTypeMayBeOmitted var applicationName alias.Singular = "app"