diff --git a/forms/record_upsert.go b/forms/record_upsert.go index e00b4264..ba21e94c 100644 --- a/forms/record_upsert.go +++ b/forms/record_upsert.go @@ -292,7 +292,7 @@ func (form *RecordUpsert) Submit() error { } // delete old files (if any) - if err := form.processFilesToDelete(); err != nil { + if err := form.processFilesToDelete(); err != nil { //nolint:staticcheck // for now fail silently to avoid reupload when `form.Submit()` // is called manually (aka. not from an api request)... } diff --git a/tools/hook/hook.go b/tools/hook/hook.go index da88b8e9..c0fd40b3 100644 --- a/tools/hook/hook.go +++ b/tools/hook/hook.go @@ -44,8 +44,9 @@ func (h *Hook[T]) Reset() { // - any non-nil error is returned in one of the handlers func (h *Hook[T]) Trigger(data T, oneOffHandlers ...Handler[T]) error { h.mux.Lock() - handlers := append(h.handlers, oneOffHandlers...) - h.mux.Unlock() // unlock is not deferred to avoid deadlocks when Trigger is called recursive in the handlers + handlers := append(h.handlers, oneOffHandlers...) //nolint:gocritic + // unlock is not deferred to avoid deadlocks when Trigger is called recursive by the handlers + h.mux.Unlock() for _, fn := range handlers { err := fn(data) diff --git a/tools/inflector/inflector.go b/tools/inflector/inflector.go index 6e39efaf..f4b45243 100644 --- a/tools/inflector/inflector.go +++ b/tools/inflector/inflector.go @@ -8,7 +8,6 @@ import ( var columnifyRemoveRegex = regexp.MustCompile(`[^\w\.\*\-\_\@\#]+`) var snakecaseSplitRegex = regexp.MustCompile(`[\W_]+`) -var usernamifySplitRegex = regexp.MustCompile(`\W+`) // UcFirst converts the first character of a string into uppercase. func UcFirst(str string) string { @@ -85,34 +84,3 @@ func Snakecase(str string) string { return strings.ToLower(result.String()) } - -// Usernamify generates a properly formatted username from the provided string. -// Returns "unknown" if `str` is empty or contains only non word characters. -// -// ```go -// Usernamify("John Doe, hello") // "john.doe.hello" -// ``` -func Usernamify(str string) string { - // split at any non word character - words := usernamifySplitRegex.Split(strings.ToLower(str), -1) - - // concatenate any non empty word with a dot - var result strings.Builder - for _, word := range words { - if word == "" { - continue - } - - if result.Len() > 0 { - result.WriteString(".") - } - - result.WriteString(word) - } - - if result.Len() == 0 { - return "unknown" - } - - return result.String() -} diff --git a/tools/inflector/inflector_test.go b/tools/inflector/inflector_test.go index 4a09e554..8a768ddb 100644 --- a/tools/inflector/inflector_test.go +++ b/tools/inflector/inflector_test.go @@ -128,26 +128,3 @@ func TestSnakecase(t *testing.T) { } } } - -func TestUsernamify(t *testing.T) { - scenarios := []struct { - val string - expected string - }{ - {"", "unknown"}, - {" ", "unknown"}, - {"!@#$%^", "unknown"}, - {"...", "unknown"}, - {"_", "_"}, // underscore is valid word character - {"John Doe", "john.doe"}, - {"John_Doe", "john_doe"}, - {".a!b@c#d$e%123. ", "a.b.c.d.e.123"}, - {"Hello, world", "hello.world"}, - } - - for i, scenario := range scenarios { - if result := inflector.Usernamify(scenario.val); result != scenario.expected { - t.Errorf("(%d) Expected %q, got %q", i, scenario.expected, result) - } - } -}