Skip to content

Use the struct-initialization linter more #3121

@eljobe

Description

@eljobe

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions