Skip to content
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

all: fix golangci-lint errors #14555

Merged
merged 1 commit into from
Jan 7, 2025
Merged

all: fix golangci-lint errors #14555

merged 1 commit into from
Jan 7, 2025

Conversation

willnorris
Copy link
Member

These erroneously blocked a recent PR, which I fixed by simply re-running CI. But we might as well fix them anyway. These are mostly printf to print and a couple of != to !Equal()

Updates #cleanup

fmt.Sprintf("PATH=" + defaultPathForUser(&u.User)),
fmt.Sprintf("SHELL=%v", u.LoginShell()),
fmt.Sprintf("USER=%v", u.Username),
fmt.Sprintf("HOME=%v", u.HomeDir),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the printf on these, thinking that we may want to use %q at some point, in case any of these values have spaces. I didn't do that proactively since I'm not 100% sure quoted strings are supported here, and didn't take the time to investigate further.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they're quoted at this level.

Sprintf is fine, or concat. Your call. I might do %s for extra clarity that we know they're strings. But %v is also fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done (switched to %s)

fmt.Sprintf("PATH=" + defaultPathForUser(&u.User)),
fmt.Sprintf("SHELL=%v", u.LoginShell()),
fmt.Sprintf("USER=%v", u.Username),
fmt.Sprintf("HOME=%v", u.HomeDir),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they're quoted at this level.

Sprintf is fine, or concat. Your call. I might do %s for extra clarity that we know they're strings. But %v is also fine.

Comment on lines 44 to 45
if got, want := cache.updated, time.Unix(0, 0); !got.Equal(want) {
t.Fatalf("got %s, want %s", got, want)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this fails, the local PDT or whatever time from time.Unix(0, 0) will probably be misleading

I'd prefer to normalize the timezone in the got/want variables first and then == would be fine (if the lint tool knew that, but it won't) just for the failure output to be nice. But Equal is fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converted both values to UTC

@@ -77,7 +77,7 @@ func presentRiskToUser(riskType, riskMessage, acceptedRisks string) error {
for left := riskAbortTimeSeconds; left > 0; left-- {
msg := fmt.Sprintf("\rContinuing in %d seconds...", left)
msgLen = len(msg)
printf(msg)
print(msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't equivalent. The printf before was our indirection to work in wasm/etc:

var Stderr io.Writer = os.Stderr
var Stdout io.Writer = os.Stdout

func errf(format string, a ...any) {
	fmt.Fprintf(Stderr, format, a...)
}

func printf(format string, a ...any) {
	fmt.Fprintf(Stdout, format, a...)
}

By using print, you're using the implementation's print (not even part of the language!)

So I'd do printf("%s", msg) here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh snap... totally didn't notice this was a local function and not a builtin. fixed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also didn't realized that print and println weren't part of the language. TIL https://go.dev/ref/spec#Bootstrapping

These erroneously blocked a recent PR, which I fixed by simply
re-running CI. But we might as well fix them anyway.
These are mostly `printf` to `print` and a couple of `!=` to `!Equal()`

Updates #cleanup

Signed-off-by: Will Norris <will@tailscale.com>
@willnorris willnorris merged commit 60daa2a into main Jan 7, 2025
50 checks passed
@willnorris willnorris deleted the will/lint-cleanup branch January 7, 2025 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants