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

@ -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
}