Skip to content

Staticcheck

Staticcheck is a state of the art linter for the Go programming language. Using static analysis, it finds bugs and performance issues, offers simplifications, and enforces style rules.

Tools

Install

go install honnef.co/go/tools/cmd/staticcheck@latest

$GOPATH/bin에 설치된다. staticcheck 를 명령행에서 실행하면 된다.

Usage

그냥 Go 파일들 있는 위치 넣어주면 된다.

staticcheck ./cmd/edge/

문제가 있다면 다음과 같이 에러가 출력된다:

cmd/edge/main.go:541:23: Printf format %s has arg #1 of wrong type int64 (SA5009)

run script example

하위 폴더를 재귀적으로 찾게 하기 위해 ./lib/... 처럼 입력하면 된다:

#!/usr/bin/env bash

ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" || exit; pwd)

if ! command -v go &> /dev/null; then
    echo "Not found go command" 1>&2
    exit 1
fi

staticcheck \
    "$ROOT_DIR/lib/..." \
    "$ROOT_DIR/cmd/..."

Warnings

출력되는 에러 또는 경고 목록에 대한 대응 방안 정리.

wrong type for method ProtoReflect

자세한 내용은 Protocol Buffers#wrong type for method ProtoReflect 항목 확인.

See also

Favorite site