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

Create a separate module for our golangci-lint version #80

Merged
merged 3 commits into from
Sep 9, 2021

Conversation

benjaminjkraft
Copy link
Collaborator

Summary:

In principle, it's not a problem to have test-only deps in your go.mod,
because they won't end up in your importers' builds (and in newer Go
versions may not even be downloaded. (Which is why there's no
annotation to do so.) In practice, that doesn't really work for
golangci-lint, because it doesn't really use semver (reasonably, in that
any updated linter may break lint in your codebase). And we don't
really need it other than to run the binary at a particular version.

So now, I put it in its own go module. This requires a bit more
throat-clearing to run it (we can't just go run), but it's not so bad
and avoids anyone getting annoyed at us because we upgraded their
golangci-lint for them.

We could do the same for internal/integration, which adds quite a lot,
including gqlgen, to our dependency tree, but it's not clear there's a
need.

Fixes #62.

Issue: #62

Test plan:

make check

In principle, it's not a problem to have test-only deps in your go.mod,
because they won't end up in your importers' builds (and in newer Go
versions may not even be downloaded.  (Which is why there's no
annotation to do so.)  In practice, that doesn't really work for
golangci-lint, because it doesn't really use semver (reasonably, in that
any updated linter may break lint in your codebase).  And we don't
really need it other than to run the binary at a particular version.

So now, I put it in its own go module.  This requires a bit more
throat-clearing to run it (we can't just `go run`), but it's not so bad
and avoids anyone getting annoyed at us because we upgraded their
golangci-lint for them.

We could do the same for `internal/integration`, which adds quite a lot,
including gqlgen, to our dependency tree, but it's not clear there's a
need.

Fixes #62.

Issue: #62

Test plan:
make check

Reviewers: marksandstrom, steve, adam, miguel
@benjaminjkraft
Copy link
Collaborator Author

(@StevenACoffman, I cc'ed you here in case you know a better way to do this, or know of reasons why I should do it for gqlgen as well.)

Copy link
Contributor

@dnerdy dnerdy left a comment

Choose a reason for hiding this comment

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

Makes sense to me!

// `go mod tidy` ignores so-tagged files explicitly, so we use another build
// tag we never intend to set.
// +build tools
//go:build tools
Copy link
Member

Choose a reason for hiding this comment

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

So is go:build in Go 1.17? I remembered something about "finishing the transition in Go 1.18" (which maybe was just dropping // +build support)?

I also recall that some old versions of Go required // +build tools to be the very first line of the file... but that might have been before go mod so maybe not an issue? 🤷‍♂️ I think the current rules (until 1.18) are:

  1. start with the prefix +build followed by one or more spaces
  2. located at top of file before the package declaration
  3. have at least one blank line between it and package declaration to prevent it from being treated as package documentation
  4. The tags separated by space will be interpreted under the OR logic.
  5. Comma separated tags will be interpreted under the AND logic.
  6. Each term is an alphanumeric word and if preceded by ! it means it is negated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I think 1.16-1.18 all sync the two, and 1.17 is where go:build becomes the source of truth. Since it's easy, I plan to keep both around until we have other reasons to drop 1.16, which is presumably a while yet.

With all that said, I could probably remove this build tag now; nobody should be trying to build anything in this module!

@@ -0,0 +1,6 @@
module github.com/Khan/genqlient/internal/lint

go 1.14
Copy link
Member

Choose a reason for hiding this comment

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

1.14 is really old. I kind of think Khan is close to the trailing edge when it comes to Go version support. Most surveys show that 80% are on the current or last version by 6 months after a release. With container based runtimes and dependabot, it's automagical.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I think that's accurate. But my general feeling is to wait to drop support until there's a nontrivial reason to, which is why I dropped 1.13 recently, but kept 1.14.

Copy link
Member

@StevenACoffman StevenACoffman left a comment

Choose a reason for hiding this comment

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

This is how I would do it, but are we doing this to support webapp dependencies' updates lagging?

@benjaminjkraft
Copy link
Collaborator Author

benjaminjkraft commented Sep 9, 2021

No, Craig actually just updated golangci-lint in webapp when pulling in the change that added it to genqlient, so it was not an issue in practice at Khan. But I still felt it was a potential problem!

@benjaminjkraft benjaminjkraft merged commit 1c061b1 into main Sep 9, 2021
@benjaminjkraft benjaminjkraft deleted the benkraft.clean-go-mod branch September 9, 2021 16:23
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.

Clean up go.mod
3 participants