From 30fd5cdbd945914b31cdd3a50980249e268e977f Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Mon, 11 Sep 2023 10:46:40 +0200 Subject: [PATCH] ci(lint): enable gocritic linter (#1605) Signed-off-by: Matthieu MOREL --- .golangci.yml | 1 + from_dockerfile_test.go | 7 +++---- modulegen/internal/context/types.go | 8 +++----- modulegen/internal/mkdocs/main.go | 10 +++++----- modulegen/internal/module/main.go | 10 +++++----- modules/k3s/k3s.go | 3 +-- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 8c02d880c6..0e29a3dced 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,6 +1,7 @@ linters: enable: - gci + - gocritic - gofumpt - misspell diff --git a/from_dockerfile_test.go b/from_dockerfile_test.go index 833ff451cd..11b143e49e 100644 --- a/from_dockerfile_test.go +++ b/from_dockerfile_test.go @@ -2,7 +2,6 @@ package testcontainers import ( "context" - "path/filepath" "strings" "testing" @@ -24,7 +23,7 @@ func TestBuildImageFromDockerfile(t *testing.T) { tag, err := provider.BuildImage(ctx, &ContainerRequest{ // fromDockerfileIncludingRepo { FromDockerfile: FromDockerfile{ - Context: filepath.Join("testdata"), + Context: "testdata", Dockerfile: "echo.Dockerfile", Repo: "test-repo", Tag: "test-tag", @@ -61,7 +60,7 @@ func TestBuildImageFromDockerfile_NoRepo(t *testing.T) { tag, err := provider.BuildImage(ctx, &ContainerRequest{ FromDockerfile: FromDockerfile{ - Context: filepath.Join("testdata"), + Context: "testdata", Dockerfile: "echo.Dockerfile", Repo: "test-repo", }, @@ -96,7 +95,7 @@ func TestBuildImageFromDockerfile_NoTag(t *testing.T) { tag, err := provider.BuildImage(ctx, &ContainerRequest{ FromDockerfile: FromDockerfile{ - Context: filepath.Join("testdata"), + Context: "testdata", Dockerfile: "echo.Dockerfile", Tag: "test-tag", }, diff --git a/modulegen/internal/context/types.go b/modulegen/internal/context/types.go index b2c4a50fb9..6264579ed2 100644 --- a/modulegen/internal/context/types.go +++ b/modulegen/internal/context/types.go @@ -26,11 +26,9 @@ func (m *TestcontainersModule) ContainerName() string { if m.IsModule { name = m.Title() - } else { - if m.TitleName != "" { - r, n := utf8.DecodeRuneInString(m.TitleName) - name = string(unicode.ToLower(r)) + m.TitleName[n:] - } + } else if m.TitleName != "" { + r, n := utf8.DecodeRuneInString(m.TitleName) + name = string(unicode.ToLower(r)) + m.TitleName[n:] } return name + "Container" diff --git a/modulegen/internal/mkdocs/main.go b/modulegen/internal/mkdocs/main.go index 92b7843d7e..9a1c4d04c6 100644 --- a/modulegen/internal/mkdocs/main.go +++ b/modulegen/internal/mkdocs/main.go @@ -13,11 +13,11 @@ type Generator struct{} func (g Generator) AddModule(ctx context.Context, tcModule context.TestcontainersModule) error { moduleMdFile := filepath.Join(ctx.DocsDir(), tcModule.ParentDir(), tcModule.Lower()+".md") funcMap := template.FuncMap{ - "Entrypoint": func() string { return tcModule.Entrypoint() }, - "ContainerName": func() string { return tcModule.ContainerName() }, - "ParentDir": func() string { return tcModule.ParentDir() }, - "ToLower": func() string { return tcModule.Lower() }, - "Title": func() string { return tcModule.Title() }, + "Entrypoint": tcModule.Entrypoint, + "ContainerName": tcModule.ContainerName, + "ParentDir": tcModule.ParentDir, + "ToLower": tcModule.Lower, + "Title": tcModule.Title, } err := GenerateMdFile(moduleMdFile, funcMap, tcModule) if err != nil { diff --git a/modulegen/internal/module/main.go b/modulegen/internal/module/main.go index 924332e514..a38f258c2b 100644 --- a/modulegen/internal/module/main.go +++ b/modulegen/internal/module/main.go @@ -26,11 +26,11 @@ func (g Generator) AddModule(ctx context.Context, tcModule context.Testcontainer func generateGoFiles(moduleDir string, tcModule context.TestcontainersModule) error { funcMap := template.FuncMap{ - "Entrypoint": func() string { return tcModule.Entrypoint() }, - "ContainerName": func() string { return tcModule.ContainerName() }, - "ParentDir": func() string { return tcModule.ParentDir() }, - "ToLower": func() string { return tcModule.Lower() }, - "Title": func() string { return tcModule.Title() }, + "Entrypoint": tcModule.Entrypoint, + "ContainerName": tcModule.ContainerName, + "ParentDir": tcModule.ParentDir, + "ToLower": tcModule.Lower, + "Title": tcModule.Title, } return GenerateFiles(moduleDir, tcModule.Lower(), funcMap, tcModule) } diff --git a/modules/k3s/k3s.go b/modules/k3s/k3s.go index fa8c43bb0a..ad8fa2866c 100644 --- a/modules/k3s/k3s.go +++ b/modules/k3s/k3s.go @@ -93,8 +93,7 @@ func getContainerHost(ctx context.Context, opts ...testcontainers.ContainerCusto return "", err } - switch p := p.(type) { - case *testcontainers.DockerProvider: + if p, ok := p.(*testcontainers.DockerProvider); ok { return p.DaemonHost(ctx) }