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
+20-16
Original file line number
Diff line number
Diff line change
@@ -9,31 +9,35 @@ from scratch and integrate it into `golangci-lint`.
9
9
10
10
## How to add a public linter to `golangci-lint`
11
11
12
-
You need to implement a new linter using `go/analysis` API. We don't accept not `go/analysis` linters.
12
+
You need to implement a new linter using `go/analysis` API.
13
+
We don't accept not `go/analysis` linters.
13
14
14
15
After that:
15
16
16
-
1. Implement functional tests for the linter: add one file into directory [`test/testdata`](https://github.com/golangci/golangci-lint/tree/master/test/testdata).
17
-
Run `T=yourlintername.go make test_linters` to ensure that test fails.
18
-
2. Add a new file `pkg/golinters/{yourlintername}.go`. Look at other linters in this directory. Implement linter integration and check that test passes.
17
+
1. Implement functional tests for the linter:
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`
21
+
2. Add a new file `pkg/golinters/{yourlintername}.go`.
22
+
Look at other linters in this directory.
23
+
Implement linter integration and check that test passes.
19
24
3. Add the new struct for the linter (which you've implemented in `pkg/golinters/{yourlintername}.go`) to the
20
25
list of all supported linters in [`pkg/lint/lintersdb/manager.go`](https://github.com/golangci/golangci-lint/blob/master/pkg/lint/lintersdb/manager.go)
21
-
to the function `GetAllSupportedLinterConfigs`. Enable it by default only if you are sure.
22
-
4. Find out what options do you need to configure for the linter. For example, `nakedret` has
23
-
only 1 option: [`max-func-lines`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml).
26
+
to the function `GetAllSupportedLinterConfigs`.
27
+
- 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)
28
+
4. Find out what options do you need to configure for the linter.
29
+
For example, `nakedret` has only 1 option: [`max-func-lines`](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml).
24
30
Choose default values to not being annoying for users of golangci-lint. Add configuration options to:
25
-
26
-
-[.golangci.example.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml) - the example of a configuration file. You can also add
27
-
them to [.golangci.yml](https://github.com/golangci/golangci-lint/blob/master/.golangci.yml) if you think
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).
33
37
34
38
## How to add a private linter to `golangci-lint`
35
39
36
-
Some people and organizations may choose to have custommade linters run as a part of `golangci-lint`.
40
+
Some people and organizations may choose to have custom-made linters run as a part of `golangci-lint`.
37
41
Typically, these linters can't be open-sourced or too specific.
38
42
Such linters can be added through Go's plugin library.
0 commit comments