Skip to content

Commit

Permalink
docs: add golangci-lint integration info
Browse files Browse the repository at this point in the history
  • Loading branch information
tmzane authored Mar 11, 2023
1 parent 88adc62 commit fd94c3f
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,60 +34,71 @@ The rational from [Uber Style Guide][1]:
## 🚀 Features

`musttag` supports these packages out of the box:
The following packages are supported out of the box:

* `encoding/json`
* `encoding/xml`
* `gopkg.in/yaml.v3`
* `github.com/BurntSushi/toml`
* `github.com/mitchellh/mapstructure`
* ...and any [custom one](#custom-packages)
* [`encoding/json`][2]
* [`encoding/xml`][3]
* [`gopkg.in/yaml.v3`][4]
* [`github.com/BurntSushi/toml`][5]
* [`github.com/mitchellh/mapstructure`][6]

## 📦 Install
In addition, any [custom package](#custom-packages) can be added to the list.

### Go
## 📋 Usage

```shell
go install github.com/junk1tm/musttag/cmd/musttag@latest
```
`musttag` is already integrated into `golangci-lint`, and this is the recommended way to use it.

### Brew
To enable the linter, add the following lines to `.golangci.yml`:

```shell
brew install junk1tm/tap/musttag
```yaml
linters:
enable:
- mustttag
```
### Manual

Download a prebuilt binary from the [Releases][2] page.

## 📋 Usage

As a standalone binary:
If you'd rather prefer to use `musttag` standalone, you can install it via `brew`...

```shell
musttag ./...
brew install junk1tm/tap/musttag
```

Via `go vet`:
...or download a prebuilt binary from the [Releases][8] page.

Then run it either directly or as a `go vet` tool:

```shell
go vet -vettool=$(which musttag) ./...
```

### Custom packages

The `-fn=name:tag:argpos` flag can be used to report functions from custom packages, where
To enable reporting a custom function, you need to add its description to `.golangci.yml`.

The following is an example of adding support for the `sqlx.Get` function from [`github.com/jmoiron/sqlx`][7]:

* `name` is the full name of the function, including the package
* `tag` is the struct tag whose presence should be ensured
* `argpos` is the position of the argument to check
```yaml
linters-settings:
musttag:
functions:
# The full name of the function, including the package.
- name: github.com/jmoiron/sqlx.Get
# The struct tag whose presence should be ensured.
tag: db
# The position of the argument to check.
arg-pos: 1
```

For example, to support the `sqlx.Get` function:
The same can be done via the `-fn=name:tag:arg-pos` flag when using `musttag` standalone:

```shell
musttag -fn="github.com/jmoiron/sqlx.Get:db:1" ./...
```

[1]: https://github.com/uber-go/guide/blob/master/style.md#use-field-tags-in-marshaled-structs
[2]: https://github.com/junk1tm/musttag/releases
[2]: https://pkg.go.dev/encoding/json
[3]: https://pkg.go.dev/encoding/xml
[4]: https://github.com/go-yaml/yaml
[5]: https://github.com/BurntSushi/toml
[6]: https://github.com/mitchellh/mapstructure
[7]: https://github.com/jmoiron/sqlx
[8]: https://github.com/junk1tm/musttag/releases

0 comments on commit fd94c3f

Please sign in to comment.