Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@brandur
Copy link
Contributor

@brandur brandur commented Mar 25, 2025

For better or rwose, golangci-lint has released a v2 [1] that's
incompatible with v1. It'll only be a matter of time until we're forced
to upgrade to it, so I figure we may as well do it early.

There's a bunch of new obnoxious linters that I've disabled. Most of
these complain about "cyclomatic complexity" or "cognitive complexity"
or functions being too long (they all seem to want everything broken
down into functions of ten lines).

Aside from that, testifylint seems to have gotten even more effective
at finding misuses of testify, so it fixed a bunch more arguable misuses
of various assertions, which seems good for normalizing code.

The structure of the YAML file changes fairly significantly, but it's
all basically the same thing with various aspects reorganized. I made
the new one using the built-in golangci-lint migrate and copied
comments over manually.

If we can get this in, the next step will be to distribute it out to
other River projects. Most of them are using copies of this repo's
configuration file, so it should be pretty easy to do.

[1] https://ldez.github.io/blog/2025/03/23/golangci-lint-v2/

// - JobInsertMiddleware
// - WorkerMiddleware
//
// More operation-specific interfaces may be added in future versions.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These ones are a little unfortunate, but the lint that checks that comments end with periods has a bug in it where it was seeing "- WorkerMiddleware" as the last line, trying to rewrite it to end in a period with --fix, but then accidentally removing the entire comment in favor of just "- WorkerMiddleware." (period at end).

It's definitely a bug which I guess I should send over to someone, but it was just easier to add one more sentence at the end instead so it stops doing that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Wild bug. We could put the revert of this in its own branch and send it over as a reproduction if we know which repo to open it on?

@brandur brandur force-pushed the brandur-golangci-lint-v2 branch from 7d3776c to bff038a Compare March 25, 2025 05:06
@brandur brandur requested a review from bgentry March 25, 2025 05:11
Copy link
Contributor

@bgentry bgentry left a comment

Choose a reason for hiding this comment

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

I'm a little nervous about shipping this in Pro prior to landing the next big PR there. Will try to get that finished up ASAP so it's a non-issue.

- err113 # wants all errors to be defined as variables at the package level; quite obnoxious
- maintidx # ANOTHER ANOTHER "cyclomatic complexity" lint (see also "cyclop" and "gocyclo")
- mnd # detects "magic numbers", which it defines as any number; annoying
- nestif # yells when if blocks are nested; what planet do these people come from?
Copy link
Contributor

Choose a reason for hiding this comment

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

🤣

Comment on lines +15 to +16
- cyclop # screams into the void at "cyclomatic complexity"
- funlen # screams when functions are more than 60 lines long; what are we even doing here guys
Copy link
Contributor

Choose a reason for hiding this comment

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

These are popular in Ruby and Elixir. It makes a bit more sense in Ruby with DSLs and the low cost of extracting tons of little methods, but less so in Go IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah exactly. IMO it seems fine to keep function lengths generally short, but requiring it of every single function is just too much. There are many places where a slightly longer function can be more clear than a shorter one! Dogma is the enemy quality.

.golangci.yaml Outdated
Comment on lines 37 to 38
- pkg: github.com/xtgo/uuid
desc: Use `github.com/google/uuid` package for UUIDs instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

intentional non-alphabetical resorts of attr ordering in here? There's a whole bunch of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah I didn't even notice.

