Skip to content

golangci/example-plugin-linter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is an example linter that can be compiled into a plugin for golangci-lint.

To use this:

Create the Plugin From This Linter

  1. Download the code *
  2. From the root project directory, run go build -buildmode=plugin -o plugin/example.go.
  3. Copy the generated example.so file into your project or to some other known location of your choosing. **

Create a Copy of golangci-lint that Can Run with Plugins

(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)

  1. Download the i473 branch of https://github.com/dbraley/golangci-lint/tree/i473
  2. From that projects root directy, run make vendor_free_build
  3. Copy the golangci-lint executable that was created to your path, project, or other location

Configure Your Project for Linting

  1. 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.
  2. 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
  1. If your .golangci.yml file has linters:disable-all set to true, you'll also need to add your linter to the linters:enable seciont:
linters:
 enable:
  # ...
  - varcheck
  - whitespace
  # Custom linters
  - example
  1. Alternately, you can leave it disabled and turn it on via command line only: golangci-lint run -Eexample

To Configure Your Own golang.org/x/tools/go/analysis Based Linter

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.

About

Example linter that can be used as a plugin for https://github.com/golangci/golangci-lint

Topics

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%