Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7
Example linter that can be used as a plugin forhttps://github.com/golangci/golangci-lint
golangci/example-plugin-linter
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is an example linter that can be compiled into a plugin forgolangci-lint.
- Download the source code
- From the root project directory, run
go build -buildmode=plugin plugin/example.go. - Copy the generated
example.sofile into your project or to some other known location of your choosing.1
In order to use plugins, you'll need a golangci-lint executable that can run them.
Plugin dependencies defined in thego.mod file MUST have a matching version (or hash) as the same dependency in thgolangci-lint binary if the dependency is used in both.
Because of the high probability of this both using the same dependency, it is recommended to use a locally built binary.
To do so:
- Downloadgolangci-lint source code
- From the projects root directory, run
make build - Copy the
golangci-lintexecutable that was created to your path, project, or other location
If you already have a linter plugin available, you can follow these steps to define its usage in a projects.golangci.yml file.
If you're looking for instructions on how to configure your own custom linter, they can be found further down.
- If the project you want to lint does not have one already, copy the.golangci.yml to the root directory.
- Adjust the YAML to appropriate
linters-settings.customentries as so:linters:settings:custom:example:path:/example.sodescription:The description of the linteroriginal-url:github.com/golangci/example-lintersettings:# Settings are optional.one:Footwo: -name:Barthree:name:Bar
That is all the configuration that is required to run a custom linter in your project.
Custom linters are enabled by default, but abide by the same rules as other linters.
If the disable all option is specified either on command line or in.golang.yml fileslinters.disable-all: true, custom linters will be disabled;they can be re-enabled by adding them to thelinters.enable list,or providing the enabled option on the command line,golangci-lint run -Eexample.
The configuration inside thesettings field of linter have some limitations (there are NOT related to the plugin system itself):we use Viper to handle the configuration but Viper put all the keys in lowercase, and. cannot be used inside a key.
Your linter must provide one or moregolang.org/x/tools/go/analysis.Analyzer structs.
Your project should also usego.mod.
All versions of libraries that overlapgolangci-lint (including replaced libraries) MUST be set to the same version asgolangci-lint.You can see the versions by runninggo version -m golangci-lint.
You'll also need to create a Go file likeplugin/example.go.
This file MUST be in the packagemain, and MUST define an exposed function calledNew with the following signature:
funcNew(confany) ([]*analysis.Analyzer,error) {// ...}
Seeplugin/example.go for more info.
To build the plugin, from the root project directory, run:
go build -buildmode=plugin plugin/example.go
This will create a plugin*.so file that can be copied into your project or another well known location for usage ingolangci-lint.
Footnotes
Alternately, you can use the
-o /path/to/location/example.sooutput flag to have it put it there for you.↩
About
Example linter that can be used as a plugin forhttps://github.com/golangci/golangci-lint
Topics
Resources
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Languages
- Go100.0%