This repository contains mattermost-specific go-vet rules that are used to maintain code consistency in mattermost
.
- equalLenAsserts - check for (require/assert).Equal(t, X, len(Y))
- inconsistentReceiverName - check for inconsistent receiver names in the methods of a struct
- license - check the license header
- openApiSync - check for inconsistencies between OpenAPI spec and the source code
- structuredLogging - check invalid usage of logging (must use structured logging)
- tFatal - check invalid usage of t.Fatal assertions (instead of testify methods)
- apiAuditLogs - check that audit records are properly created in the API layer
- rawSql - check invalid usage of raw SQL queries instead of using the squirrel lib
- emptyStrCmp - check for idiomatic empty string comparisons
- pointerToSlice - check for usage of pointer to slice in function definitions
- mutexLock - check for cases where a mutex is left locked before returning
- wrapError - check for original errors being passed as details rather then wrapped
- noSelectStar - check for SQL queries using SELECT * which breaks forwards compatibility
Mattermost Go Vet is designed to run against the mattermost/mattermost
repo. It assumes that you have the mattermost/mattermost
and mattermost/mattermost-govet
in the same top-level directory.
The following can be used to test locally:
# ENV vars
MM_ROOT=</path/to/mattermost/>
MM_GOVET=</path/to/mattermost-govet>
GOBIN=</path/to/go/bin>
API_YAML=$MM_ROOT/api/v4/html/static/mattermost-openapi-v4.yaml
# Make OpenAPI file
if [ ! -f $API_YAML ]; then
make -C $MM_ROOT/api build
fi
# Install
go install $MM_GOVET
# Run
go vet -vettool=$GOBIN/mattermost-govet -openApiSync -openApiSync.spec=$API_YAML ./... 2>&1 || true