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
+3-71Lines changed: 3 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,75 +46,7 @@ After that:
46
46
Some people and organizations may choose to have custom-made linters run as a part of `golangci-lint`.
47
47
Typically, these linters can't be open-sourced or too specific.
48
48
49
-
Such linters can be added through Go's plugin library.
49
+
Such linters can be added through 2 plugin systems:
50
50
51
-
For a private linter (which acts as a plugin) to work properly,
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
-
56
-
This means that `golangci-lint` needs to be built for whatever machine you intend to run it on
57
-
(cloning the golangci-lint repository and running a `CGO_ENABLED=1 make build` should do the trick for your machine).
58
-
59
-
### Configure a Plugin
60
-
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.
66
-
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.
68
-
2. Adjust the yaml to appropriate `linters-settings:custom` entries as so:
Private linters can be added through [Go's plugin system](https://pkg.go.dev/plugin).
6
+
7
+
For a private linter (which acts as a plugin) to work properly,
8
+
the plugin as well as the golangci-lint binary **needs to be built for the same environment**.
9
+
10
+
`CGO_ENABLED` is another requirement.
11
+
12
+
This means that `golangci-lint` needs to be built for whatever machine you intend to run it on
13
+
(cloning the golangci-lint repository and running a `CGO_ENABLED=1 make build` should do the trick for your machine).
14
+
15
+
## Create a Plugin
16
+
17
+
Your linter must provide one or more `golang.org/x/tools/go/analysis.Analyzer` structs.
18
+
19
+
Your project should also use `go.mod`.
20
+
21
+
All versions of libraries that overlap `golangci-lint` (including replaced libraries) MUST be set to the same version as `golangci-lint`.
22
+
You can see the versions by running `go version -m golangci-lint`.
23
+
24
+
You'll also need to create a Go file like `plugin/example.go`.
25
+
26
+
This file MUST be in the package `main`, and MUST define an exposed function called `New` with the following signature:
27
+
```go
28
+
funcNew(confany) ([]*analysis.Analyzer, error) {
29
+
// ...
30
+
}
31
+
```
32
+
33
+
See [plugin/example.go](https://github.com/golangci/example-plugin-linter/blob/master/plugin/example.go) for more info.
34
+
35
+
To build the plugin, from the root project directory, run:
36
+
```bash
37
+
go build -buildmode=plugin plugin/example.go
38
+
```
39
+
40
+
This will create a plugin `*.so` file that can be copied into your project or another well known location for usage in `golangci-lint`.
41
+
42
+
## Configure a Plugin
43
+
44
+
If you already have a linter plugin available, you can follow these steps to define its usage in a projects `.golangci.yml` file.
45
+
46
+
An example linter can be found at [here](https://github.com/golangci/example-plugin-linter).
47
+
48
+
If you're looking for instructions on how to configure your own custom linter, they can be found further down.
49
+
50
+
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.
51
+
2. Adjust the yaml to appropriate `linters-settings.custom` entries as so:
0 commit comments