Add "style" tag to gocritic

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2022-07-13 03:10:48 +02:00
parent d42adf6efb
commit 96cbb1cbcf
8 changed files with 36 additions and 35 deletions

View File

@ -39,9 +39,11 @@ linters-settings:
enabled-tags:
- diagnostic
- opinionated
- style
disabled-checks:
- paramTypeCombine
- unnamedResult
- whyNoLint
gocyclo:
min-complexity: 16
lll:

View File

@ -110,16 +110,16 @@ func buildCommand(p *projectOptions, backend api.Service) *cobra.Command {
cmd.Flags().StringArrayVar(&opts.args, "build-arg", []string{}, "Set build-time variables for services.")
cmd.Flags().StringVar(&opts.ssh, "ssh", "", "Set SSH authentications used when building service images. (use 'default' for using your default SSH Agent)")
cmd.Flags().Bool("parallel", true, "Build images in parallel. DEPRECATED")
cmd.Flags().MarkHidden("parallel") //nolint:errcheck
cmd.Flags().MarkHidden("parallel") // nolint:errcheck
cmd.Flags().Bool("compress", true, "Compress the build context using gzip. DEPRECATED")
cmd.Flags().MarkHidden("compress") //nolint:errcheck
cmd.Flags().MarkHidden("compress") // nolint:errcheck
cmd.Flags().Bool("force-rm", true, "Always remove intermediate containers. DEPRECATED")
cmd.Flags().MarkHidden("force-rm") //nolint:errcheck
cmd.Flags().MarkHidden("force-rm") // nolint:errcheck
cmd.Flags().BoolVar(&opts.noCache, "no-cache", false, "Do not use cache when building the image")
cmd.Flags().Bool("no-rm", false, "Do not remove intermediate containers after a successful build. DEPRECATED")
cmd.Flags().MarkHidden("no-rm") //nolint:errcheck
cmd.Flags().MarkHidden("no-rm") // nolint:errcheck
cmd.Flags().StringVarP(&opts.memory, "memory", "m", "", "Set memory limit for the build container. Not supported on buildkit yet.")
cmd.Flags().MarkHidden("memory") //nolint:errcheck
cmd.Flags().MarkHidden("memory") // nolint:errcheck
return cmd
}

View File

@ -27,6 +27,16 @@ import (
"github.com/docker/compose/v2/pkg/api"
)
// LogConsumer consume logs from services and format them
type logConsumer struct {
ctx context.Context
presenters sync.Map // map[string]*presenter
width int
writer io.Writer
color bool
prefix bool
}
// NewLogConsumer creates a new LogConsumer
func NewLogConsumer(ctx context.Context, w io.Writer, color bool, prefix bool) api.LogConsumer {
return &logConsumer{
@ -101,16 +111,6 @@ func (l *logConsumer) computeWidth() {
l.width = width + 1
}
// LogConsumer consume logs from services and format them
type logConsumer struct {
ctx context.Context
presenters sync.Map // map[string]*presenter
width int
writer io.Writer
color bool
prefix bool
}
type presenter struct {
colors colorFunc
name string

View File

@ -553,7 +553,7 @@ func (s composeService) getLinks(ctx context.Context, projectName string, servic
containerName := getCanonicalContainerName(c)
links = append(links,
format(containerName, linkName),
format(containerName, strings.Join([]string{linkServiceName, strconv.Itoa(number)}, Separator)),
format(containerName, linkServiceName+Separator+strconv.Itoa(number)),
format(containerName, strings.Join([]string{projectName, linkServiceName, strconv.Itoa(number)}, Separator)),
)
}

View File

@ -263,7 +263,7 @@ func (s *composeService) copyFromContainer(ctx context.Context, containerID, src
}
preArchive := content
if len(srcInfo.RebaseName) != 0 {
if srcInfo.RebaseName != "" {
_, srcBase := archive.SplitPathDirEntry(srcInfo.Path)
preArchive = archive.RebaseArchiveEntries(content, srcBase, srcInfo.RebaseName)
}

View File

@ -22,7 +22,6 @@ import (
"sort"
"testing"
"github.com/compose-spec/compose-go/types"
composetypes "github.com/compose-spec/compose-go/types"
"github.com/docker/compose/v2/pkg/api"
moby "github.com/docker/docker/api/types"
@ -66,17 +65,17 @@ func TestBuildVolumeMount(t *testing.T) {
}
func TestServiceImageName(t *testing.T) {
assert.Equal(t, getImageName(types.ServiceConfig{Image: "myImage"}, "myProject"), "myImage")
assert.Equal(t, getImageName(types.ServiceConfig{Name: "aService"}, "myProject"), "myProject_aService")
assert.Equal(t, getImageName(composetypes.ServiceConfig{Image: "myImage"}, "myProject"), "myImage")
assert.Equal(t, getImageName(composetypes.ServiceConfig{Name: "aService"}, "myProject"), "myProject_aService")
}
func TestPrepareNetworkLabels(t *testing.T) {
project := types.Project{
project := composetypes.Project{
Name: "myProject",
Networks: types.Networks(map[string]types.NetworkConfig{"skynet": {}}),
Networks: composetypes.Networks(map[string]composetypes.NetworkConfig{"skynet": {}}),
}
prepareNetworks(&project)
assert.DeepEqual(t, project.Networks["skynet"].Labels, types.Labels(map[string]string{
assert.DeepEqual(t, project.Networks["skynet"].Labels, composetypes.Labels(map[string]string{
"com.docker.compose.network": "skynet",
"com.docker.compose.project": "myProject",
"com.docker.compose.version": api.ComposeVersion,

View File

@ -32,6 +32,11 @@ type logPrinter interface {
Cancel()
}
type printer struct {
queue chan api.ContainerEvent
consumer api.LogConsumer
}
// newLogPrinter builds a LogPrinter passing containers logs to LogConsumer
func newLogPrinter(consumer api.LogConsumer) logPrinter {
queue := make(chan api.ContainerEvent)
@ -48,11 +53,6 @@ func (p *printer) Cancel() {
}
}
type printer struct {
queue chan api.ContainerEvent
consumer api.LogConsumer
}
func (p *printer) HandleEvent(event api.ContainerEvent) {
p.queue <- event
}

View File

@ -27,13 +27,13 @@ func TestSplitWriter(t *testing.T) {
w := GetWriter(func(line string) {
lines = append(lines, line)
})
w.Write([]byte("h")) //nolint: errcheck
w.Write([]byte("e")) //nolint: errcheck
w.Write([]byte("l")) //nolint: errcheck
w.Write([]byte("l")) //nolint: errcheck
w.Write([]byte("o")) //nolint: errcheck
w.Write([]byte("\n")) //nolint: errcheck
w.Write([]byte("world!\n")) //nolint: errcheck
w.Write([]byte("h")) // nolint: errcheck
w.Write([]byte("e")) // nolint: errcheck
w.Write([]byte("l")) // nolint: errcheck
w.Write([]byte("l")) // nolint: errcheck
w.Write([]byte("o")) // nolint: errcheck
w.Write([]byte("\n")) // nolint: errcheck
w.Write([]byte("world!\n")) // nolint: errcheck
assert.DeepEqual(t, lines, []string{"hello", "world!"})
}