Fix other linters on modified lines

This commit is contained in:
Katrina Verey
2022-08-10 18:50:28 -04:00
parent f6b72077c8
commit 55a37de686
10 changed files with 19 additions and 11 deletions

View File

@@ -102,6 +102,9 @@ linters-settings:
arguments:
- [ "ID", "API", "JSON" ] # AllowList
- [ ] # DenyList
gomnd:
ignored-functions:
- os.WriteFile
gomoddirectives:
replace-local: true
gosec:

View File

@@ -210,7 +210,7 @@ func (p *HelmChartInflationGeneratorPlugin) writeValuesBytes(
return "", fmt.Errorf("cannot create tmp dir to write helm values")
}
path := filepath.Join(p.tmpDir, p.Name+"-kustomize-values.yaml")
return path, os.WriteFile(path, b, 0644)
return path, errors.Wrap(os.WriteFile(path, b, 0644), "failed to write values file")
}
func (p *HelmChartInflationGeneratorPlugin) cleanup() {

View File

@@ -55,8 +55,9 @@ func (r *InitRunner) runE(c *cobra.Command, args []string) error {
return errors.Errorf("directory already initialized with a Krmfile")
}
return os.WriteFile(filename, []byte(strings.TrimSpace(`
err := os.WriteFile(filename, []byte(strings.TrimSpace(`
apiVersion: config.k8s.io/v1alpha1
kind: Krmfile
`)), 0600)
return errors.Wrap(err)
}

View File

@@ -125,7 +125,10 @@ func (fsOnDisk) ReadDir(name string) ([]string, error) {
}
// ReadFile delegates to os.ReadFile.
func (fsOnDisk) ReadFile(name string) ([]byte, error) { return os.ReadFile(name) }
func (fsOnDisk) ReadFile(name string) ([]byte, error) {
//nolint:wrapcheck
return os.ReadFile(name)
}
// WriteFile delegates to os.WriteFile with read/write permissions.
func (fsOnDisk) WriteFile(name string, c []byte) error {

View File

@@ -100,5 +100,6 @@ func (l parser) readFile(path string) ([]byte, error) {
}
defer f.Close()
return io.ReadAll(f)
content, err := io.ReadAll(f)
return content, errors.Wrap(err)
}

View File

@@ -281,7 +281,7 @@ func TestAdd_Filter2(t *testing.T) {
path := filepath.Join(os.TempDir(), "resourcefile")
// write initial resourcefile to temp path
err := os.WriteFile(path, []byte(resourcefile), 0666)
err := os.WriteFile(path, []byte(resourcefile), 0644)
if !assert.NoError(t, err) {
t.FailNow()
}
@@ -342,7 +342,7 @@ func TestAddUpdateSubstitution(t *testing.T) {
path := filepath.Join(os.TempDir(), "resourcefile")
// write initial resourcefile to temp path
err := os.WriteFile(path, []byte(resourcefile), 0666)
err := os.WriteFile(path, []byte(resourcefile), 0644)
if !assert.NoError(t, err) {
t.FailNow()
}

View File

@@ -42,7 +42,7 @@ func TestDelete_Filter2(t *testing.T) {
path := filepath.Join(os.TempDir(), "resourcefile2")
// write initial resourcefile to temp path
err := os.WriteFile(path, []byte(resourcefile2), 0666)
err := os.WriteFile(path, []byte(resourcefile2), 0644)
if !assert.NoError(t, err) {
t.FailNow()
}

View File

@@ -48,7 +48,7 @@ func TestDeleterCreator_Delete(t *testing.T) {
}
defer os.Remove(openAPI.Name())
// write openapi to temp dir
err = os.WriteFile(openAPI.Name(), []byte(openAPIFile), 0666)
err = os.WriteFile(openAPI.Name(), []byte(openAPIFile), 0644)
if !assert.NoError(t, err) {
t.FailNow()
}
@@ -59,7 +59,7 @@ func TestDeleterCreator_Delete(t *testing.T) {
t.FailNow()
}
defer os.Remove(resource.Name())
err = os.WriteFile(resource.Name(), []byte(resourceFile), 0666)
err = os.WriteFile(resource.Name(), []byte(resourceFile), 0644)
if !assert.NoError(t, err) {
t.FailNow()
}

View File

@@ -66,7 +66,7 @@ func WriteFile(node *RNode, path string) error {
if err != nil {
return err
}
return os.WriteFile(path, []byte(out), 0600)
return errors.WrapPrefixf(os.WriteFile(path, []byte(out), 0600), "writing RNode to file")
}
// UpdateFile reads the file at path, applies the filter to it, and write the result back.

View File

@@ -215,7 +215,7 @@ func (p *HelmChartInflationGeneratorPlugin) writeValuesBytes(
return "", fmt.Errorf("cannot create tmp dir to write helm values")
}
path := filepath.Join(p.tmpDir, p.Name+"-kustomize-values.yaml")
return path, os.WriteFile(path, b, 0644)
return path, errors.Wrap(os.WriteFile(path, b, 0644), "failed to write values file")
}
func (p *HelmChartInflationGeneratorPlugin) cleanup() {