Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

NotificationsYou must be signed in to change notification settings

golangci/example-plugin-linter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

To use this:

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

Create a Copy ofgolangci-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 thei473 branch ofhttps://github.com/dbraley/golangci-lint/tree/i473
  2. From that projects root directy, runmake vendor_free_build
  3. Copy thegolangci-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 thehttps://github.com/dbraley/golangci-lint/blob/i473/.golangci.yml to the root directory.
  2. Adjust the yaml to appropriatelinters-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 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
  1. Alternately, you can leave it disabled and turn it on via command line only:golangci-lint run -Eexample
  2. If everything works correctly, you should see the linter show up as enabled by runninggolangci-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.
  3. You can also see the linter get loaded with the-v option for eitherrun orlinters

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

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:

  1. A variable of typeanalyzerPlugin. The typeanalyzerPlugin can be defined as a string, struct, whatever.
type analyzerPlugin struct{}var AnalyzerPlugin analyzerPlugin
  1. A function with signaturefunc (*analyzerPlugin) GetLinterName() string
  2. A function with signaturefunc (*analyzerPlugin) GetLinterDesc() string
  3. A function with signaturefunc (*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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go100.0%

[8]ページ先頭

©2009-2025 Movatter.jp