This is an example linter that can be compiled into a plugin for golangci-lint
.
To use this:
- Download the code *
- From the root project directory, run
go build -buildmode=plugin -o plugin/example.go
. - Copy the generated
example.so
file into your project or to some other known location of your choosing. **
(After the PR this will be either the production code or simpler to get hopefully. For now atleast, you must build this locally because it needs code that hasn't been accepted yet. Additionally, golangci-lint
is built with the vendors option, which breaks plugins that have overlapping dependencies, so a vendor-free version of the code must be used)
- Download the
i473
branch of https://github.com/dbraley/golangci-lint/tree/i473 - From that projects root directy, run
make vendor_free_build
- Copy the
golangci-lint
executable that was created to your path, project, or other location
- If the project you want to lint does not have one already, copy the https://github.com/dbraley/golangci-lint/blob/i473/.golangci.yml to the root directory.
- Adjust the yaml to appropriate
linters-settings:custom
entries as so:
linters-settings:
custom:
example: # If this doesn't match the linters name definition, it will warn you but still run
path: /example.so # Adjust this the location of the plugin
enabled: true # This determines if the linter is run by default
original-url: github.com/dbraley/example-linter # This is just documentation for custom linters
slow: false # Set this to true to observe `--fast` option
- If your
.golangci.yml
file haslinters:disable-all
set to true, you'll also need to add your linter to thelinters:enable
seciont:
linters:
enable:
# ...
- varcheck
- whitespace
# Custom linters
- example
- Alternately, you can leave it disabled and turn it on via command line only:
golangci-lint run -Eexample
Your Linter must implement one or more analysis.Analyzer
structs.
Your project should also use go.mod
. All versions of libraries that overlap golangci-lint
(including replaced libraries) MUST be set to the same version as golangci-lint
. You can see the versions by running go version -m golangci-lint
.
* Sorry, I haven't found a way to enable go get
functionality for plugins yet. If you know how, let me know!
** Alternately, you can use the -o /path/to/location/example.so
output flag to have it put it there for you.