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.
To use this:
- Download the code *
- From the root project directory, run
go build -buildmode=plugin -o plugin/example.go. - Copy the generated
example.sofile 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
i473branch ofhttps://github.com/dbraley/golangci-lint/tree/i473 - From that projects root directy, run
make vendor_free_build - Copy the
golangci-lintexecutable that was created to your path, project, or other location
- If the project you want to lint does not have one already, copy thehttps://github.com/dbraley/golangci-lint/blob/i473/.golangci.yml to the root directory.
- Adjust the yaml to appropriate
linters-settings:customentries 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.ymlfile haslinters:disable-allset to true, you'll also need to add your linter to thelinters:enableseciont:
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 - If everything works correctly, you should see the linter show up as enabled by running
golangci-lint linters. This linter will look for// TODO:in front of functions, so you can also add that to your code and see the errors. - You can also see the linter get loaded with the
-voption for eitherrunorlinters
Your Linter must implement one or moreanalysis.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 want to create a go file likeplugin/example.go. This MUST be in the packagemain, and define:
- A variable of type
analyzerPlugin. The typeanalyzerPlugincan be defined as a string, struct, whatever.
type analyzerPlugin struct{}var AnalyzerPlugin analyzerPlugin- A function with signature
func (*analyzerPlugin) GetLinterName() string - A function with signature
func (*analyzerPlugin) GetLinterDesc() string - A function with signature
func (*analyzerPlugin) GetAnalyzers() []*analysis.Analyzer
* Sorry, I haven't found a way to enablego 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.
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%