mirror of
https://github.com/mattermost/mattermost.git
synced 2026-04-14 13:39:08 -04:00
* inline mattermost-govet
* fix style issues
* simplify the openApiSync spec test
* README.md tweaks
* fix missing licenses
* simplify README.md
* trigger server-ci on tools/mattermost-govet/**
* Apply 470cf78253
---------
Co-authored-by: Mattermost Build <build@mattermost.com>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package emptyInterface
|
|
|
|
import (
|
|
"go/ast"
|
|
"strings"
|
|
|
|
"golang.org/x/tools/go/analysis"
|
|
)
|
|
|
|
var Analyzer = &analysis.Analyzer{
|
|
Name: "emptyInterface",
|
|
Doc: "check for usage of interface{} instead of any",
|
|
Run: run,
|
|
}
|
|
|
|
func run(pass *analysis.Pass) (interface{}, error) {
|
|
checkList := []string{
|
|
"Regenerate this file using `make plugin-mocks`.",
|
|
"Regenerate this file using `make store-mocks`.",
|
|
"Regenerate this file using `make sharedchannel-mocks`.",
|
|
}
|
|
|
|
for _, file := range pass.Files {
|
|
comments := ""
|
|
for _, commentGroup := range file.Comments {
|
|
for _, comment := range commentGroup.List {
|
|
comments = comments + comment.Text
|
|
}
|
|
}
|
|
skip := false
|
|
for _, check := range checkList {
|
|
if strings.Contains(comments, check) {
|
|
skip = true
|
|
}
|
|
}
|
|
if skip {
|
|
continue
|
|
}
|
|
|
|
ast.Inspect(file, func(node ast.Node) bool {
|
|
switch x := node.(type) {
|
|
case *ast.InterfaceType:
|
|
if len(x.Methods.List) == 0 {
|
|
pass.Reportf(x.Pos(), "using 'interface{}', please replace it with 'any'.")
|
|
}
|
|
return true
|
|
}
|
|
return true
|
|
})
|
|
}
|
|
return nil, nil
|
|
}
|