structinit

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

🧐 StructInit

Go Linter to check struct's field initialization order.

⬇️ Getting Started

Run it as a standalone linter

To install it, run:

go install github.com/manuelarte/testcomments@latest
Run it as a module plugin in golangci-lint

You can integrate this linter with golangci-lint by using the module plugin.

Example of a custom-gcl.yml file that includes this linter:

version: v2.12.2
plugins:
- module: "codeberg.org/manuelarte/structinit"
  import: "codeberg.org/manuelarte/structinit/plugin"
  version: v0.0.1

Feature

By marking a struct with //go:structinit, that indicates that whenever you initialize that struct, the fields need to be initialized in the same order as they are declared in the struct.

//go:structinit
type MyStruct struct {
    Field1 string
    Field2 int

func NewMyStruct() *MyStruct {
    return &MyStruct{
        Field1: "value1",
        Field2: 42,
    }
}

func OtherMyStruct() *MyStruct {
    return &MyStruct{ // Linter will complain about this, since it's expecting Field1 to be initialized first.
        Field2: 42,
  Field1: "value1",
    }
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package analyzer contains the analyzer with the business logic of this linter.
Package analyzer contains the analyzer with the business logic of this linter.
Package plugin add supports to adding this analyzer as a golangci-lint plugin.
Package plugin add supports to adding this analyzer as a golangci-lint plugin.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL