From 54e9ee37a7a301dbe74d46fd3c87712e6120e9bf Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 20 Jan 2022 18:46:10 +0100 Subject: format with gofumpt (#18184) * gofumpt -w -l . * gofumpt -w -l -extra . * Add linter * manual fix * change make fmt --- modules/util/paginate_test.go | 2 +- modules/util/path_test.go | 2 +- modules/util/sanitize.go | 6 ++++-- modules/util/sanitize_test.go | 6 +++--- modules/util/shellquote.go | 8 +++++--- modules/util/truncate.go | 6 ++++-- modules/util/util_test.go | 1 - 7 files changed, 18 insertions(+), 13 deletions(-) (limited to 'modules/util') diff --git a/modules/util/paginate_test.go b/modules/util/paginate_test.go index d962e04c16..3657efc919 100644 --- a/modules/util/paginate_test.go +++ b/modules/util/paginate_test.go @@ -36,7 +36,7 @@ func TestPaginateSlice(t *testing.T) { Val int } - var testVar = []*Test{{Val: 2}, {Val: 3}, {Val: 4}} + testVar := []*Test{{Val: 2}, {Val: 3}, {Val: 4}} testVar, ok = PaginateSlice(testVar, 1, 50).([]*Test) assert.True(t, ok) assert.EqualValues(t, []*Test{{Val: 2}, {Val: 3}, {Val: 4}}, testVar) diff --git a/modules/util/path_test.go b/modules/util/path_test.go index 41104f79fc..b0ea448a1c 100644 --- a/modules/util/path_test.go +++ b/modules/util/path_test.go @@ -13,7 +13,7 @@ import ( ) func TestFileURLToPath(t *testing.T) { - var cases = []struct { + cases := []struct { url string expected string haserror bool diff --git a/modules/util/sanitize.go b/modules/util/sanitize.go index de59ffaa2e..a782fcf512 100644 --- a/modules/util/sanitize.go +++ b/modules/util/sanitize.go @@ -9,8 +9,10 @@ import ( "strings" ) -const userPlaceholder = "sanitized-credential" -const unparsableURL = "(unparsable url)" +const ( + userPlaceholder = "sanitized-credential" + unparsableURL = "(unparsable url)" +) type sanitizedError struct { err error diff --git a/modules/util/sanitize_test.go b/modules/util/sanitize_test.go index 578f75f518..c141f5e947 100644 --- a/modules/util/sanitize_test.go +++ b/modules/util/sanitize_test.go @@ -16,7 +16,7 @@ func TestNewSanitizedError(t *testing.T) { err2 := NewSanitizedError(err) assert.Equal(t, err.Error(), err2.Error()) - var cases = []struct { + cases := []struct { input error oldnew []string expected string @@ -43,7 +43,7 @@ func TestNewSanitizedError(t *testing.T) { } func TestNewStringURLSanitizer(t *testing.T) { - var cases = []struct { + cases := []struct { input string placeholder bool expected string @@ -101,7 +101,7 @@ func TestNewStringURLSanitizer(t *testing.T) { } func TestNewStringURLSanitizedError(t *testing.T) { - var cases = []struct { + cases := []struct { input string placeholder bool expected string diff --git a/modules/util/shellquote.go b/modules/util/shellquote.go index bde24a1517..5a12c2e261 100644 --- a/modules/util/shellquote.go +++ b/modules/util/shellquote.go @@ -41,9 +41,11 @@ const ( needsSingleQuote = "!\n" ) -var doubleQuoteEscaper = strings.NewReplacer(`$`, `\$`, "`", "\\`", `"`, `\"`, `\`, `\\`) -var singleQuoteEscaper = strings.NewReplacer(`'`, `'\''`) -var singleQuoteCoalescer = strings.NewReplacer(`''\'`, `\'`, `\'''`, `\'`) +var ( + doubleQuoteEscaper = strings.NewReplacer(`$`, `\$`, "`", "\\`", `"`, `\"`, `\`, `\\`) + singleQuoteEscaper = strings.NewReplacer(`'`, `'\''`) + singleQuoteCoalescer = strings.NewReplacer(`''\'`, `\'`, `\'''`, `\'`) +) // ShellEscape will escape the provided string. // We can't just use go-shellquote here because our preferences for escaping differ from those in that we want: diff --git a/modules/util/truncate.go b/modules/util/truncate.go index 38c2c0d1d6..2e6f7f68b0 100644 --- a/modules/util/truncate.go +++ b/modules/util/truncate.go @@ -7,8 +7,10 @@ package util import "unicode/utf8" // in UTF8 "…" is 3 bytes so doesn't really gain us anything... -const utf8Ellipsis = "…" -const asciiEllipsis = "..." +const ( + utf8Ellipsis = "…" + asciiEllipsis = "..." +) // SplitStringAtByteN splits a string at byte n accounting for rune boundaries. (Combining characters are not accounted for.) func SplitStringAtByteN(input string, n int) (left, right string) { diff --git a/modules/util/util_test.go b/modules/util/util_test.go index f42b1a930f..e2e26b2627 100644 --- a/modules/util/util_test.go +++ b/modules/util/util_test.go @@ -46,7 +46,6 @@ func TestURLJoin(t *testing.T) { } func TestIsEmptyString(t *testing.T) { - cases := []struct { s string expected bool -- cgit v1.2.3