From 4c33b8f170d3b54807dbc10ffab329036f0cca14 Mon Sep 17 00:00:00 2001 From: Milas Bowman Date: Mon, 11 Sep 2023 09:37:03 -0400 Subject: [PATCH] ci: tweak restricted imports in linter Signed-off-by: Milas Bowman --- .golangci.yml | 6 ++++-- go.mod | 2 +- pkg/compose/compose.go | 9 +++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 03c1a22b875..b32b091f716 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,9 +36,13 @@ linters-settings: deny: - pkg: io/ioutil desc: 'io/ioutil package has been deprecated' + - pkg: gopkg.in/yaml.v2 + desc: 'compose-go uses yaml.v3' gomodguard: blocked: versions: + - github.com/distribution/distribution: + reason: "use distribution/reference" - gotest.tools: version: "< 3.0.0" reason: "deprecated, pre-modules version" @@ -61,5 +65,3 @@ issues: # golangci hides some golint warnings (the warning about exported things # withtout documentation for example), this will make it show them anyway. exclude-use-default: false - exclude: - - should not use dot imports diff --git a/go.mod b/go.mod index 55de039a51a..453afc58925 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,6 @@ require ( go.uber.org/goleak v1.2.1 golang.org/x/sync v0.3.0 google.golang.org/grpc v1.57.0 - gopkg.in/yaml.v2 v2.4.0 gotest.tools/v3 v3.5.0 ) @@ -172,6 +171,7 @@ require ( google.golang.org/protobuf v1.30.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.26.2 // indirect k8s.io/apimachinery v0.26.2 // indirect diff --git a/pkg/compose/compose.go b/pkg/compose/compose.go index b8a98ddf393..688a48454b9 100644 --- a/pkg/compose/compose.go +++ b/pkg/compose/compose.go @@ -18,7 +18,6 @@ package compose import ( "context" - "encoding/json" "fmt" "io" "os" @@ -36,15 +35,13 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/cli/flags" "github.com/docker/cli/cli/streams" + "github.com/docker/compose/v2/pkg/api" moby "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/opencontainers/go-digest" "github.com/pkg/errors" - "gopkg.in/yaml.v2" - - "github.com/docker/compose/v2/pkg/api" ) var stdioToStdout bool @@ -169,9 +166,9 @@ func (s *composeService) Config(ctx context.Context, project *types.Project, opt switch options.Format { case "json": - return json.MarshalIndent(project, "", " ") + return project.MarshalJSON() case "yaml": - return yaml.Marshal(project) + return project.MarshalYAML() default: return nil, fmt.Errorf("unsupported format %q", options.Format) }