Add "opinionated" tag to gocritic

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2022-07-13 02:53:08 +02:00
parent a81f23a199
commit d42adf6efb
10 changed files with 77 additions and 70 deletions

View file

@ -61,29 +61,30 @@ func (s *composeService) build(ctx context.Context, project *types.Project, opti
}
for _, service := range services {
if service.Build != nil {
imageName := getImageName(service, project.Name)
imagesToBuild = append(imagesToBuild, imageName)
buildOptions, err := s.toBuildOptions(project, service, imageName, options.SSHs)
if err != nil {
return err
}
buildOptions.Pull = options.Pull
buildOptions.BuildArgs = mergeArgs(buildOptions.BuildArgs, args)
buildOptions.NoCache = options.NoCache
buildOptions.CacheFrom, err = buildflags.ParseCacheEntry(service.Build.CacheFrom)
if err != nil {
return err
}
for _, image := range service.Build.CacheFrom {
buildOptions.CacheFrom = append(buildOptions.CacheFrom, bclient.CacheOptionsEntry{
Type: "registry",
Attrs: map[string]string{"ref": image},
})
}
opts[imageName] = buildOptions
if service.Build == nil {
continue
}
imageName := getImageName(service, project.Name)
imagesToBuild = append(imagesToBuild, imageName)
buildOptions, err := s.toBuildOptions(project, service, imageName, options.SSHs)
if err != nil {
return err
}
buildOptions.Pull = options.Pull
buildOptions.BuildArgs = mergeArgs(buildOptions.BuildArgs, args)
buildOptions.NoCache = options.NoCache
buildOptions.CacheFrom, err = buildflags.ParseCacheEntry(service.Build.CacheFrom)
if err != nil {
return err
}
for _, image := range service.Build.CacheFrom {
buildOptions.CacheFrom = append(buildOptions.CacheFrom, bclient.CacheOptionsEntry{
Type: "registry",
Attrs: map[string]string{"ref": image},
})
}
opts[imageName] = buildOptions
}
_, err = s.doBuild(ctx, project, opts, options.Progress)
@ -312,11 +313,11 @@ func mergeArgs(m ...types.Mapping) types.Mapping {
return merged
}
func dockerFilePath(context string, dockerfile string) string {
if urlutil.IsGitURL(context) || filepath.IsAbs(dockerfile) {
func dockerFilePath(ctxName string, dockerfile string) string {
if urlutil.IsGitURL(ctxName) || filepath.IsAbs(dockerfile) {
return dockerfile
}
return filepath.Join(context, dockerfile)
return filepath.Join(ctxName, dockerfile)
}
func sshAgentProvider(sshKeys types.SSHConfig) (session.Attachable, error) {

View file

@ -214,7 +214,7 @@ func (s *composeService) doBuildClassicSimpleImage(ctx context.Context, options
if imageID == "" {
return "", errors.Errorf("Server did not provide an image ID. Cannot write %s", options.ImageIDFile)
}
if err := os.WriteFile(options.ImageIDFile, []byte(imageID), 0666); err != nil {
if err := os.WriteFile(options.ImageIDFile, []byte(imageID), 0o666); err != nil {
return "", err
}
}

View file

@ -893,7 +893,7 @@ func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount
continue
}
mount, err := buildMount(p, types.ServiceVolumeConfig{
mnt, err := buildMount(p, types.ServiceVolumeConfig{
Type: types.VolumeTypeBind,
Source: definedSecret.File,
Target: target,
@ -902,7 +902,7 @@ func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount
if err != nil {
return nil, err
}
mounts[target] = mount
mounts[target] = mnt
}
values := make([]mount.Mount, 0, len(mounts))
for _, v := range mounts {
@ -911,8 +911,8 @@ func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount
return values, nil
}
func isUnixAbs(path string) bool {
return strings.HasPrefix(path, "/")
func isUnixAbs(p string) bool {
return strings.HasPrefix(p, "/")
}
func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.Mount, error) {

View file

@ -57,7 +57,7 @@ func createTar(env string, config types.ServiceSecretConfig) (bytes.Buffer, erro
value := []byte(env)
b := bytes.Buffer{}
tarWriter := tar.NewWriter(&b)
mode := uint32(0400)
mode := uint32(0o400)
if config.Mode != nil {
mode = *config.Mode
}

View file

@ -127,7 +127,7 @@ func initializePlugins(t testing.TB, configDir string) {
}
})
require.NoError(t, os.MkdirAll(filepath.Join(configDir, "cli-plugins"), 0755),
require.NoError(t, os.MkdirAll(filepath.Join(configDir, "cli-plugins"), 0o755),
"Failed to create cli-plugins directory")
composePlugin, err := findExecutable(DockerComposeExecutableName, []string{"../../bin", "../../../bin"})
if os.IsNotExist(err) {
@ -175,7 +175,7 @@ func CopyFile(t testing.TB, sourceFile string, destinationFile string) {
// nolint: errcheck
defer src.Close()
dst, err := os.OpenFile(destinationFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
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
defer dst.Close()

View file

@ -71,9 +71,9 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
})
t.Run("do not display if scan already invoked", func(t *testing.T) {
_ = os.MkdirAll(filepath.Join(c.ConfigDir, "scan"), 0755)
_ = os.MkdirAll(filepath.Join(c.ConfigDir, "scan"), 0o755)
scanConfigFile := filepath.Join(c.ConfigDir, "scan", "config.json")
err := os.WriteFile(scanConfigFile, []byte(`{"optin":true}`), 0644)
err := os.WriteFile(scanConfigFile, []byte(`{"optin":true}`), 0o644)
assert.NilError(t, err)
res := c.RunDockerCmd(t, "build", "-t", "test-image-scan-msg", "fixtures/simple-build-test/nginx-build")