Skip to content

Commit

Permalink
docs: improve new linter section (#5066)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Oct 11, 2024
1 parent 944e1d8 commit b91b324
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/new-linter-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In order for a pull request adding a linter to be reviewed, the linter and the P

- [ ] It must not be a duplicate of another linter or a rule of a linter (the team will help to verify that).
- [ ] It must have a valid license (AGPL is not allowed), and the file must contain the required information by the license, ex: author, year, etc.
- [ ] It must use Go version <= 1.21
- [ ] It must use Go version <= 1.22.0
- [ ] The linter repository must have a CI and tests.
- [ ] It must use [`go/analysis`](https://golangci-lint.run/contributing/new-linters/).
- [ ] It must have a valid tag, ex: `v1.0.0`, `v0.1.0`.
Expand Down Expand Up @@ -58,6 +58,7 @@ In order for a pull request adding a linter to be reviewed, the linter and the P
- [ ] The linter should be published as a binary (useful to diagnose bug origins).
- [ ] The linter repository should have a `.gitignore` (IDE files, binaries, OS files, etc. should not be committed)
- [ ] A tag should never be recreated.
- [ ] Use `main` as the default branch name.

---

Expand Down
18 changes: 8 additions & 10 deletions docs/src/docs/contributing/new-linters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,25 @@ After that:

1. Implement functional tests for the linter:
- Add one file into directory `pkg/golinters/{yourlintername}/testdata/`.
- Run the test to ensure that test fails.
- Run:
```bash
go run ./cmd/golangci-lint/ run --no-config --disable-all --enable={yourlintername} ./pkg/golinters/{yourlintername}/testdata/{yourlintername}.go
```
2. Add a new file `pkg/golinters/{yourlintername}/{yourlintername}.go`.
Look at other linters in this directory.
Implement linter integration and check that test passes.
Other linters implementation can help you.
3. Add the new struct for the linter (which you've implemented in `pkg/golinters/{yourlintername}/{yourlintername}.go`) to the
list of all supported linters in [`pkg/lint/lintersdb/builder_linter.go`](https://github.com/golangci/golangci-lint/blob/master/pkg/lint/lintersdb/builder_linter.go)
to the method `LinterBuilder.Build`.
- Add `WithSince("next_version")`, where `next_version` must be replaced by the next minor version. (ex: v1.2.0 if the current version is v1.1.0)
4. Find out what options do you need to configure for the linter.
For example, `nakedret` has only 1 option: [`max-func-lines`](https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml).
Choose default values to not being annoying for users of golangci-lint. Add configuration options to:
- [.golangci.reference.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml) - the example of a configuration file.
- [.golangci.next.reference.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.next.reference.yml): the example of a configuration file.
You can also add them to [.golangci.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.yml)
if you think that this project needs not default values.
- [config struct](https://github.com/golangci/golangci-lint/blob/master/pkg/config/config.go) -
don't forget about `mapstructure` tag for proper configuration files parsing by [pflag](https://github.com/spf13/pflag).
- [config struct](https://github.com/golangci/golangci-lint/blob/master/pkg/config/config.go):
don't forget about `mapstructure` tags for proper configuration files parsing.
5. Take a look at the example of [pull requests with new linter support](https://github.com/golangci/golangci-lint/pulls?q=is%3Apr+is%3Amerged+label%3A%22linter%3A+new%22).
6. Run the tests:
```bash
go run ./cmd/golangci-lint/ run --no-config --disable-all --enable={yourlintername} ./pkg/golinters/{yourlintername}/testdata/{yourlintername}.go
```

## How to add a private linter to `golangci-lint`

Expand Down

0 comments on commit b91b324

Please sign in to comment.