dev: bytes.NewBuffer/bytes.NewBufferString to shorten initialization (#3632)

This commit is contained in:
Oleksandr Redko 2023-02-24 17:40:18 +02:00 committed by GitHub
parent ca5738e1fe
commit f4fec8c6d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 12 deletions

View File

@ -157,8 +157,7 @@ func (e *Executor) initHashSalt(version string) error {
return fmt.Errorf("failed to calculate config salt: %w", err)
}
var b bytes.Buffer
b.Write(binSalt)
b := bytes.NewBuffer(binSalt)
b.Write(configSalt)
cache.SetSalt(b.Bytes())
return nil
@ -198,8 +197,7 @@ func computeConfigSalt(cfg *config.Config) ([]byte, error) {
return nil, fmt.Errorf("failed to json marshal config linter settings: %w", err)
}
var configData bytes.Buffer
configData.WriteString("linters-settings=")
configData := bytes.NewBufferString("linters-settings=")
configData.Write(lintersSettingsBytes)
configData.WriteString("\nbuild-tags=%s" + strings.Join(cfg.Run.BuildTags, ","))

View File

@ -88,13 +88,9 @@ func runGofumpt(lintCtx *linter.Context, pass *analysis.Pass, diff differ, optio
}
if !bytes.Equal(input, output) {
out := bytes.Buffer{}
_, err = out.WriteString(fmt.Sprintf("--- %[1]s\n+++ %[1]s\n", f))
if err != nil {
return nil, fmt.Errorf("error while running gofumpt: %w", err)
}
out := bytes.NewBufferString(fmt.Sprintf("--- %[1]s\n+++ %[1]s\n", f))
err = diff.Diff(&out, bytes.NewReader(input), bytes.NewReader(output))
err := diff.Diff(out, bytes.NewReader(input), bytes.NewReader(output))
if err != nil {
return nil, fmt.Errorf("error while running gofumpt: %w", err)
}

View File

@ -64,8 +64,7 @@ func updateStateFile(replacements map[string]string) error {
return err
}
var contentBuf bytes.Buffer
contentBuf.WriteString("This file stores hash of website templates to trigger " +
contentBuf := bytes.NewBufferString("This file stores hash of website templates to trigger " +
"Netlify rebuild when something changes, e.g. new linter is added.\n")
contentBuf.WriteString(hex.EncodeToString(h.Sum(nil)))