Fix nolint issues

Reference -> https://golangci-lint.run/usage/false-positives/#nolint-directive

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2022-07-13 19:20:40 +02:00
parent 96cbb1cbcf
commit fc723acb3b
11 changed files with 31 additions and 31 deletions

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().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().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().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().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().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().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().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().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 return cmd
} }

View File

@ -89,14 +89,14 @@ func (l *logConsumer) Log(container, service, message string) {
} }
p := l.getPresenter(container) p := l.getPresenter(container)
for _, line := range strings.Split(message, "\n") { for _, line := range strings.Split(message, "\n") {
fmt.Fprintf(l.writer, "%s%s\n", p.prefix, line) // nolint:errcheck fmt.Fprintf(l.writer, "%s%s\n", p.prefix, line) //nolint:errcheck
} }
} }
func (l *logConsumer) Status(container, msg string) { func (l *logConsumer) Status(container, msg string) {
p := l.getPresenter(container) p := l.getPresenter(container)
s := p.colors(fmt.Sprintf("%s %s\n", container, msg)) s := p.colors(fmt.Sprintf("%s %s\n", container, msg))
l.writer.Write([]byte(s)) // nolint:errcheck l.writer.Write([]byte(s)) //nolint:errcheck
} }
func (l *logConsumer) computeWidth() { func (l *logConsumer) computeWidth() {

View File

@ -127,9 +127,9 @@ func (s *composeService) attachContainerStreams(ctx context.Context, container s
if stdout != nil { if stdout != nil {
go func() { go func() {
if tty { if tty {
io.Copy(stdout, streamOut) // nolint:errcheck io.Copy(stdout, streamOut) //nolint:errcheck
} else { } else {
stdcopy.StdCopy(stdout, stderr, streamOut) // nolint:errcheck stdcopy.StdCopy(stdout, stderr, streamOut) //nolint:errcheck
} }
}() }()
} }

View File

@ -64,7 +64,7 @@ func (s *composeService) doBuildClassic(ctx context.Context, project *types.Proj
return nameDigests, errs return nameDigests, errs
} }
// nolint: gocyclo //nolint: gocyclo
func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options buildx.Options) (string, error) { func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options buildx.Options) (string, error) {
var ( var (
buildCtx io.ReadCloser buildCtx io.ReadCloser
@ -96,7 +96,7 @@ func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options
if err != nil { if err != nil {
return "", errors.Errorf("unable to open Dockerfile: %v", err) return "", errors.Errorf("unable to open Dockerfile: %v", err)
} }
defer dockerfileCtx.Close() // nolint:errcheck defer dockerfileCtx.Close() //nolint:errcheck
} }
case urlutil.IsGitURL(specifiedContext): case urlutil.IsGitURL(specifiedContext):
tempDir, relDockerfile, err = build.GetContextFromGitURL(specifiedContext, dockerfileName) tempDir, relDockerfile, err = build.GetContextFromGitURL(specifiedContext, dockerfileName)
@ -111,7 +111,7 @@ func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options
} }
if tempDir != "" { if tempDir != "" {
defer os.RemoveAll(tempDir) // nolint:errcheck defer os.RemoveAll(tempDir) //nolint:errcheck
contextDir = tempDir contextDir = tempDir
} }
@ -175,7 +175,7 @@ func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options
if err != nil { if err != nil {
return "", err return "", err
} }
defer response.Body.Close() // nolint:errcheck defer response.Body.Close() //nolint:errcheck
imageID := "" imageID := ""
aux := func(msg jsonmessage.JSONMessage) { aux := func(msg jsonmessage.JSONMessage) {

View File

@ -95,7 +95,7 @@ func (s *composeService) logContainers(ctx context.Context, consumer api.LogCons
if err != nil { if err != nil {
return err return err
} }
defer r.Close() // nolint errcheck defer r.Close() //nolint errcheck
name := getContainerNameWithoutProject(c) name := getContainerNameWithoutProject(c)
w := utils.GetWriter(func(line string) { w := utils.GetWriter(func(line string) {

View File

@ -60,7 +60,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
return progress.Run(ctx, func(ctx context.Context) error { return progress.Run(ctx, func(ctx context.Context) error {
go func() { go func() {
<-signalChan <-signalChan
s.Kill(ctx, project.Name, api.KillOptions{ // nolint:errcheck s.Kill(ctx, project.Name, api.KillOptions{ //nolint:errcheck
Services: project.ServiceNames(), Services: project.ServiceNames(),
}) })
}() }()
@ -74,7 +74,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
<-signalChan <-signalChan
printer.Cancel() printer.Cancel()
fmt.Println("Gracefully stopping... (press Ctrl+C again to force)") fmt.Println("Gracefully stopping... (press Ctrl+C again to force)")
stopFunc() // nolint:errcheck stopFunc() //nolint:errcheck
}() }()
var exitCode int var exitCode int

View File

@ -134,7 +134,7 @@ func TestDownComposefileInParentFolder(t *testing.T) {
tmpFolder, err := os.MkdirTemp("fixtures/simple-composefile", "test-tmp") tmpFolder, err := os.MkdirTemp("fixtures/simple-composefile", "test-tmp")
assert.NilError(t, err) assert.NilError(t, err)
defer os.Remove(tmpFolder) // nolint: errcheck defer os.Remove(tmpFolder) //nolint: errcheck
projectName := filepath.Base(tmpFolder) projectName := filepath.Base(tmpFolder)
res := c.RunDockerComposeCmd(t, "--project-directory", tmpFolder, "up", "-d") res := c.RunDockerComposeCmd(t, "--project-directory", tmpFolder, "up", "-d")

View File

@ -172,12 +172,12 @@ func CopyFile(t testing.TB, sourceFile string, destinationFile string) {
src, err := os.Open(sourceFile) src, err := os.Open(sourceFile)
require.NoError(t, err, "Failed to open source file: %s") require.NoError(t, err, "Failed to open source file: %s")
// nolint: errcheck //nolint: errcheck
defer src.Close() defer src.Close()
dst, err := os.OpenFile(destinationFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o755) dst, err := os.OpenFile(destinationFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o755)
require.NoError(t, err, "Failed to open destination file: %s", destinationFile) require.NoError(t, err, "Failed to open destination file: %s", destinationFile)
// nolint: errcheck //nolint: errcheck
defer dst.Close() defer dst.Close()
_, err = io.Copy(dst, src) _, err = io.Copy(dst, src)

View File

@ -50,7 +50,7 @@ func TestLocalComposeVolume(t *testing.T) {
t.Run("check container volume specs", func(t *testing.T) { t.Run("check container volume specs", func(t *testing.T) {
res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx2-1", "--format", "{{ json .Mounts }}") res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx2-1", "--format", "{{ json .Mounts }}")
output := res.Stdout() output := res.Stdout()
// nolint //nolint
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/src/app/node_modules","Driver":"local","Mode":"z","RW":true,"Propagation":""`), output) assert.Assert(t, strings.Contains(output, `"Destination":"/usr/src/app/node_modules","Driver":"local","Mode":"z","RW":true,"Propagation":""`), output)
assert.Assert(t, strings.Contains(output, `"Destination":"/myconfig","Mode":"","RW":false,"Propagation":"rprivate"`), output) assert.Assert(t, strings.Contains(output, `"Destination":"/myconfig","Mode":"","RW":false,"Propagation":"rprivate"`), output)
}) })
@ -68,7 +68,7 @@ func TestLocalComposeVolume(t *testing.T) {
t.Run("check container bind-mounts specs", func(t *testing.T) { t.Run("check container bind-mounts specs", func(t *testing.T) {
res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx-1", "--format", "{{ json .Mounts }}") res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx-1", "--format", "{{ json .Mounts }}")
output := res.Stdout() output := res.Stdout()
// nolint //nolint
assert.Assert(t, strings.Contains(output, `"Type":"bind"`)) assert.Assert(t, strings.Contains(output, `"Type":"bind"`))
assert.Assert(t, strings.Contains(output, `"Destination":"/usr/share/nginx/html"`)) assert.Assert(t, strings.Contains(output, `"Destination":"/usr/share/nginx/html"`))
}) })
@ -103,7 +103,7 @@ func TestProjectVolumeBind(t *testing.T) {
t.Run("up on project volume with bind specification", func(t *testing.T) { t.Run("up on project volume with bind specification", func(t *testing.T) {
tmpDir, err := os.MkdirTemp("", projectName) tmpDir, err := os.MkdirTemp("", projectName)
assert.NilError(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) // nolint defer os.RemoveAll(tmpDir) //nolint
c.RunDockerComposeCmd(t, "--project-name", projectName, "down") c.RunDockerComposeCmd(t, "--project-name", projectName, "down")

View File

@ -164,14 +164,14 @@ func (w *ttyWriter) print() {
continue continue
} }
line := lineText(event, "", terminalWidth, statusPadding, runtime.GOOS != "windows") line := lineText(event, "", terminalWidth, statusPadding, runtime.GOOS != "windows")
// nolint: errcheck //nolint: errcheck
fmt.Fprint(w.out, line) fmt.Fprint(w.out, line)
numLines++ numLines++
for _, v := range w.eventIDs { for _, v := range w.eventIDs {
ev := w.events[v] ev := w.events[v]
if ev.ParentID == event.ID { if ev.ParentID == event.ID {
line := lineText(ev, " ", terminalWidth, statusPadding, runtime.GOOS != "windows") line := lineText(ev, " ", terminalWidth, statusPadding, runtime.GOOS != "windows")
// nolint: errcheck //nolint: errcheck
fmt.Fprint(w.out, line) fmt.Fprint(w.out, line)
numLines++ numLines++
} }

View File

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