Skip to content

A linter to prevent initializing structs without naming fields #6208

@mitar

Description

@mitar

Welcome

How did you install golangci-lint?

Official binary

Your feature request related to a problem? Please describe

Go supports initializing structs without naming fields in which case it maps values to fields in field-definition order:

type S struct {
    A string
    B string
}

It allows creating an instance of the struct by doing S{"a", "b"} instead of S{A: "a", B: "b"}.

Describe the solution you'd like

I think initializing structs without naming fields is fragile and I would like to request a linter which would complain about it (and potentially autofix by adding fields).

Describe alternatives you've considered

Code style for our projects could require developers not to use short style, but it is best if a linter can check for that.

Additional context

No response

Supporter

  • I am a sponsor through thanks.dev

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions