-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use constants to reduce duplication #42
base: main
Are you sure you want to change the base?
Conversation
main.go
Outdated
AS_GIT_EDITOR = "as-git-editor" | ||
ERROR_STRING = "Error: %s" | ||
SHIFT_TAB = "shift+tab" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constants in Go are usually not in uppercase, and barely never in "screaming snake case"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware of this standard, thank you!
main.go
Outdated
@@ -47,9 +47,15 @@ var ( | |||
AFS *afero.Afero = &afero.Afero{Fs: FS} | |||
) | |||
|
|||
const ( | |||
AS_GIT_EDITOR = "as-git-editor" | |||
ERROR_STRING = "Error: %s" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERROR_STRING = "Error: %s" | |
ERROR_STRING = "Error: %s" |
This one make no sense to me
Unless I miss something you are using it when calling fail.
Please prefix error with "Errors: " in fail function.
Also, if you are only passing an error to fail, please consider updating fail signature to accept an error. This way you format the error with fmt.Errorf if you need some formating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of multiline error messages such as
fail(
"\n%s\n%s\n\n%s\n\n",
color.RedString(fmt.Sprintf("It looks like the commit failed.\nError: %s", err)),
color.YellowString("To run it again without going through meteor's wizard, simply run the following command (I've copied it to your clipboard!):"),
color.BlueString(printableCommitCommand),
)
Where the arguments to fail
are actually just strings. I would have to split fail
into different functions for each specific case (passing errors, passing strings...) which would be fine, just not sure if the generic approach is better or worse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could have a function for generating the error messages though, and allow fail
to just accept strings instead. I think this is a change that I'll do in a different PR though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds a good idea
Quality Gate passedIssues Measures |
This PR addresses a SonarCloud issue where some strings were duplicated multiple times. These strings are now constants