Skip to content

chore: upgrade .golangci.yml and workflow to v2 #6924

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

mohammed90
Copy link
Member

I also ran golangci-lint fmt, which formats all files including tests. It found a couple issues, which is good.

run `golangci-lint fmt`

Signed-off-by: Mohammed Al Sahaf <[email protected]>
@mohammed90 mohammed90 added under review 🧐 Review is pending before merging CI/CD 🔩 Automated tests, releases labels Mar 25, 2025
Signed-off-by: Mohammed Al Sahaf <[email protected]>
Signed-off-by: Mohammed Al Sahaf <[email protected]>
Signed-off-by: Mohammed Al Sahaf <[email protected]>
Signed-off-by: Mohammed Al Sahaf <[email protected]>
Signed-off-by: Mohammed Al Sahaf <[email protected]>
@mohammed90 mohammed90 requested a review from WeidiDeng March 25, 2025 20:29
@mohammed90
Copy link
Member Author

mohammed90 commented Mar 25, 2025

@WeidiDeng, please take a look. The linter complaints included code lines in the listener management, and those parts of the code scare me. I already introduced and fixed one bug of infinite recursion. I'm afraid I did something else 👀

if !quoted && !(heredoc != heredocClosed || heredocEscaped) &&
if !quoted && (heredoc == heredocClosed && !heredocEscaped) &&
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this one is a valuable change, I think there's a usefulness behind this condition. But maybe it's better to extract this out to a var with a clearer name. I dunno.

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 honestly struggled to read the former form 😅 How would you read it? It'll help me find a suitable variable name. The new form is read in my head as:

If not quoted, and heredoc is closed and not escaped.

if !(quoted || btQuoted) && !(inHeredoc || heredocEscaped) &&
if (!quoted && !btQuoted) && (!inHeredoc && !heredocEscaped) &&
Copy link
Member

Choose a reason for hiding this comment

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

This one is okay I think, but both are easy enough to read I think.

@francislavoie
Copy link
Member

I'm glad fmt easily fixes the imports order now, very nice addition. We should maybe add that to the contribution doc to mention how to run it

@WeidiDeng
Copy link
Member

The changes regarding listeners are unreasonable. Those embedded fields are explicitly referred to so it's clear whose methods or fields we are using. Because of the way caddy usage pool is designed, there are many cases of struct embedding.

I see the new linter shortens many these types of embedding, and to be fair, I don't like it. Rather, I'd like for the linter to expand some of the embedding to its full form or not care about it at all.

@mohammed90
Copy link
Member Author

The changes regarding listeners are unreasonable. Those embedded fields are explicitly referred to so it's clear whose methods or fields we are using. Because of the way caddy usage pool is designed, there are many cases of struct embedding.

I see the new linter shortens many these types of embedding, and to be fair, I don't like it. Rather, I'd like for the linter to expand some of the embedding to its full form or not care about it at all.

Noted. I'll figure out which linting rule triggers this and disable it.

@WeidiDeng
Copy link
Member

Embeds in several other parts are shortened when it's better to leave them as they're, such as headers and response writers.

I think the linter should be run on the unmodified source before this bump.

@mohammed90 mohammed90 marked this pull request as draft April 15, 2025 22:01
@mohammed90
Copy link
Member Author

Changing it to draft until I resolve the review points. It might take me some time.

@mohammed90 mohammed90 marked this pull request as ready for review May 2, 2025 18:01
@mohammed90
Copy link
Member Author

Embeds in several other parts are shortened when it's better to leave them as they're, such as headers and response writers.

I think the linter should be run on the unmodified source before this bump.

All fixed

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Oops, I had pending comments for like weeks ago that didn't get posted I guess. Sorry if these are late to the party. I don't even remember where I was at in the review. I'm picky about linters 😜 -- I feel like they either are WAY too opinionated, or the enforce something very specific that you want for your code base.

break // shortcut if event not bound at all
}

for app.subscriptions[eventName] != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Sometimes I like the break/return pattern because it means less indentation, or can read a little easier.

Comment on lines +668 to +671
switch subdir {
case "request_buffers":
h.RequestBuffers = size
} else if subdir == "response_buffers" {
case "response_buffers":
Copy link
Member

Choose a reason for hiding this comment

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

I have no idea with a linter think it's a good idea to replace 3 lines of code with 4.

Comment on lines +125 to +128
switch fromAddr.Scheme {
case "http":
fromAddr.Port = httpPort
} else if fromAddr.Scheme == "https" {
case "https":
Copy link
Member

Choose a reason for hiding this comment

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

... or 2 lines of code with 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/CD 🔩 Automated tests, releases under review 🧐 Review is pending before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants