From 49eceac9d17f9880a26d55ace25a1de37ec9a489 Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Thu, 24 Apr 2025 08:07:00 +0200 Subject: [PATCH 01/12] feat: adding embeddedcheck linter --- .golangci.next.reference.yml | 2 + go.mod | 1 + go.sum | 4 ++ pkg/golinters/embeddedcheck/embeddedcheck.go | 19 +++++++++ .../embeddedcheck_integration_test.go | 11 ++++++ .../embeddedcheck/testdata/comments.go | 27 +++++++++++++ .../embeddedcheck/testdata/simple.go | 39 +++++++++++++++++++ .../embeddedcheck/testdata/special-cases.go | 11 ++++++ pkg/lint/lintersdb/builder_linter.go | 6 +++ 9 files changed, 120 insertions(+) create mode 100644 pkg/golinters/embeddedcheck/embeddedcheck.go create mode 100644 pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go create mode 100644 pkg/golinters/embeddedcheck/testdata/comments.go create mode 100644 pkg/golinters/embeddedcheck/testdata/simple.go create mode 100644 pkg/golinters/embeddedcheck/testdata/special-cases.go diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 37866ff00f2c..0ae29f2afdac 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -32,6 +32,7 @@ linters: - dupl - dupword - durationcheck + - embeddedcheck - err113 - errcheck - errchkjson @@ -140,6 +141,7 @@ linters: - dupl - dupword - durationcheck + - embeddedcheck - err113 - errcheck - errchkjson diff --git a/go.mod b/go.mod index a8835e203561..c8df5784bd66 100644 --- a/go.mod +++ b/go.mod @@ -176,6 +176,7 @@ require ( github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.6 // indirect + github.com/manuelarte/embeddedcheck v0.1.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect diff --git a/go.sum b/go.sum index ff028d1c4652..75d6c85f21ec 100644 --- a/go.sum +++ b/go.sum @@ -389,6 +389,10 @@ github.com/macabu/inamedparam v0.2.0 h1:VyPYpOc10nkhI2qeNUdh3Zket4fcZjEWe35poddB github.com/macabu/inamedparam v0.2.0/go.mod h1:+Pee9/YfGe5LJ62pYXqB89lJ+0k5bsR8Wgz/C0Zlq3U= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/manuelarte/embeddedcheck v0.0.0-20250424052803-01b6c502329f h1:a2YN2IGksQUTvhEshCSgtL/yDGSIurVE8Q2SRWqRBQ4= +github.com/manuelarte/embeddedcheck v0.0.0-20250424052803-01b6c502329f/go.mod h1:cAaX6azjhVXtXcQHj4nYCWnTpiB1X5USQJ72G8ntFAU= +github.com/manuelarte/embeddedcheck v0.1.0 h1:6AOs56h594geKgf9hal4ZloOaRaEAYpoGnK6DDK90BQ= +github.com/manuelarte/embeddedcheck v0.1.0/go.mod h1:cAaX6azjhVXtXcQHj4nYCWnTpiB1X5USQJ72G8ntFAU= github.com/manuelarte/funcorder v0.2.1 h1:7QJsw3qhljoZ5rH0xapIvjw31EcQeFbF31/7kQ/xS34= github.com/manuelarte/funcorder v0.2.1/go.mod h1:BQQ0yW57+PF9ZpjpeJDKOffEsQbxDFKW8F8zSMe/Zd0= github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI= diff --git a/pkg/golinters/embeddedcheck/embeddedcheck.go b/pkg/golinters/embeddedcheck/embeddedcheck.go new file mode 100644 index 000000000000..03809dcc55aa --- /dev/null +++ b/pkg/golinters/embeddedcheck/embeddedcheck.go @@ -0,0 +1,19 @@ +package embeddedcheck + +import ( + "github.com/manuelarte/embeddedcheck/analyzer" + "golang.org/x/tools/go/analysis" + + "github.com/golangci/golangci-lint/v2/pkg/goanalysis" +) + +func New() *goanalysis.Linter { + a := analyzer.NewAnalyzer() + + return goanalysis.NewLinter( + a.Name, + a.Doc, + []*analysis.Analyzer{a}, + nil, + ).WithLoadMode(goanalysis.LoadModeSyntax) +} diff --git a/pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go b/pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go new file mode 100644 index 000000000000..f984812f8895 --- /dev/null +++ b/pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go @@ -0,0 +1,11 @@ +package embeddedcheck + +import ( + "testing" + + "github.com/golangci/golangci-lint/v2/test/testshared/integration" +) + +func TestFromTestdata(t *testing.T) { + integration.RunTestdata(t) +} diff --git a/pkg/golinters/embeddedcheck/testdata/comments.go b/pkg/golinters/embeddedcheck/testdata/comments.go new file mode 100644 index 000000000000..24314e1b2981 --- /dev/null +++ b/pkg/golinters/embeddedcheck/testdata/comments.go @@ -0,0 +1,27 @@ +//golangcitest:args -Eembeddedcheck +package simple + +import "time" + +type ValidStructWithSingleLineComments struct { + // time.Time Single line comment + time.Time + + // version Single line comment + version int +} + +type StructWithSingleLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + // version Single line comment + version int +} + +type StructWithMultiLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + // version Single line comment + // very long comment + version int +} diff --git a/pkg/golinters/embeddedcheck/testdata/simple.go b/pkg/golinters/embeddedcheck/testdata/simple.go new file mode 100644 index 000000000000..8f4e92fe42cc --- /dev/null +++ b/pkg/golinters/embeddedcheck/testdata/simple.go @@ -0,0 +1,39 @@ +//golangcitest:args -Eembeddedcheck +package simple + +import ( + "context" + "time" +) + +type ValidStruct struct { + time.Time + + version int +} + +type NoSpaceStruct struct { + time.Time // want `there must be an empty line separating embedded fields from regular fields` + version int +} + +type NotSortedStruct struct { + version int + + time.Time // want `embedded types should be listed before non embedded types` +} + +type MixedEmbeddedAndNotEmbedded struct { + context.Context + + name string + + time.Time // want `embedded types should be listed before non embedded types` + + age int +} + +type EmbeddedWithPointers struct { + *time.Time // want `there must be an empty line separating embedded fields from regular fields` + version int +} diff --git a/pkg/golinters/embeddedcheck/testdata/special-cases.go b/pkg/golinters/embeddedcheck/testdata/special-cases.go new file mode 100644 index 000000000000..e145b89a5090 --- /dev/null +++ b/pkg/golinters/embeddedcheck/testdata/special-cases.go @@ -0,0 +1,11 @@ +//golangcitest:args -Eembeddedcheck +package simple + +import "time" + +func myFunction() { + type myType struct { + version int + time.Time // want `embedded types should be listed before non embedded types` + } +} diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 5ac3e5ba2fb0..5411bf6d8cb7 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -18,6 +18,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/dupl" "github.com/golangci/golangci-lint/v2/pkg/golinters/dupword" "github.com/golangci/golangci-lint/v2/pkg/golinters/durationcheck" + "github.com/golangci/golangci-lint/v2/pkg/golinters/embeddedcheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/err113" "github.com/golangci/golangci-lint/v2/pkg/golinters/errcheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/errchkjson" @@ -205,6 +206,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithLoadForGoAnalysis(). WithURL("https://github.com/charithe/durationcheck"), + linter.NewConfig(embeddedcheck.New()). + WithSince("v2.2.0"). + WithLoadForGoAnalysis(). + WithURL("https://github.com/manuelarte/embeddedcheck"), + linter.NewConfig(errcheck.New(&cfg.Linters.Settings.Errcheck)). WithGroups(config.GroupStandard). WithSince("v1.0.0"). From 719f1cc868fbcc871079effa588179d855dfc3cc Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Thu, 24 Apr 2025 08:41:29 +0200 Subject: [PATCH 02/12] feat: fixing go.mod --- go.mod | 2 +- go.sum | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c8df5784bd66..ede4e7c03949 100644 --- a/go.mod +++ b/go.mod @@ -73,6 +73,7 @@ require ( github.com/ldez/usetesting v0.4.3 github.com/leonklingele/grouper v1.1.2 github.com/macabu/inamedparam v0.2.0 + github.com/manuelarte/embeddedcheck v0.1.0 github.com/manuelarte/funcorder v0.2.1 github.com/maratori/testableexamples v1.0.0 github.com/maratori/testpackage v1.1.1 @@ -176,7 +177,6 @@ require ( github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.6 // indirect - github.com/manuelarte/embeddedcheck v0.1.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect diff --git a/go.sum b/go.sum index 75d6c85f21ec..9178dd3f388d 100644 --- a/go.sum +++ b/go.sum @@ -389,8 +389,6 @@ github.com/macabu/inamedparam v0.2.0 h1:VyPYpOc10nkhI2qeNUdh3Zket4fcZjEWe35poddB github.com/macabu/inamedparam v0.2.0/go.mod h1:+Pee9/YfGe5LJ62pYXqB89lJ+0k5bsR8Wgz/C0Zlq3U= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= -github.com/manuelarte/embeddedcheck v0.0.0-20250424052803-01b6c502329f h1:a2YN2IGksQUTvhEshCSgtL/yDGSIurVE8Q2SRWqRBQ4= -github.com/manuelarte/embeddedcheck v0.0.0-20250424052803-01b6c502329f/go.mod h1:cAaX6azjhVXtXcQHj4nYCWnTpiB1X5USQJ72G8ntFAU= github.com/manuelarte/embeddedcheck v0.1.0 h1:6AOs56h594geKgf9hal4ZloOaRaEAYpoGnK6DDK90BQ= github.com/manuelarte/embeddedcheck v0.1.0/go.mod h1:cAaX6azjhVXtXcQHj4nYCWnTpiB1X5USQJ72G8ntFAU= github.com/manuelarte/funcorder v0.2.1 h1:7QJsw3qhljoZ5rH0xapIvjw31EcQeFbF31/7kQ/xS34= From 19d0761b1b3c0b543381999e4bd30d56f864cdb0 Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Thu, 24 Apr 2025 13:09:49 +0200 Subject: [PATCH 03/12] renaming integration tests with prefix embeddedcheck --- .../testdata/{comments.go => embeddedcheck_comments.go} | 0 .../embeddedcheck/testdata/{simple.go => embeddedcheck_simple.go} | 0 .../testdata/{special-cases.go => embeddedcheck_special-cases.go} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename pkg/golinters/embeddedcheck/testdata/{comments.go => embeddedcheck_comments.go} (100%) rename pkg/golinters/embeddedcheck/testdata/{simple.go => embeddedcheck_simple.go} (100%) rename pkg/golinters/embeddedcheck/testdata/{special-cases.go => embeddedcheck_special-cases.go} (100%) diff --git a/pkg/golinters/embeddedcheck/testdata/comments.go b/pkg/golinters/embeddedcheck/testdata/embeddedcheck_comments.go similarity index 100% rename from pkg/golinters/embeddedcheck/testdata/comments.go rename to pkg/golinters/embeddedcheck/testdata/embeddedcheck_comments.go diff --git a/pkg/golinters/embeddedcheck/testdata/simple.go b/pkg/golinters/embeddedcheck/testdata/embeddedcheck_simple.go similarity index 100% rename from pkg/golinters/embeddedcheck/testdata/simple.go rename to pkg/golinters/embeddedcheck/testdata/embeddedcheck_simple.go diff --git a/pkg/golinters/embeddedcheck/testdata/special-cases.go b/pkg/golinters/embeddedcheck/testdata/embeddedcheck_special-cases.go similarity index 100% rename from pkg/golinters/embeddedcheck/testdata/special-cases.go rename to pkg/golinters/embeddedcheck/testdata/embeddedcheck_special-cases.go From 0c883bfd4b0b3c31287de7a7d76527a93739973e Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Thu, 24 Apr 2025 13:22:13 +0200 Subject: [PATCH 04/12] removing WithLoadForGoAnalysis() --- pkg/lint/lintersdb/builder_linter.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 5411bf6d8cb7..df0efbb99542 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -208,7 +208,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { linter.NewConfig(embeddedcheck.New()). WithSince("v2.2.0"). - WithLoadForGoAnalysis(). WithURL("https://github.com/manuelarte/embeddedcheck"), linter.NewConfig(errcheck.New(&cfg.Linters.Settings.Errcheck)). From 550a39008efa7d3cf6a30a64b6a147667b6f57b8 Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Thu, 24 Apr 2025 08:07:00 +0200 Subject: [PATCH 05/12] feat: adding embeddedcheck linter --- .golangci.next.reference.yml | 2 + go.mod | 1 + go.sum | 2 + pkg/golinters/embeddedcheck/embeddedcheck.go | 19 +++++++++ .../embeddedcheck_integration_test.go | 11 ++++++ .../embeddedcheck/testdata/comments.go | 27 +++++++++++++ .../embeddedcheck/testdata/simple.go | 39 +++++++++++++++++++ .../embeddedcheck/testdata/special-cases.go | 11 ++++++ pkg/lint/lintersdb/builder_linter.go | 6 +++ 9 files changed, 118 insertions(+) create mode 100644 pkg/golinters/embeddedcheck/embeddedcheck.go create mode 100644 pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go create mode 100644 pkg/golinters/embeddedcheck/testdata/comments.go create mode 100644 pkg/golinters/embeddedcheck/testdata/simple.go create mode 100644 pkg/golinters/embeddedcheck/testdata/special-cases.go diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index dbcc0377a400..2eb543e77111 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -32,6 +32,7 @@ linters: - dupl - dupword - durationcheck + - embeddedcheck - err113 - errcheck - errchkjson @@ -140,6 +141,7 @@ linters: - dupl - dupword - durationcheck + - embeddedcheck - err113 - errcheck - errchkjson diff --git a/go.mod b/go.mod index b2a3c45e11cc..aa0146fdb114 100644 --- a/go.mod +++ b/go.mod @@ -73,6 +73,7 @@ require ( github.com/ldez/usetesting v0.4.3 github.com/leonklingele/grouper v1.1.2 github.com/macabu/inamedparam v0.2.0 + github.com/manuelarte/embeddedcheck v0.1.0 github.com/manuelarte/funcorder v0.3.0 github.com/maratori/testableexamples v1.0.0 github.com/maratori/testpackage v1.1.1 diff --git a/go.sum b/go.sum index 182df4b27f2b..53390c6d269e 100644 --- a/go.sum +++ b/go.sum @@ -389,6 +389,8 @@ github.com/macabu/inamedparam v0.2.0 h1:VyPYpOc10nkhI2qeNUdh3Zket4fcZjEWe35poddB github.com/macabu/inamedparam v0.2.0/go.mod h1:+Pee9/YfGe5LJ62pYXqB89lJ+0k5bsR8Wgz/C0Zlq3U= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/manuelarte/embeddedcheck v0.1.0 h1:6AOs56h594geKgf9hal4ZloOaRaEAYpoGnK6DDK90BQ= +github.com/manuelarte/embeddedcheck v0.1.0/go.mod h1:cAaX6azjhVXtXcQHj4nYCWnTpiB1X5USQJ72G8ntFAU= github.com/manuelarte/funcorder v0.3.0 h1:mV1joNYIjIUnnyZ6wfaC+sCWB6IvG62ay3xuhbklHps= github.com/manuelarte/funcorder v0.3.0/go.mod h1:wBFktqsi8PyQvNYEUpF5Lt+V/xqgaevfCi4SSpUhyPo= github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI= diff --git a/pkg/golinters/embeddedcheck/embeddedcheck.go b/pkg/golinters/embeddedcheck/embeddedcheck.go new file mode 100644 index 000000000000..03809dcc55aa --- /dev/null +++ b/pkg/golinters/embeddedcheck/embeddedcheck.go @@ -0,0 +1,19 @@ +package embeddedcheck + +import ( + "github.com/manuelarte/embeddedcheck/analyzer" + "golang.org/x/tools/go/analysis" + + "github.com/golangci/golangci-lint/v2/pkg/goanalysis" +) + +func New() *goanalysis.Linter { + a := analyzer.NewAnalyzer() + + return goanalysis.NewLinter( + a.Name, + a.Doc, + []*analysis.Analyzer{a}, + nil, + ).WithLoadMode(goanalysis.LoadModeSyntax) +} diff --git a/pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go b/pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go new file mode 100644 index 000000000000..f984812f8895 --- /dev/null +++ b/pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go @@ -0,0 +1,11 @@ +package embeddedcheck + +import ( + "testing" + + "github.com/golangci/golangci-lint/v2/test/testshared/integration" +) + +func TestFromTestdata(t *testing.T) { + integration.RunTestdata(t) +} diff --git a/pkg/golinters/embeddedcheck/testdata/comments.go b/pkg/golinters/embeddedcheck/testdata/comments.go new file mode 100644 index 000000000000..24314e1b2981 --- /dev/null +++ b/pkg/golinters/embeddedcheck/testdata/comments.go @@ -0,0 +1,27 @@ +//golangcitest:args -Eembeddedcheck +package simple + +import "time" + +type ValidStructWithSingleLineComments struct { + // time.Time Single line comment + time.Time + + // version Single line comment + version int +} + +type StructWithSingleLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + // version Single line comment + version int +} + +type StructWithMultiLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + // version Single line comment + // very long comment + version int +} diff --git a/pkg/golinters/embeddedcheck/testdata/simple.go b/pkg/golinters/embeddedcheck/testdata/simple.go new file mode 100644 index 000000000000..8f4e92fe42cc --- /dev/null +++ b/pkg/golinters/embeddedcheck/testdata/simple.go @@ -0,0 +1,39 @@ +//golangcitest:args -Eembeddedcheck +package simple + +import ( + "context" + "time" +) + +type ValidStruct struct { + time.Time + + version int +} + +type NoSpaceStruct struct { + time.Time // want `there must be an empty line separating embedded fields from regular fields` + version int +} + +type NotSortedStruct struct { + version int + + time.Time // want `embedded types should be listed before non embedded types` +} + +type MixedEmbeddedAndNotEmbedded struct { + context.Context + + name string + + time.Time // want `embedded types should be listed before non embedded types` + + age int +} + +type EmbeddedWithPointers struct { + *time.Time // want `there must be an empty line separating embedded fields from regular fields` + version int +} diff --git a/pkg/golinters/embeddedcheck/testdata/special-cases.go b/pkg/golinters/embeddedcheck/testdata/special-cases.go new file mode 100644 index 000000000000..e145b89a5090 --- /dev/null +++ b/pkg/golinters/embeddedcheck/testdata/special-cases.go @@ -0,0 +1,11 @@ +//golangcitest:args -Eembeddedcheck +package simple + +import "time" + +func myFunction() { + type myType struct { + version int + time.Time // want `embedded types should be listed before non embedded types` + } +} diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 5ac3e5ba2fb0..5411bf6d8cb7 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -18,6 +18,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/dupl" "github.com/golangci/golangci-lint/v2/pkg/golinters/dupword" "github.com/golangci/golangci-lint/v2/pkg/golinters/durationcheck" + "github.com/golangci/golangci-lint/v2/pkg/golinters/embeddedcheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/err113" "github.com/golangci/golangci-lint/v2/pkg/golinters/errcheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/errchkjson" @@ -205,6 +206,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithLoadForGoAnalysis(). WithURL("https://github.com/charithe/durationcheck"), + linter.NewConfig(embeddedcheck.New()). + WithSince("v2.2.0"). + WithLoadForGoAnalysis(). + WithURL("https://github.com/manuelarte/embeddedcheck"), + linter.NewConfig(errcheck.New(&cfg.Linters.Settings.Errcheck)). WithGroups(config.GroupStandard). WithSince("v1.0.0"). From d101e8f566ef0d4ca66a4d9fdfd633a2f2cb853e Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Thu, 24 Apr 2025 13:09:49 +0200 Subject: [PATCH 06/12] renaming integration tests with prefix embeddedcheck --- .../testdata/{comments.go => embeddedcheck_comments.go} | 0 .../embeddedcheck/testdata/{simple.go => embeddedcheck_simple.go} | 0 .../testdata/{special-cases.go => embeddedcheck_special-cases.go} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename pkg/golinters/embeddedcheck/testdata/{comments.go => embeddedcheck_comments.go} (100%) rename pkg/golinters/embeddedcheck/testdata/{simple.go => embeddedcheck_simple.go} (100%) rename pkg/golinters/embeddedcheck/testdata/{special-cases.go => embeddedcheck_special-cases.go} (100%) diff --git a/pkg/golinters/embeddedcheck/testdata/comments.go b/pkg/golinters/embeddedcheck/testdata/embeddedcheck_comments.go similarity index 100% rename from pkg/golinters/embeddedcheck/testdata/comments.go rename to pkg/golinters/embeddedcheck/testdata/embeddedcheck_comments.go diff --git a/pkg/golinters/embeddedcheck/testdata/simple.go b/pkg/golinters/embeddedcheck/testdata/embeddedcheck_simple.go similarity index 100% rename from pkg/golinters/embeddedcheck/testdata/simple.go rename to pkg/golinters/embeddedcheck/testdata/embeddedcheck_simple.go diff --git a/pkg/golinters/embeddedcheck/testdata/special-cases.go b/pkg/golinters/embeddedcheck/testdata/embeddedcheck_special-cases.go similarity index 100% rename from pkg/golinters/embeddedcheck/testdata/special-cases.go rename to pkg/golinters/embeddedcheck/testdata/embeddedcheck_special-cases.go From 71ca3dd5ca03cc81946ce853751b82966cf0b153 Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Thu, 24 Apr 2025 13:22:13 +0200 Subject: [PATCH 07/12] removing WithLoadForGoAnalysis() --- pkg/lint/lintersdb/builder_linter.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index 5411bf6d8cb7..df0efbb99542 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -208,7 +208,6 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { linter.NewConfig(embeddedcheck.New()). WithSince("v2.2.0"). - WithLoadForGoAnalysis(). WithURL("https://github.com/manuelarte/embeddedcheck"), linter.NewConfig(errcheck.New(&cfg.Linters.Settings.Errcheck)). From bd144482f92a7a266b18948d79e29c9ad82a3638 Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Mon, 12 May 2025 15:33:05 +0200 Subject: [PATCH 08/12] updating name to embeddedstructfieldcheck --- .golangci.next.reference.yml | 4 ++-- go.mod | 8 ++++---- go.sum | 20 +++++++++---------- .../testdata/embeddedcheck_special-cases.go | 11 ---------- .../embeddedstructfieldcheck.go} | 4 ++-- ...eddedstructfieldcheck_integration_test.go} | 2 +- .../embeddedstructfieldcheck_comments.go} | 2 +- .../embeddedstructfieldcheck_simple.go} | 6 +++--- .../embeddedstructfieldcheck_special_cases.go | 11 ++++++++++ pkg/lint/lintersdb/builder_linter.go | 6 +++--- 10 files changed, 37 insertions(+), 37 deletions(-) delete mode 100644 pkg/golinters/embeddedcheck/testdata/embeddedcheck_special-cases.go rename pkg/golinters/{embeddedcheck/embeddedcheck.go => embeddedstructfieldcheck/embeddedstructfieldcheck.go} (76%) rename pkg/golinters/{embeddedcheck/embeddedcheck_integration_test.go => embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go} (82%) rename pkg/golinters/{embeddedcheck/testdata/embeddedcheck_comments.go => embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_comments.go} (93%) rename pkg/golinters/{embeddedcheck/testdata/embeddedcheck_simple.go => embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_simple.go} (72%) create mode 100644 pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_special_cases.go diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 2eb543e77111..776986397f52 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -32,7 +32,7 @@ linters: - dupl - dupword - durationcheck - - embeddedcheck + - embeddedstructfieldcheck - err113 - errcheck - errchkjson @@ -141,7 +141,7 @@ linters: - dupl - dupword - durationcheck - - embeddedcheck + - embeddedstructfieldcheck - err113 - errcheck - errchkjson diff --git a/go.mod b/go.mod index aa0146fdb114..c6b84ee11e7e 100644 --- a/go.mod +++ b/go.mod @@ -73,7 +73,7 @@ require ( github.com/ldez/usetesting v0.4.3 github.com/leonklingele/grouper v1.1.2 github.com/macabu/inamedparam v0.2.0 - github.com/manuelarte/embeddedcheck v0.1.0 + github.com/manuelarte/embeddedstructfieldcheck v0.2.0 github.com/manuelarte/funcorder v0.3.0 github.com/maratori/testableexamples v1.0.0 github.com/maratori/testpackage v1.1.1 @@ -130,8 +130,8 @@ require ( go.augendre.info/fatcontext v0.8.0 go.uber.org/automaxprocs v1.6.0 golang.org/x/mod v0.24.0 - golang.org/x/sys v0.32.0 - golang.org/x/tools v0.32.0 + golang.org/x/sys v0.33.0 + golang.org/x/tools v0.33.0 gopkg.in/yaml.v3 v3.0.1 honnef.co/go/tools v0.6.1 mvdan.cc/gofumpt v0.8.0 @@ -210,7 +210,7 @@ require ( go.uber.org/zap v1.24.0 // indirect golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac // indirect - golang.org/x/sync v0.13.0 // indirect + golang.org/x/sync v0.14.0 // indirect golang.org/x/text v0.24.0 // indirect google.golang.org/protobuf v1.36.6 // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum index 53390c6d269e..1688d2ccf9e8 100644 --- a/go.sum +++ b/go.sum @@ -389,8 +389,8 @@ github.com/macabu/inamedparam v0.2.0 h1:VyPYpOc10nkhI2qeNUdh3Zket4fcZjEWe35poddB github.com/macabu/inamedparam v0.2.0/go.mod h1:+Pee9/YfGe5LJ62pYXqB89lJ+0k5bsR8Wgz/C0Zlq3U= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= -github.com/manuelarte/embeddedcheck v0.1.0 h1:6AOs56h594geKgf9hal4ZloOaRaEAYpoGnK6DDK90BQ= -github.com/manuelarte/embeddedcheck v0.1.0/go.mod h1:cAaX6azjhVXtXcQHj4nYCWnTpiB1X5USQJ72G8ntFAU= +github.com/manuelarte/embeddedstructfieldcheck v0.2.0 h1:GUV2A7XAOOj/XWlN1AdICai7YV6sSF8ZBODF58RSa9A= +github.com/manuelarte/embeddedstructfieldcheck v0.2.0/go.mod h1:LSo/IQpPfx1dXMcX4ibZCYA7Yy6ayZHIaOGM70+1Wy8= github.com/manuelarte/funcorder v0.3.0 h1:mV1joNYIjIUnnyZ6wfaC+sCWB6IvG62ay3xuhbklHps= github.com/manuelarte/funcorder v0.3.0/go.mod h1:wBFktqsi8PyQvNYEUpF5Lt+V/xqgaevfCi4SSpUhyPo= github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI= @@ -743,8 +743,8 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= -golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= +golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY= +golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -766,8 +766,8 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= -golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= +golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -823,8 +823,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= -golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= +golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= @@ -906,8 +906,8 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= -golang.org/x/tools v0.32.0 h1:Q7N1vhpkQv7ybVzLFtTjvQya2ewbwNDZzUgfXGqtMWU= -golang.org/x/tools v0.32.0/go.mod h1:ZxrU41P/wAbZD8EDa6dDCa6XfpkhJ7HFMjHJXfBDu8s= +golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= +golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/pkg/golinters/embeddedcheck/testdata/embeddedcheck_special-cases.go b/pkg/golinters/embeddedcheck/testdata/embeddedcheck_special-cases.go deleted file mode 100644 index e145b89a5090..000000000000 --- a/pkg/golinters/embeddedcheck/testdata/embeddedcheck_special-cases.go +++ /dev/null @@ -1,11 +0,0 @@ -//golangcitest:args -Eembeddedcheck -package simple - -import "time" - -func myFunction() { - type myType struct { - version int - time.Time // want `embedded types should be listed before non embedded types` - } -} diff --git a/pkg/golinters/embeddedcheck/embeddedcheck.go b/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck.go similarity index 76% rename from pkg/golinters/embeddedcheck/embeddedcheck.go rename to pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck.go index 03809dcc55aa..781bcf5d201e 100644 --- a/pkg/golinters/embeddedcheck/embeddedcheck.go +++ b/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck.go @@ -1,7 +1,7 @@ -package embeddedcheck +package embeddedstructfieldcheck import ( - "github.com/manuelarte/embeddedcheck/analyzer" + "github.com/manuelarte/embeddedstructfieldcheck/analyzer" "golang.org/x/tools/go/analysis" "github.com/golangci/golangci-lint/v2/pkg/goanalysis" diff --git a/pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go b/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go similarity index 82% rename from pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go rename to pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go index f984812f8895..a70331872271 100644 --- a/pkg/golinters/embeddedcheck/embeddedcheck_integration_test.go +++ b/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go @@ -1,4 +1,4 @@ -package embeddedcheck +package embeddedstructfieldcheck import ( "testing" diff --git a/pkg/golinters/embeddedcheck/testdata/embeddedcheck_comments.go b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_comments.go similarity index 93% rename from pkg/golinters/embeddedcheck/testdata/embeddedcheck_comments.go rename to pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_comments.go index 24314e1b2981..12a6a4fa1ddf 100644 --- a/pkg/golinters/embeddedcheck/testdata/embeddedcheck_comments.go +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_comments.go @@ -1,4 +1,4 @@ -//golangcitest:args -Eembeddedcheck +//golangcitest:args -Eembeddedstructfieldcheck package simple import "time" diff --git a/pkg/golinters/embeddedcheck/testdata/embeddedcheck_simple.go b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_simple.go similarity index 72% rename from pkg/golinters/embeddedcheck/testdata/embeddedcheck_simple.go rename to pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_simple.go index 8f4e92fe42cc..47b155e5f52a 100644 --- a/pkg/golinters/embeddedcheck/testdata/embeddedcheck_simple.go +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_simple.go @@ -1,4 +1,4 @@ -//golangcitest:args -Eembeddedcheck +//golangcitest:args -Eembeddedstructfieldcheck package simple import ( @@ -20,7 +20,7 @@ type NoSpaceStruct struct { type NotSortedStruct struct { version int - time.Time // want `embedded types should be listed before non embedded types` + time.Time // want `embedded fields should be listed before regular fields` } type MixedEmbeddedAndNotEmbedded struct { @@ -28,7 +28,7 @@ type MixedEmbeddedAndNotEmbedded struct { name string - time.Time // want `embedded types should be listed before non embedded types` + time.Time // want `embedded fields should be listed before regular fields` age int } diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_special_cases.go b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_special_cases.go new file mode 100644 index 000000000000..95b5356b5824 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/embeddedstructfieldcheck_special_cases.go @@ -0,0 +1,11 @@ +//golangcitest:args -Eembeddedstructfieldcheck +package simple + +import "time" + +func myFunction() { + type myType struct { + version int + time.Time // want `embedded fields should be listed before regular fields` + } +} diff --git a/pkg/lint/lintersdb/builder_linter.go b/pkg/lint/lintersdb/builder_linter.go index df0efbb99542..c588f1193713 100644 --- a/pkg/lint/lintersdb/builder_linter.go +++ b/pkg/lint/lintersdb/builder_linter.go @@ -18,7 +18,7 @@ import ( "github.com/golangci/golangci-lint/v2/pkg/golinters/dupl" "github.com/golangci/golangci-lint/v2/pkg/golinters/dupword" "github.com/golangci/golangci-lint/v2/pkg/golinters/durationcheck" - "github.com/golangci/golangci-lint/v2/pkg/golinters/embeddedcheck" + "github.com/golangci/golangci-lint/v2/pkg/golinters/embeddedstructfieldcheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/err113" "github.com/golangci/golangci-lint/v2/pkg/golinters/errcheck" "github.com/golangci/golangci-lint/v2/pkg/golinters/errchkjson" @@ -206,9 +206,9 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) { WithLoadForGoAnalysis(). WithURL("https://github.com/charithe/durationcheck"), - linter.NewConfig(embeddedcheck.New()). + linter.NewConfig(embeddedstructfieldcheck.New()). WithSince("v2.2.0"). - WithURL("https://github.com/manuelarte/embeddedcheck"), + WithURL("https://github.com/manuelarte/embeddedstructfieldcheck"), linter.NewConfig(errcheck.New(&cfg.Linters.Settings.Errcheck)). WithGroups(config.GroupStandard). From dd128d68e9c662ed1d1c3a95c6ad26ecc11a90f3 Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Mon, 12 May 2025 15:37:39 +0200 Subject: [PATCH 09/12] fixing merge conflicts --- go.sum | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.sum b/go.sum index 5aec366fb13e..3705d8254cac 100644 --- a/go.sum +++ b/go.sum @@ -391,6 +391,8 @@ github.com/macabu/inamedparam v0.2.0 h1:VyPYpOc10nkhI2qeNUdh3Zket4fcZjEWe35poddB github.com/macabu/inamedparam v0.2.0/go.mod h1:+Pee9/YfGe5LJ62pYXqB89lJ+0k5bsR8Wgz/C0Zlq3U= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/manuelarte/embeddedstructfieldcheck v0.2.0 h1:GUV2A7XAOOj/XWlN1AdICai7YV6sSF8ZBODF58RSa9A= +github.com/manuelarte/embeddedstructfieldcheck v0.2.0/go.mod h1:LSo/IQpPfx1dXMcX4ibZCYA7Yy6ayZHIaOGM70+1Wy8= github.com/manuelarte/funcorder v0.5.0 h1:llMuHXXbg7tD0i/LNw8vGnkDTHFpTnWqKPI85Rknc+8= github.com/manuelarte/funcorder v0.5.0/go.mod h1:Yt3CiUQthSBMBxjShjdXMexmzpP8YGvGLjrxJNkO2hA= github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI= From dfcc1f8355ed0d9a03cf340989fe3653bcf20da9 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Mon, 12 May 2025 16:47:33 +0200 Subject: [PATCH 10/12] review: add JSONSchema --- jsonschema/golangci.next.jsonschema.json | 1 + 1 file changed, 1 insertion(+) diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 78960fabeaf1..9da8ac328072 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -734,6 +734,7 @@ "dupl", "dupword", "durationcheck", + "embeddedstructfieldcheck", "errcheck", "errchkjson", "errname", From 7904365aa31fdc4f253c45a44b597eab19612766 Mon Sep 17 00:00:00 2001 From: Manuel Doncel Martos Date: Tue, 13 May 2025 08:10:48 +0200 Subject: [PATCH 11/12] updating to v0.2.1 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 52a2f5704704..ca6b23a4880b 100644 --- a/go.mod +++ b/go.mod @@ -74,7 +74,7 @@ require ( github.com/ldez/usetesting v0.4.3 github.com/leonklingele/grouper v1.1.2 github.com/macabu/inamedparam v0.2.0 - github.com/manuelarte/embeddedstructfieldcheck v0.2.0 + github.com/manuelarte/embeddedstructfieldcheck v0.2.1 github.com/manuelarte/funcorder v0.5.0 github.com/maratori/testableexamples v1.0.0 github.com/maratori/testpackage v1.1.1 diff --git a/go.sum b/go.sum index 3705d8254cac..6c6f2bf9639b 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/macabu/inamedparam v0.2.0 h1:VyPYpOc10nkhI2qeNUdh3Zket4fcZjEWe35poddB github.com/macabu/inamedparam v0.2.0/go.mod h1:+Pee9/YfGe5LJ62pYXqB89lJ+0k5bsR8Wgz/C0Zlq3U= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= -github.com/manuelarte/embeddedstructfieldcheck v0.2.0 h1:GUV2A7XAOOj/XWlN1AdICai7YV6sSF8ZBODF58RSa9A= -github.com/manuelarte/embeddedstructfieldcheck v0.2.0/go.mod h1:LSo/IQpPfx1dXMcX4ibZCYA7Yy6ayZHIaOGM70+1Wy8= +github.com/manuelarte/embeddedstructfieldcheck v0.2.1 h1:oKexdVGs8Jy31IzOD/EMKfZmgogFhAaDbHb1o0qmA1Q= +github.com/manuelarte/embeddedstructfieldcheck v0.2.1/go.mod h1:LSo/IQpPfx1dXMcX4ibZCYA7Yy6ayZHIaOGM70+1Wy8= github.com/manuelarte/funcorder v0.5.0 h1:llMuHXXbg7tD0i/LNw8vGnkDTHFpTnWqKPI85Rknc+8= github.com/manuelarte/funcorder v0.5.0/go.mod h1:Yt3CiUQthSBMBxjShjdXMexmzpP8YGvGLjrxJNkO2hA= github.com/maratori/testableexamples v1.0.0 h1:dU5alXRrD8WKSjOUnmJZuzdxWOEQ57+7s93SLMxb2vI= From 609cc80ad4f904a68c02bac87ebea312c515cfff Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 13 May 2025 09:52:23 +0200 Subject: [PATCH 12/12] review: add fix tests --- ...beddedstructfieldcheck_integration_test.go | 8 ++++ .../testdata/fix/in/comments.go | 39 +++++++++++++++++++ .../testdata/fix/in/simple.go | 23 +++++++++++ .../testdata/fix/out/comments.go | 39 +++++++++++++++++++ .../testdata/fix/out/simple.go | 25 ++++++++++++ 5 files changed, 134 insertions(+) create mode 100644 pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/comments.go create mode 100644 pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/simple.go create mode 100644 pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/comments.go create mode 100644 pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/simple.go diff --git a/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go b/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go index a70331872271..ba4258467733 100644 --- a/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go +++ b/pkg/golinters/embeddedstructfieldcheck/embeddedstructfieldcheck_integration_test.go @@ -9,3 +9,11 @@ import ( func TestFromTestdata(t *testing.T) { integration.RunTestdata(t) } + +func TestFix(t *testing.T) { + integration.RunFix(t) +} + +func TestFixPathPrefix(t *testing.T) { + integration.RunFixPathPrefix(t) +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/comments.go b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/comments.go new file mode 100644 index 000000000000..5cd45dc171b7 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/comments.go @@ -0,0 +1,39 @@ +//golangcitest:args -Eembeddedstructfieldcheck +//golangcitest:expected_exitcode 0 +package testdata + +import "time" + +type ValidStructWithSingleLineComments struct { + // time.Time Single line comment + time.Time + + // version Single line comment + version int +} + +type StructWithSingleLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + + // version Single line comment + version int +} + +type StructWithMultiLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + + // version Single line comment + // very long comment + version int +} + +type A struct { + // comment + ValidStructWithSingleLineComments + // C is foo + StructWithSingleLineComments // want `there must be an empty line separating embedded fields from regular fields` + + D string +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/simple.go b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/simple.go new file mode 100644 index 000000000000..578ddc0d170e --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/in/simple.go @@ -0,0 +1,23 @@ +//golangcitest:args -Eembeddedstructfieldcheck +//golangcitest:expected_exitcode 0 +package testdata + +import ( + "time" +) + +type ValidStruct struct { + time.Time + + version int +} + +type NoSpaceStruct struct { + time.Time // want `there must be an empty line separating embedded fields from regular fields` + version int +} + +type EmbeddedWithPointers struct { + *time.Time // want `there must be an empty line separating embedded fields from regular fields` + version int +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/comments.go b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/comments.go new file mode 100644 index 000000000000..5cd45dc171b7 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/comments.go @@ -0,0 +1,39 @@ +//golangcitest:args -Eembeddedstructfieldcheck +//golangcitest:expected_exitcode 0 +package testdata + +import "time" + +type ValidStructWithSingleLineComments struct { + // time.Time Single line comment + time.Time + + // version Single line comment + version int +} + +type StructWithSingleLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + + // version Single line comment + version int +} + +type StructWithMultiLineComments struct { + // time.Time Single line comment + time.Time // want `there must be an empty line separating embedded fields from regular fields` + + // version Single line comment + // very long comment + version int +} + +type A struct { + // comment + ValidStructWithSingleLineComments + // C is foo + StructWithSingleLineComments // want `there must be an empty line separating embedded fields from regular fields` + + D string +} diff --git a/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/simple.go b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/simple.go new file mode 100644 index 000000000000..a35f19ff4a15 --- /dev/null +++ b/pkg/golinters/embeddedstructfieldcheck/testdata/fix/out/simple.go @@ -0,0 +1,25 @@ +//golangcitest:args -Eembeddedstructfieldcheck +//golangcitest:expected_exitcode 0 +package testdata + +import ( + "time" +) + +type ValidStruct struct { + time.Time + + version int +} + +type NoSpaceStruct struct { + time.Time // want `there must be an empty line separating embedded fields from regular fields` + + version int +} + +type EmbeddedWithPointers struct { + *time.Time // want `there must be an empty line separating embedded fields from regular fields` + + version int +}