You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/docs/contributing/new-linters.mdx
+57-30
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,10 @@
2
2
title: New linters
3
3
---
4
4
5
-
## How to write a custom linter
5
+
## How to write a linter
6
6
7
-
Use `go/analysis` and take a look at [this tutorial](https://disaev.me/p/writing-useful-go-analysis-linter/): it shows how to write `go/analysis` linter
8
-
from scratch and integrate it into `golangci-lint`.
7
+
Use `go/analysis` and take a look at [this tutorial](https://disaev.me/p/writing-useful-go-analysis-linter/):
8
+
it shows how to write `go/analysis` linter from scratch and integrate it into `golangci-lint`.
9
9
10
10
## How to add a public linter to `golangci-lint`
11
11
@@ -16,8 +16,14 @@ After that:
16
16
17
17
1. Implement functional tests for the linter:
18
18
- Add one file into directory [`test/testdata`](https://github.com/golangci/golangci-lint/tree/master/test/testdata).
19
-
- Run `T=yourlintername.go make test_linters` to ensure that test fails.
20
-
- Run `go run ./cmd/golangci-lint/ run --no-config --disable-all --enable=yourlintername ./test/testdata/yourlintername.go`
19
+
- Run the test to ensure that test fails:
20
+
```bash
21
+
T=yourlintername.go make test_linters
22
+
```
23
+
- Run:
24
+
```bash
25
+
go run ./cmd/golangci-lint/ run --no-config --disable-all --enable=yourlintername ./test/testdata/yourlintername.go
26
+
```
21
27
2. Add a new file `pkg/golinters/{yourlintername}.go`.
22
28
Look at other linters in this directory.
23
29
Implement linter integration and check that test passes.
@@ -33,58 +39,79 @@ After that:
33
39
if you think that this project needs not default values.
don't forget about `mapstructure` tag for proper configuration files parsing by [pflag](https://github.com/spf13/pflag).
36
-
5. Take a look at the example of [Pull Request with new linter support](https://github.com/golangci/golangci-lint/pulls?q=is%3Apr+is%3Amerged+label%3A%22linter%3A+new%22).
42
+
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).
37
43
38
44
## How to add a private linter to `golangci-lint`
39
45
40
46
Some people and organizations may choose to have custom-made linters run as a part of `golangci-lint`.
41
47
Typically, these linters can't be open-sourced or too specific.
48
+
42
49
Such linters can be added through Go's plugin library.
43
50
44
51
For a private linter (which acts as a plugin) to work properly,
45
-
the plugin as well as the golangci-lint binary needs to be built for the same environment. `CGO_ENABLED` is another requirement.
52
+
the plugin as well as the golangci-lint binary **needs to be built for the same environment**.
53
+
54
+
`CGO_ENABLED` is another requirement.
55
+
46
56
This means that `golangci-lint` needs to be built for whatever machine you intend to run it on
47
57
(cloning the golangci-lint repository and running a `CGO_ENABLED=1 make build` should do the trick for your machine).
48
58
49
59
### Configure a Plugin
50
60
51
-
If you already have a linter plugin available, you can follow these steps to define it's usage in a projects
52
-
`.golangci.yml` file. An example linter can be found at [here](https://github.com/golangci/example-plugin-linter). If you're looking for
53
-
instructions on how to configure your own custom linter, they can be found further down.
61
+
If you already have a linter plugin available, you can follow these steps to define its usage in a projects `.golangci.yml` file.
62
+
63
+
An example linter can be found at [here](https://github.com/golangci/example-plugin-linter).
64
+
65
+
If you're looking for instructions on how to configure your own custom linter, they can be found further down.
54
66
55
67
1. If the project you want to lint does not have one already, copy the [.golangci.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.yml) to the root directory.
56
68
2. Adjust the yaml to appropriate `linters-settings:custom` entries as so:
0 commit comments