Skip to content

Use the struct-initialization linter more #3121

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
eljobe opened this issue Apr 10, 2025 · 0 comments
Open

Use the struct-initialization linter more #3121

eljobe opened this issue Apr 10, 2025 · 0 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@eljobe
Copy link
Member

eljobe commented Apr 10, 2025

In much of the go codebase, we use and initialize structs.

In most of those places, we should really ensure that all fields on the struct are explicitly initialized. This helps to ensure that new fields on structs aren't just silently getting the zero value for that type without anyone noticing.

We can annotate each struct initialization with:

// lint:require-exhaustive-initialization

To ensure that structs are exhaustively initialized.

One example of this is:

// lint:require-exhaustive-initialization

But, that's just in the linter test. We want to start adopting this in more places in our codebase with the eventual goal of making the linter-opt out once the majority of struct initializations are exhaustive.

If you open a PR to add this annotation to a struct, be sure to reference this issue in the commit comment.

@eljobe eljobe added the good first issue Good for newcomers label Apr 10, 2025
@eljobe eljobe self-assigned this Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant