Skip to content

Commit 19bbb12

Browse files
authored
ci: tweak restricted imports in linter (docker#10992)
* Eliminate direct dependency on gopkg.in/yaml.v2 * Add gopkg.in/yaml.v2 as a restricted import * Add github.com/distribution/distribution as a restricted dependency in favor of distribution/reference which is the subset of functionality that Compose needs * Remove an unused exclusion NOTE: This does change the `compose config` output slightly but does NOT change the semantics: * YAML indentation is slightly different for lists (this is a `v2` / `v3` thing) * JSON is now "minified" instead of pretty-printed (I think this generally desirable and more consistent with other JSON command outputs) Signed-off-by: Milas Bowman <[email protected]>
1 parent 7a13457 commit 19bbb12

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

.golangci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ linters-settings:
3636
deny:
3737
- pkg: io/ioutil
3838
desc: 'io/ioutil package has been deprecated'
39+
- pkg: gopkg.in/yaml.v2
40+
desc: 'compose-go uses yaml.v3'
3941
gomodguard:
4042
blocked:
4143
versions:
44+
- github.com/distribution/distribution:
45+
reason: "use distribution/reference"
4246
- gotest.tools:
4347
version: "< 3.0.0"
4448
reason: "deprecated, pre-modules version"
@@ -61,5 +65,3 @@ issues:
6165
# golangci hides some golint warnings (the warning about exported things
6266
# withtout documentation for example), this will make it show them anyway.
6367
exclude-use-default: false
64-
exclude:
65-
- should not use dot imports

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ require (
4848
go.uber.org/goleak v1.2.1
4949
golang.org/x/sync v0.3.0
5050
google.golang.org/grpc v1.58.0
51-
gopkg.in/yaml.v2 v2.4.0
5251
gotest.tools/v3 v3.5.0
5352
)
5453

@@ -172,6 +171,7 @@ require (
172171
google.golang.org/protobuf v1.31.0 // indirect
173172
gopkg.in/inf.v0 v0.9.1 // indirect
174173
gopkg.in/ini.v1 v1.67.0 // indirect
174+
gopkg.in/yaml.v2 v2.4.0 // indirect
175175
gopkg.in/yaml.v3 v3.0.1 // indirect
176176
k8s.io/api v0.26.2 // indirect
177177
k8s.io/apimachinery v0.26.2 // indirect

pkg/compose/compose.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package compose
1818

1919
import (
2020
"context"
21-
"encoding/json"
2221
"fmt"
2322
"io"
2423
"os"
@@ -36,15 +35,13 @@ import (
3635
"github.com/docker/cli/cli/config/configfile"
3736
"github.com/docker/cli/cli/flags"
3837
"github.com/docker/cli/cli/streams"
38+
"github.com/docker/compose/v2/pkg/api"
3939
moby "github.com/docker/docker/api/types"
4040
"github.com/docker/docker/api/types/filters"
4141
"github.com/docker/docker/api/types/swarm"
4242
"github.com/docker/docker/client"
4343
"github.com/opencontainers/go-digest"
4444
"github.com/pkg/errors"
45-
"gopkg.in/yaml.v2"
46-
47-
"github.com/docker/compose/v2/pkg/api"
4845
)
4946

5047
var stdioToStdout bool
@@ -169,9 +166,9 @@ func (s *composeService) Config(ctx context.Context, project *types.Project, opt
169166

170167
switch options.Format {
171168
case "json":
172-
return json.MarshalIndent(project, "", " ")
169+
return project.MarshalJSON()
173170
case "yaml":
174-
return yaml.Marshal(project)
171+
return project.MarshalYAML()
175172
default:
176173
return nil, fmt.Errorf("unsupported format %q", options.Format)
177174
}

0 commit comments

Comments
 (0)