mirror of
https://github.com/hanzoai/team.git
synced 2026-10-30 14:49:35 +00: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 https://github.com/mattermost/mattermost-govet/commit/470cf78253f0aa85a4f4b5b50002682bf823e729 --------- Co-authored-by: Mattermost Build <[email protected]>
44 lines
909 B
Go
44 lines
909 B
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package tFatal
|
|
|
|
import (
|
|
"go/ast"
|
|
|
|
"golang.org/x/tools/go/analysis"
|
|
)
|
|
|
|
var Analyzer = &analysis.Analyzer{
|
|
Name: "tFatal",
|
|
Doc: "check invalid usage of t.Fatal assertions",
|
|
Run: run,
|
|
}
|
|
|
|
func run(pass *analysis.Pass) (interface{}, error) {
|
|
for _, file := range pass.Files {
|
|
ast.Inspect(file, func(node ast.Node) bool {
|
|
switch x := node.(type) {
|
|
case *ast.CallExpr:
|
|
fun, ok := x.Fun.(*ast.SelectorExpr)
|
|
if !ok {
|
|
return true
|
|
}
|
|
|
|
module, ok := fun.X.(*ast.Ident)
|
|
if !ok {
|
|
return true
|
|
}
|
|
|
|
if fun.Sel.Name != "Fatal" || module.Name != "t" {
|
|
return true
|
|
}
|
|
|
|
pass.Reportf(node.Pos(), "t.Fatal usage is not allowed. Use semantic assertions with require or assert modules from testify package.")
|
|
}
|
|
return true
|
|
})
|
|
}
|
|
return nil, nil
|
|
}
|