Skip to content

Conversation

@benhoyt
Copy link
Contributor

@benhoyt benhoyt commented Nov 19, 2025

DRAFT: do not merge without further discussion. This is the result of running gofumpt -l -w . on the Pebble codebase, to evaluate whether we want to use it.

The time.Date arguments, which gofumpt (I think properly) changes from 04 to 0o4, should be changes to just 4 to avoid this. We clearly intend decimal here -- there will be some manual edits required to fix these. But the other octal changes like 0o777 look fine.

Most of the other changes look good.

The one change I wasn't happy about is the change from }, { between struct literals, to },\n{. But it seems it allows the one-line format sometimes, so I'm not sure if we can tweak that behaviour, or if it matters enough to worry about.
UPDATE: I discovered gofumpt is fine with this, we just had some inconsistent comments between struct entries. See these commits for the fix (we'll need to fix manually in a few other places too).

Copy link
Contributor

@dimaqq dimaqq left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +51 to +56
SpawnTime: time.Date(2016, 0o4, 21, 1, 2, 3, 0, time.UTC),
ReadyTime: time.Date(2016, 0o4, 21, 1, 2, 4, 0, time.UTC),
}},

SpawnTime: time.Date(2016, 04, 21, 1, 2, 3, 0, time.UTC),
ReadyTime: time.Date(2016, 04, 21, 1, 2, 4, 0, time.UTC),
SpawnTime: time.Date(2016, 0o4, 21, 1, 2, 3, 0, time.UTC),
ReadyTime: time.Date(2016, 0o4, 21, 1, 2, 4, 0, time.UTC),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather see 4 than 0o4 here.

At the same time, the hidden octal 04 was kind nasty, any change is better than no change.

Comment on lines +43 to +54
}{{ // API source: Unix Domain Socket
// User: nil
apiSource: daemon.TransportTypeUnixSocket,
user: nil,
openCheckErr: nil,
adminCheckErr: errUnauthorized,
userCheckErr: errUnauthorized,
metricsCheckErr: errUnauthorized,
pairingCheckErr: errUnauthorized,
}, {
// User access: UntrustedAccess
apiSource: daemon.TransportTypeUnixSocket,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm happy with the change, though:

  • the comments look a bit inconsistent now, how come the "API" comment shares a line with the opening curly, but "Untrusted" doesn't?
  • the first comment was meant to apply to the block, and now it doesn't... perhaps the this code needs to be refactored so that variable names or keys are used instead of comments

Something like:

type accessTest struct {...}

var (
	untrustedUser = &daemon.UserState{Access: state.UntrustedAccess}
	metricsUser   = &daemon.UserState{Access: state.MetricsAccess}
...

var unixSocketTests = []accessTest{
	// User: nil
	{
		apiSource:       daemon.TransportTypeUnixSocket,
		user:            nil,
        ...
     },{
        ...
     }
}
...

func ... TestAccess (...) {
	tests := nil
	tests = append(tests, unixSocketTests...)
	tests = append(tests, httpTests...)
    ...
}

Comment on lines +597 to +598
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

This change seems to be the opposite of the test change above?

Copy link
Member

Choose a reason for hiding this comment

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

I think that this is one of the spots that Ben mentioned in the PR description:

The one change I wasn't happy about is the change from }, { between struct literals, to },\n{. But it seems it allows the one-line format sometimes, so I'm not sure if we can tweak that behaviour, or if it matters enough to worry about.
UPDATE: I discovered gofumpt is fine with this, we just had some inconsistent comments between struct entries. See these commits for the fix (we'll need to fix manually in a few other places too).

See the // Some basics. comment above. That comment doesn't appear to add significant value and could probably be removed.

var (
timeNow = time.Now
)
var timeNow = time.Now
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this only so that it can be mocked out in tests.

Is this a Go idiom, or does this dependency injection point deserve a comment?

Comment on lines +463 to +472
expected: []*timeutil.Schedule{
{
WeekSpans: []timeutil.WeekSpan{
{Start: timeutil.Week{Weekday: time.Monday}, End: timeutil.Week{Weekday: time.Monday}},
},
}, {
WeekSpans: []timeutil.WeekSpan{
{Start: timeutil.Week{Weekday: time.Wednesday}, End: timeutil.Week{Weekday: time.Wednesday}},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps a bit too verbose, but these are tests, no biggie.

Comment on lines +133 to +134
layers: []string{
`
Copy link
Contributor

Choose a reason for hiding this comment

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

Does that technically change the leading whitespace in the multiline string literal?

Copy link
Member

@holmanb holmanb Dec 17, 2025

Choose a reason for hiding this comment

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

It doesn't look like it. The same number of newlines exist within the backticks, a newline is just added before.

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