From 1a7b93a65c5d1296d729aa5bd184ae9498907e21 Mon Sep 17 00:00:00 2001 From: Raul Catalinas <105791463+RaulCatalinas@users.noreply.github.com> Date: Tue, 3 Dec 2024 23:39:52 +0100 Subject: [PATCH] chore: removed forgotten magic strings - Replaced remaining magic strings with enums for consistency. --- internal/utils/npm.go | 12 +++++++----- internal/utils/package-json.go | 10 ++++++---- internal/utils/utils.go | 12 +++++++----- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/internal/utils/npm.go b/internal/utils/npm.go index 53b545b..a39a208 100644 --- a/internal/utils/npm.go +++ b/internal/utils/npm.go @@ -4,13 +4,15 @@ import ( "fmt" "os" "strings" + + "github.com/RaulCatalinas/HuskyBC/internal/enums" ) func modifyNpmIgnore(filesToAdd interface{}) { defer func() { if r := recover(); r != nil { WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: GetErrorMessage("NpmIgnoreWrite"), }) @@ -19,7 +21,7 @@ func modifyNpmIgnore(filesToAdd interface{}) { }() WriteMessage(WriteMessageProps{ - Type: "info", + Type: enums.MessageTypeInfo, Message: "Writing in the file \".npmignore\"...", }) @@ -27,7 +29,7 @@ func modifyNpmIgnore(filesToAdd interface{}) { if err != nil { WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: GetErrorMessage("GetWorkingDirectory"), }) @@ -53,7 +55,7 @@ func modifyNpmIgnore(filesToAdd interface{}) { filesToWrite = strings.Join(v, "\n") default: WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: GetErrorMessage("InvalidTypeForFilesToAdd"), }) @@ -90,7 +92,7 @@ func modifyNpmIgnore(filesToAdd interface{}) { trimmedIgnoredFilesArray = append(trimmedIgnoredFilesArray, v...) default: WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: GetErrorMessage("InvalidTypeForFilesToAdd"), }) diff --git a/internal/utils/package-json.go b/internal/utils/package-json.go index 7b4d9ff..e2b157f 100644 --- a/internal/utils/package-json.go +++ b/internal/utils/package-json.go @@ -2,6 +2,8 @@ package utils import ( "os" + + "github.com/RaulCatalinas/HuskyBC/internal/enums" ) type addScriptProps struct { @@ -31,7 +33,7 @@ func addScript(props addScriptProps) { defer func() { if r := recover(); r != nil { WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: GetErrorMessage("AddScript"), }) @@ -40,7 +42,7 @@ func addScript(props addScriptProps) { }() WriteMessage(WriteMessageProps{ - Type: "info", + Type: enums.MessageTypeInfo, Message: "Modifying package.json...", }) @@ -61,7 +63,7 @@ func addScript(props addScriptProps) { scriptsSection[v.Key] = v.Value default: WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: GetErrorMessage("InvalidTypeForScriptsToAdd"), }) os.Exit(1) @@ -70,7 +72,7 @@ func addScript(props addScriptProps) { jsonMarshalIndentAndWriteFile(packageJsonObj, packageJsonPath) WriteMessage(WriteMessageProps{ - Type: "success", + Type: enums.MessageTypeSuccess, Message: "Package.json modified successfully", }) } diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 266ec30..600135c 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -4,6 +4,8 @@ import ( "encoding/json" "os" "strings" + + "github.com/RaulCatalinas/HuskyBC/internal/enums" ) func exists(filePath string) bool { @@ -17,7 +19,7 @@ func createEmptyFile(fileName string) { if err != nil { WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: GetErrorMessage("CreateEmptyFile"), }) @@ -33,7 +35,7 @@ func readFile(filename string) []byte { errorMessage := GetErrorMessage("ReadFile") WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: strings.Replace(errorMessage, "{fileName}", filename, -1), }) @@ -50,7 +52,7 @@ func writeFile(filename string, newData []byte) { errorMessage := GetErrorMessage("WriteFile") WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: strings.Replace(errorMessage, "{fileName}", filename, -1), }) } @@ -61,7 +63,7 @@ func jsonMarshalIndent(packageJsonObj map[string]interface{}) []byte { if err != nil { WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: GetErrorMessage("JsonMarshal"), }) @@ -78,7 +80,7 @@ func jsonUnmarshal(data []byte) map[string]interface{} { if err != nil { WriteMessage(WriteMessageProps{ - Type: "error", + Type: enums.MessageTypeError, Message: GetErrorMessage("JsonUnmarshal"), })