Jelajahi Sumber

Fix nolint issues

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

Signed-off-by: Ulysses Souza <[email protected]>
Ulysses Souza 3 tahun lalu
induk
melakukan
fc723acb3b

+ 5 - 5
cmd/compose/build.go

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

+ 2 - 2
cmd/formatter/logs.go

@@ -89,14 +89,14 @@ func (l *logConsumer) Log(container, service, message string) {
 	}
 	p := l.getPresenter(container)
 	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) {
 	p := l.getPresenter(container)
 	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() {

+ 2 - 2
pkg/compose/attach.go

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

+ 4 - 4
pkg/compose/build_classic.go

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

+ 1 - 1
pkg/compose/logs.go

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

+ 2 - 2
pkg/compose/up.go

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

+ 1 - 1
pkg/e2e/compose_test.go

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

+ 2 - 2
pkg/e2e/framework.go

@@ -172,12 +172,12 @@ func CopyFile(t testing.TB, sourceFile string, destinationFile string) {
 
 	src, err := os.Open(sourceFile)
 	require.NoError(t, err, "Failed to open source file: %s")
-	// nolint: errcheck
+	//nolint: errcheck
 	defer src.Close()
 
 	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)
-	// nolint: errcheck
+	//nolint: errcheck
 	defer dst.Close()
 
 	_, err = io.Copy(dst, src)

+ 3 - 3
pkg/e2e/volumes_test.go

@@ -50,7 +50,7 @@ func TestLocalComposeVolume(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 }}")
 		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":"/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) {
 		res := c.RunDockerCmd(t, "inspect", "compose-e2e-volume-nginx-1", "--format", "{{ json .Mounts }}")
 		output := res.Stdout()
-		// nolint
+		//nolint
 		assert.Assert(t, strings.Contains(output, `"Type":"bind"`))
 		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) {
 		tmpDir, err := os.MkdirTemp("", projectName)
 		assert.NilError(t, err)
-		defer os.RemoveAll(tmpDir) // nolint
+		defer os.RemoveAll(tmpDir) //nolint
 
 		c.RunDockerComposeCmd(t, "--project-name", projectName, "down")
 

+ 2 - 2
pkg/progress/tty.go

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

+ 7 - 7
pkg/utils/writer_test.go

@@ -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!"})
 
 }