I guess it doesn't matter as much for these sorts of two-item tuples, but just so we have a system, I put them all back the way they were including the Forbidigo rules below.

} else if orderBy.Order == SortOrderDesc {
case SortOrderDesc:
orderByBuilder.WriteString(" DESC")
case SortOrderUnspecified:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should actually be an error 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, I wasn't sure if this was supposed to be possible or not.

I just replaced it with an error instead. Seems to pass the tests so hopefully it's okay ...

@brandur brandur force-pushed the brandur-golangci-lint-v2 branch from bff038a to e386fb0 Compare March 26, 2025 00:34
For better or rwose, golangci-lint has released a v2 [1] that's
incompatible with v1. It'll only be a matter of time until we're forced
to upgrade to it, so I figure we may as well do it early.

There's a bunch of new obnoxious linters that I've disabled. Most of
these complain about "cyclomatic complexity" or "cognitive complexity"
or functions being too long (they all seem to want everything broken
down into functions of ten lines).

Aside from that, `testifylint` seems to have gotten even more effective
at finding misuses of testify, so it fixed a bunch more arguable misuses
of various assertions, which seems good for normalizing code.

The structure of the YAML file changes fairly significantly, but it's
all basically the same thing with various aspects reorganized. I made
the new one using the built-in `golangci-lint migrate` and copied
comments over manually.

If we can get this in, the next step will be to distribute it out to
other River projects. Most of them are using copies of this repo's
configuration file, so it should be pretty easy to do.

[1] https://ldez.github.io/blog/2025/03/23/golangci-lint-v2/
@brandur brandur force-pushed the brandur-golangci-lint-v2 branch from e386fb0 to facf2ba Compare March 26, 2025 00:35
@brandur brandur merged commit fe87261 into master Mar 26, 2025
10 checks passed
@brandur brandur deleted the brandur-golangci-lint-v2 branch March 26, 2025 00:40
brandur added a commit to riverqueue/idempotent-email-demo that referenced this pull request Mar 26, 2025
Golangci-lint v2 was released earlier this week [1]. The main River
project has already been updated [2], so here we're just going through
and updating all the peripheral projects as well. I'm reusing the same
`.golangci.yaml` across all of them so that we stay reasonable
standardized.

[1] https://ldez.github.io/blog/2025/03/23/golangci-lint-v2/
[2] riverqueue/river#818
brandur added a commit to riverqueue/rivercontrib that referenced this pull request Mar 26, 2025
Golangci-lint v2 was released earlier this week [1]. The main River
project has already been updated [2], so here we're just going through
and updating all the peripheral projects as well. I'm reusing the same
`.golangci.yaml` across all of them so that we stay reasonable
standardized.

[1] https://ldez.github.io/blog/2025/03/23/golangci-lint-v2/
[2] riverqueue/river#818
brandur added a commit to riverqueue/apiframe that referenced this pull request Mar 26, 2025
Golangci-lint v2 was released earlier this week [1]. The main River
project has already been updated [2], so here we're just going through
and updating all the peripheral projects as well. I'm reusing the same
`.golangci.yaml` across all of them so that we stay reasonable
standardized.

[1] https://ldez.github.io/blog/2025/03/23/golangci-lint-v2/
[2] riverqueue/river#818
brandur added a commit to riverqueue/idempotent-email-demo that referenced this pull request Mar 26, 2025
Golangci-lint v2 was released earlier this week [1]. The main River
project has already been updated [2], so here we're just going through
and updating all the peripheral projects as well. I'm reusing the same
`.golangci.yaml` across all of them so that we stay reasonable
standardized.

[1] https://ldez.github.io/blog/2025/03/23/golangci-lint-v2/
[2] riverqueue/river#818
brandur added a commit to riverqueue/rivercontrib that referenced this pull request Mar 26, 2025
Golangci-lint v2 was released earlier this week [1]. The main River
project has already been updated [2], so here we're just going through
and updating all the peripheral projects as well. I'm reusing the same
`.golangci.yaml` across all of them so that we stay reasonable
standardized.

[1] https://ldez.github.io/blog/2025/03/23/golangci-lint-v2/
[2] riverqueue/river#818
brandur added a commit to riverqueue/apiframe that referenced this pull request Mar 26, 2025
Golangci-lint v2 was released earlier this week [1]. The main River
project has already been updated [2], so here we're just going through
and updating all the peripheral projects as well. I'm reusing the same
`.golangci.yaml` across all of them so that we stay reasonable
standardized.

[1] https://ldez.github.io/blog/2025/03/23/golangci-lint-v2/
[2] riverqueue/river#818
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