Skip to content

Add a lint for struct constructors #2708

Closed
@elauffenburger

Description

@elauffenburger

Your feature request related to a problem? Please describe.

I've run into runtime bugs when adding a new field to a "service-like" struct (a FooService or something like that), but then I find out someone's instantiating the struct without a constructor so some code somewhere breaks at runtime because of a nil pointer!

Describe the solution you'd like.

I'd love to see two linters created:

  • structs that should have a ctor, which don't have a ctor
  • structs that do have a ctor, but which are instantiated without using the ctor

These linters would definitely want to take regexes that specify the types of structs that we consider to be lintable -- most structs don't have this problem since they're just data and we really don't even want a ctor for them.

Describe alternatives you've considered.

Pray our tests catch this stuff! 🙏

Additional context.

I've written these linters already (and they're useful for me), but I didn't want to create a PR without gauging interest first.

I'm new to this project, so thanks for your patience!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions