fix: remove telegraflinter from in-tree (#10053)

This commit is contained in:
Joshua Powers 2021-11-03 16:11:47 -06:00 committed by GitHub
parent 00325f20c0
commit b4cafff535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 90 deletions

View File

@ -21,10 +21,6 @@ linters:
- varcheck
linters-settings:
# custom:
# telegraflinter:
# path: telegraflinter.so
# description: "Find Telegraf specific review criteria, more info: https://github.com/influxdata/telegraf/wiki/Review"
revive:
rules:
- name: argument-limit

2
go.mod
View File

@ -291,7 +291,7 @@ require (
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/text v0.3.7
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/tools v0.1.5
golang.org/x/tools v0.1.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
golang.zx2c4.com/wireguard v0.0.20200121 // indirect
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200205215550-e35592f146e4

View File

@ -1,31 +0,0 @@
# Private linter for Telegraf
The purpose of this linter is to enforce the review criteria for the Telegraf project, outlined here: https://github.com/influxdata/telegraf/wiki/Review. This is currently not compatible with the linter running in the CI and can only be ran locally.
## Running it locally
To use the Telegraf linter, you need a binary of golangci-lint that was compiled with CGO enabled. Currently no release is provided with it enabled, therefore you will need to clone the source code and compile it yourself. You can run the following commands to achieve this:
1. `git clone https://github.com/sspaink/golangci-lint.git`
2. `cd golangci-lint`
3. `git checkout tags/v1.39.0 -b 1390`
4. `CGO_ENABLED=true go build -o golangci-lint-cgo ./cmd/golangci-lint`
You will now have the binary you need to run the Telegraf linter. The Telegraf linter will now need to be compiled as a plugin to get a *.so file. [Currently plugins are only supported on Linux, FreeBSD, and macOS](https://golang.org/pkg/plugin/). From the root of the Telegraf project, you can run the following commands to compile the linter and run it:
1. `CGO_ENABLED=true go build -buildmode=plugin telegraflinter/telegraflinter.go`
2. In the .golanci-lint file:
* uncomment the `custom` section under the `linters-settings` section
* uncomment `telegraflinter` under the `enable` section
3. `golanci-lint-cgo run`
*Note:* If you made a change to the telegraf linter and want to run it again, be sure to clear the [cache directory](https://golang.org/pkg/os/#UserCacheDir). On unix systems you can run `rm -rf ~/.cache/golangci-lint` otherwise it will seem like nothing changed.
## Requirement
This linter lives in the Telegraf repository and is compiled to become a Go plugin, any packages used in the linter *MUST* match the version in the golanci-lint otherwise there will be issues. For example the import `golang.org/x/tools v0.1.0` needs to match what golangci-lint is using.
## Useful references
* https://golangci-lint.run/contributing/new-linters/#how-to-add-a-private-linter-to-golangci-lint
* https://github.com/golangci/example-plugin-linter

View File

@ -1,54 +0,0 @@
// This must be package main
package main
import (
"go/ast"
"strings"
"golang.org/x/tools/go/analysis"
)
type analyzerPlugin struct{}
// This must be implemented
func (*analyzerPlugin) GetAnalyzers() []*analysis.Analyzer {
return []*analysis.Analyzer{
TelegrafAnalyzer,
}
}
// This must be defined and named 'AnalyzerPlugin'
var AnalyzerPlugin analyzerPlugin
var TelegrafAnalyzer = &analysis.Analyzer{
Name: "telegraflinter",
Doc: "Find Telegraf specific review criteria, more info: https://github.com/influxdata/telegraf/wiki/Review",
Run: run,
}
func run(pass *analysis.Pass) (interface{}, error) {
for _, file := range pass.Files {
ast.Inspect(file, func(n ast.Node) bool {
checkLogImport(n, pass)
return true
})
}
return nil, nil
}
func checkLogImport(n ast.Node, pass *analysis.Pass) {
if !strings.HasPrefix(pass.Pkg.Path(), "github.com/influxdata/telegraf/plugins/") {
return
}
if importSpec, ok := n.(*ast.ImportSpec); ok {
if importSpec.Path != nil && strings.HasPrefix(importSpec.Path.Value, "\"log\"") {
pass.Report(analysis.Diagnostic{
Pos: importSpec.Pos(),
End: 0,
Category: "log",
Message: "Don't use log package in plugin, use the Telegraf logger.",
SuggestedFixes: nil,
})
}
}
}