Skip to content

Comments

ci,lint: explicit linter configuration and subsequent fixes#141

Merged
pires merged 3 commits intomainfrom
pires/feat/linter_modernize
Feb 3, 2026
Merged

ci,lint: explicit linter configuration and subsequent fixes#141
pires merged 3 commits intomainfrom
pires/feat/linter_modernize

Conversation

@pires
Copy link
Owner

@pires pires commented Jan 26, 2026

I realized I didn't have an explicit list of linters and the default set is somewhat limited.

@emersion I know it's too much to ask but I would sleep better at night if this wasn't just a me thing 😅 🙏🏻 I left comments where I think attention is asked for.


defer conn.Close()
defer func() {
_ = conn.Close()
Copy link
Owner Author

Choose a reason for hiding this comment

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

We can be stricter but this is just an example so 🤷🏻‍♂️

@coveralls
Copy link

coveralls commented Jan 26, 2026

Coverage Status

coverage: 95.03% (+0.2%) from 94.784%
when pulling 1d885f7 on pires/feat/linter_modernize
into f6b536f on main.

defer proxyListener.Close()
defer func() {
if err := proxyListener.Close(); err != nil {
log.Printf("failed to close proxy listener: %v", err)
Copy link
Owner Author

Choose a reason for hiding this comment

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

In this example, we actually log the error vs ignoring it like we did for client/client.go.

}
if max := 1 * time.Second; delay > max {
delay = max
if maxDelay := 1 * time.Second; delay > maxDelay {
Copy link
Owner Author

Choose a reason for hiding this comment

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

max is now a built-in function so we should not use it as a var name.


go func(conn net.Conn, baseCtx context.Context) {
if err := srv.serveConn(conn, baseCtx); err != nil {
go func(baseCtx context.Context, conn net.Conn) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

context.Context ideally is the first param on a func's signature.

}

// SSLType is true if the TLV is type SSL
// IsSSL reports whether the TLV is of SSL type.
Copy link
Owner Author

Choose a reason for hiding this comment

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

Praised be linters.

}

// SSL returns the first PP2SSL if it exists and is well formed as well as bool indicating if it was found.
// FindSSL returns the first PP2SSL if it exists and is well formed.
Copy link
Owner Author

Choose a reason for hiding this comment

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

Praised be linters.

- misspell
- revive
- unconvert
- usestdlibvars
Copy link
Owner Author

Choose a reason for hiding this comment

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

Selected the ones I consider add up to the quality of the project from a security and readability perspectives.

allow-parallel-runners: true

issues:
max-issues-per-linter: 0
Copy link
Owner Author

Choose a reason for hiding this comment

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

Default is 50 which makes it harder to massively fix linter errors.

// can't decide the policy, we can't accept the connection.
if closeErr := conn.Close(); closeErr != nil {
return nil, closeErr
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

If we must close the connection then we must error out if we are unable to, right?

if sourcePort, destPort, ok := header.Ports(); ok {
if sourcePort < 0 || sourcePort > math.MaxUint16 || destPort < 0 || destPort > math.MaxUint16 {
return nil, ErrInvalidPortNumber
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

Praised be linters.

func parseUnixName(b []byte) string {
i := bytes.IndexByte(b, 0)
if i < 0 {
before, _, ok := bytes.Cut(b, []byte{0})
Copy link
Owner Author

Choose a reason for hiding this comment

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

Added unit tests to prove it works as expected.

// Make two calls to trigger the listener's accept, the first should experience
// the ErrInvalidUpstream and keep the listener open, the second should experience
// a different error which will cause the listener to close.
_, _ = http.Get("http://localhost:8080")
Copy link
Owner Author

Choose a reason for hiding this comment

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

Made this test way more explicit to better fit the description.

select {
case err := <-errCh:
if err == nil {
t.Fatalf("errors other than invalid upstream should error")
Copy link
Owner Author

Choose a reason for hiding this comment

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

This seems wrong, doesn't it?

@pires pires merged commit b672b15 into main Feb 3, 2026
12 checks passed
@pires pires deleted the pires/feat/linter_modernize branch February 3, 2026 10:45
@emersion
Copy link
Contributor

emersion commented Feb 3, 2026

Sorry, I ended up not having enough time to review this PR.

@pires
Copy link
Owner Author

pires commented Feb 3, 2026

Totally get it. Thank you for taking the time, it's much appreciated. I guess we'll learn soon if things break :D

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