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
2. From the projects root directory, run `make vendor_free_build`
1051
+
3. Copy the `golangci-lint` executable that was created to your path, project, or other location
1052
+
1053
+
### Configure Your Project for Linting
1054
+
If you already have a linter plugin available, you can follow these steps to define it's usage in a projects
1055
+
`.golangci.yml` file. An example linter can be found at [here](https://github.com/golangci/example-plugin-linter). If you're looking for
1056
+
instructions on how to configure your own custom linter, they can be found further down.
1057
+
1058
+
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.
1059
+
2. Adjust the yaml to appropriate `linters-settings:custom` entries as so:
1060
+
```
1061
+
linters-settings:
1062
+
custom:
1063
+
example:
1064
+
path: /example.so
1065
+
description: The description of the linter
1066
+
original-url: github.com/golangci/example-linter
1067
+
```
1068
+
1069
+
That is all the configuration that is required to run a custom linter in your project. Custom linters are enabled by default,
1070
+
but abide by the same rules as other linters. If the disable all option is specified either on command line or in
1071
+
`.golang.yml` files `linters:disable-all: true`, custom linters will be disabled; they can be re-enabled by adding them
1072
+
to the `linters:enable` list, or providing the enabled option on the command line, `golangci-lint run -Eexample`.
1073
+
1074
+
### To Create Your Own Custom Linter
1075
+
1076
+
Your linter must implement one or more `golang.org/x/tools/go/analysis.Analyzer` structs.
1077
+
Your project should also use `go.mod`. All versions of libraries that overlap `golangci-lint` (including replaced
1078
+
libraries) MUST be set to the same version as `golangci-lint`. You can see the versions by running `go version -m golangci-lint`.
1079
+
1080
+
You'll also need to create a go file like `plugin/example.go`. This MUST be in the package `main`, and define a
1081
+
variable of name `AnalyzerPlugin`. The `AnalyzerPlugin` instance MUST implement the following interface:
1082
+
```
1083
+
type AnalyzerPlugin interface {
1084
+
GetAnalyzers() []*analysis.Analyzer
1085
+
}
1086
+
```
1087
+
The type of `AnalyzerPlugin` is not important, but is by convention `type analyzerPlugin struct {}`. See
1088
+
[plugin/example.go](https://github.com/golangci/example-plugin-linter/plugin/example.go) for more info.
1089
+
1090
+
To build the plugin, from the root project directory, run `go build -buildmode=plugin plugin/example.go`. This will create a plugin `*.so`
1091
+
file that can be copied into your project or another well known location for usage in golangci-lint.
1092
+
1029
1093
## False Positives
1030
1094
1031
1095
False positives are inevitable, but we did our best to reduce their count. For example, we have a default enabled set of [exclude patterns](#command-line-options). If a false positive occurred you have the following choices:
2. From the projects root directory, run `make vendor_free_build`
468
+
3. Copy the `golangci-lint` executable that was created to your path, project, or other location
469
+
470
+
### Configure Your Project for Linting
471
+
If you already have a linter plugin available, you can follow these steps to define it's usage in a projects
472
+
`.golangci.yml` file. An example linter can be found at [here](https://github.com/golangci/example-plugin-linter). If you're looking for
473
+
instructions on how to configure your own custom linter, they can be found further down.
474
+
475
+
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.
476
+
2. Adjust the yaml to appropriate `linters-settings:custom` entries as so:
477
+
```
478
+
linters-settings:
479
+
custom:
480
+
example:
481
+
path: /example.so
482
+
description: The description of the linter
483
+
original-url: github.com/golangci/example-linter
484
+
```
485
+
486
+
That is all the configuration that is required to run a custom linter in your project. Custom linters are enabled by default,
487
+
but abide by the same rules as other linters. If the disable all option is specified either on command line or in
488
+
`.golang.yml` files `linters:disable-all: true`, custom linters will be disabled; they can be re-enabled by adding them
489
+
to the `linters:enable` list, or providing the enabled option on the command line, `golangci-lint run -Eexample`.
490
+
491
+
### To Create Your Own Custom Linter
492
+
493
+
Your linter must implement one or more `golang.org/x/tools/go/analysis.Analyzer` structs.
494
+
Your project should also use `go.mod`. All versions of libraries that overlap `golangci-lint` (including replaced
495
+
libraries) MUST be set to the same version as `golangci-lint`. You can see the versions by running `go version -m golangci-lint`.
496
+
497
+
You'll also need to create a go file like `plugin/example.go`. This MUST be in the package `main`, and define a
498
+
variable of name `AnalyzerPlugin`. The `AnalyzerPlugin` instance MUST implement the following interface:
499
+
```
500
+
type AnalyzerPlugin interface {
501
+
GetAnalyzers() []*analysis.Analyzer
502
+
}
503
+
```
504
+
The type of `AnalyzerPlugin` is not important, but is by convention `type analyzerPlugin struct {}`. See
505
+
[plugin/example.go](https://github.com/golangci/example-plugin-linter/plugin/example.go) for more info.
506
+
507
+
To build the plugin, from the root project directory, run `go build -buildmode=plugin plugin/example.go`. This will create a plugin `*.so`
508
+
file that can be copied into your project or another well known location for usage in golangci-lint.
509
+
458
510
## False Positives
459
511
460
512
False positives are inevitable, but we did our best to reduce their count. For example, we have a default enabled set of [exclude patterns](#command-line-options). If a false positive occurred you have the following choices:
0 commit comments