Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ysuzuki19/robustruct

Go Lint tool for struct
https://github.com/ysuzuki19/robustruct

Last synced: 20 days ago
JSON representation

Go Lint tool for struct

Awesome Lists containing this project

README

        

# robustruct

Go Lint tool for struct

This tool is module plugin for `golangci-lint`.

# Features

- `fields_require`
- Check all fields are initialized
- Suggest to use zero value
- `fields_align`
- Check all fields are aligned ordered by struct definition
- Suggest to align fields

# Sample

for the following code, robustruct will suggest the following fixes.

```go
package main

type Sample struct {
A int
B string
AA bool
}
```

## fields_require

Before fix

```go
func main() {
s := Sample{
A: 1,
B: "hello",
}
}
```

After fix

```go
func main() {
s := Sample{
A: 1,
B: "hello",
AA: false,
}
}
```

## fields_align

Before fix

```go
func main() {
s := Sample{
B: "hello",
A: 1,
AA: false,
}
}
```

After fix

```go
func main() {
s := Sample{
A: 1,
B: "hello",
AA: false,
}
}
```

# Ignore

You can disable a check with a comment.

ignore all features.

```go
// ignore:robustruct
```

ignore `fields_require`.

```go
// ignore:fields_require
```

ignore `fields_align`.

```go
// ignore:fields_align
```

## Sample

```go
func main() {
// ignore:robustruct
s := Sample{
B: "hello",
A: 1,
}
}
```

```go
func main() {
s := Sample{
A: 1,
B: "hello",
} // ignore:fields_require
}
```