Merge pull request #13516 from TerryHowe/new-lint

chore: fix problems with latest lint
pull/13283/head
George Jenkins 8 months ago committed by GitHub
commit 415c7e10fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -177,22 +177,15 @@ func formatAppVersion(c *chart.Chart) string {
return c.AppVersion() return c.AppVersion()
} }
func min(x, y int) int {
if x < y {
return x
}
return y
}
func compListRevisions(_ string, cfg *action.Configuration, releaseName string) ([]string, cobra.ShellCompDirective) { func compListRevisions(_ string, cfg *action.Configuration, releaseName string) ([]string, cobra.ShellCompDirective) {
client := action.NewHistory(cfg) client := action.NewHistory(cfg)
var revisions []string var revisions []string
if hist, err := client.Run(releaseName); err == nil { if hist, err := client.Run(releaseName); err == nil {
for _, release := range hist { for _, version := range hist {
appVersion := fmt.Sprintf("App: %s", release.Chart.Metadata.AppVersion) appVersion := fmt.Sprintf("App: %s", version.Chart.Metadata.AppVersion)
chartDesc := fmt.Sprintf("Chart: %s-%s", release.Chart.Metadata.Name, release.Chart.Metadata.Version) chartDesc := fmt.Sprintf("Chart: %s-%s", version.Chart.Metadata.Name, version.Chart.Metadata.Version)
revisions = append(revisions, fmt.Sprintf("%s\t%s, %s", strconv.Itoa(release.Version), appVersion, chartDesc)) revisions = append(revisions, fmt.Sprintf("%s\t%s, %s", strconv.Itoa(version.Version), appVersion, chartDesc))
} }
return revisions, cobra.ShellCompDirectiveNoFileComp return revisions, cobra.ShellCompDirectiveNoFileComp
} }

@ -162,9 +162,9 @@ func TestRepoIndexCmd(t *testing.T) {
} }
} }
func linkOrCopy(old, new string) error { func linkOrCopy(source, target string) error {
if err := os.Link(old, new); err != nil { if err := os.Link(source, target); err != nil {
return copyFile(old, new) return copyFile(source, target)
} }
return nil return nil

@ -215,7 +215,7 @@ func isTestHook(h *release.Hook) bool {
// bug introduced by #8156. As part of the todo to refactor renderResources // bug introduced by #8156. As part of the todo to refactor renderResources
// this duplicate code should be removed. It is added here so that the API // this duplicate code should be removed. It is added here so that the API
// surface area is as minimally impacted as possible in fixing the issue. // surface area is as minimally impacted as possible in fixing the issue.
func writeToFile(outputDir string, name string, data string, append bool) error { func writeToFile(outputDir string, name string, data string, appendData bool) error {
outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator)) outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator))
err := ensureDirectoryForFile(outfileName) err := ensureDirectoryForFile(outfileName)
@ -223,7 +223,7 @@ func writeToFile(outputDir string, name string, data string, append bool) error
return err return err
} }
f, err := createOrOpenFile(outfileName, append) f, err := createOrOpenFile(outfileName, appendData)
if err != nil { if err != nil {
return err return err
} }
@ -240,8 +240,8 @@ func writeToFile(outputDir string, name string, data string, append bool) error
return nil return nil
} }
func createOrOpenFile(filename string, append bool) (*os.File, error) { func createOrOpenFile(filename string, appendData bool) (*os.File, error) {
if append { if appendData {
return os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600) return os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600)
} }
return os.Create(filename) return os.Create(filename)

@ -108,12 +108,12 @@ func checkMarks(t *testing.T, report bool) {
} }
// Assumes that each node name is unique. Good enough for a test. // Assumes that each node name is unique. Good enough for a test.
// If clear is true, any incoming error is cleared before return. The errors // If clearIncomingError is true, any incoming error is cleared before
// are always accumulated, though. // return. The errors are always accumulated, though.
func mark(info os.FileInfo, err error, errors *[]error, clear bool) error { func mark(info os.FileInfo, err error, errors *[]error, clearIncomingError bool) error {
if err != nil { if err != nil {
*errors = append(*errors, err) *errors = append(*errors, err)
if clear { if clearIncomingError {
return nil return nil
} }
return err return err
@ -130,9 +130,8 @@ func mark(info os.FileInfo, err error, errors *[]error, clear bool) error {
func TestWalk(t *testing.T) { func TestWalk(t *testing.T) {
makeTree(t) makeTree(t)
errors := make([]error, 0, 10) errors := make([]error, 0, 10)
clear := true
markFn := func(_ string, info os.FileInfo, err error) error { markFn := func(_ string, info os.FileInfo, err error) error {
return mark(info, err, &errors, clear) return mark(info, err, &errors, true)
} }
// Expect no errors. // Expect no errors.
err := Walk(tree.name, markFn) err := Walk(tree.name, markFn)

@ -602,8 +602,8 @@ func (i *Install) replaceRelease(rel *release.Release) error {
return i.recordRelease(last) return i.recordRelease(last)
} }
// write the <data> to <output-dir>/<name>. <append> controls if the file is created or content will be appended // write the <data> to <output-dir>/<name>. <appendData> controls if the file is created or content will be appended
func writeToFile(outputDir string, name string, data string, append bool) error { func writeToFile(outputDir string, name string, data string, appendData bool) error {
outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator)) outfileName := strings.Join([]string{outputDir, name}, string(filepath.Separator))
err := ensureDirectoryForFile(outfileName) err := ensureDirectoryForFile(outfileName)
@ -611,7 +611,7 @@ func writeToFile(outputDir string, name string, data string, append bool) error
return err return err
} }
f, err := createOrOpenFile(outfileName, append) f, err := createOrOpenFile(outfileName, appendData)
if err != nil { if err != nil {
return err return err
} }
@ -628,8 +628,8 @@ func writeToFile(outputDir string, name string, data string, append bool) error
return nil return nil
} }
func createOrOpenFile(filename string, append bool) (*os.File, error) { func createOrOpenFile(filename string, appendData bool) (*os.File, error) {
if append { if appendData {
return os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600) return os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0600)
} }
return os.Create(filename) return os.Create(filename)

@ -73,16 +73,16 @@ func validateNoDeprecations(resource *K8sYamlStruct, kubeVersion *chartutil.Kube
return err return err
} }
maj, err := strconv.Atoi(majorVersion) major, err := strconv.Atoi(majorVersion)
if err != nil { if err != nil {
return err return err
} }
min, err := strconv.Atoi(minorVersion) minor, err := strconv.Atoi(minorVersion)
if err != nil { if err != nil {
return err return err
} }
if !deprecation.IsDeprecated(runtimeObject, maj, min) { if !deprecation.IsDeprecated(runtimeObject, major, minor) {
return nil return nil
} }
gvk := fmt.Sprintf("%s %s", resource.APIVersion, resource.Kind) gvk := fmt.Sprintf("%s %s", resource.APIVersion, resource.Kind)

@ -161,15 +161,15 @@ func (s *Storage) History(name string) ([]*rspb.Release, error) {
// //
// We allow max to be set explicitly so that calling functions can "make space" // We allow max to be set explicitly so that calling functions can "make space"
// for the new records they are going to write. // for the new records they are going to write.
func (s *Storage) removeLeastRecent(name string, max int) error { func (s *Storage) removeLeastRecent(name string, maximum int) error {
if max < 0 { if maximum < 0 {
return nil return nil
} }
h, err := s.History(name) h, err := s.History(name)
if err != nil { if err != nil {
return err return err
} }
if len(h) <= max { if len(h) <= maximum {
return nil return nil
} }
@ -183,8 +183,8 @@ func (s *Storage) removeLeastRecent(name string, max int) error {
var toDelete []*rspb.Release var toDelete []*rspb.Release
for _, rel := range h { for _, rel := range h {
// once we have enough releases to delete to reach the max, stop // once we have enough releases to delete to reach the maximum, stop
if len(h)-len(toDelete) == max { if len(h)-len(toDelete) == maximum {
break break
} }
if lastDeployed != nil { if lastDeployed != nil {

@ -30,7 +30,7 @@ import (
var emptyString = `""` var emptyString = `""`
// Time is a convenience wrapper around stdlib time, but with different // Time is a convenience wrapper around stdlib time, but with different
// marshalling and unmarshaling for zero values // marshalling and unmarshalling for zero values
type Time struct { type Time struct {
time.Time time.Time
} }
@ -70,8 +70,8 @@ func ParseInLocation(layout, value string, loc *time.Location) (Time, error) {
return Time{Time: t}, err return Time{Time: t}, err
} }
func Date(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) Time { func Date(year int, month time.Month, day, hour, minute, second, nanoSecond int, loc *time.Location) Time {
return Time{Time: time.Date(year, month, day, hour, min, sec, nsec, loc)} return Time{Time: time.Date(year, month, day, hour, minute, second, nanoSecond, loc)}
} }
func Unix(sec int64, nsec int64) Time { return Time{Time: time.Unix(sec, nsec)} } func Unix(sec int64, nsec int64) Time { return Time{Time: time.Unix(sec, nsec)} }

Loading…
Cancel
Save