/wrapmsg

Linter for Go's fmt.Errorf message

Primary LanguageGoMIT LicenseMIT

wrapmsg

Coverage Status

wrapmsg is Go code linter. this enforces fmt.Errorf's message when you wrap error.

Example

// OK 👍🏻
if err := pkg.Cause(); err != nil {
  return fmt.Errorf("pkg.Cause: %w", err)
}

// NG 🙅
if err := pkg.Cause(); err != nil {
  return fmt.Errorf("cause failed: %w", err)
}

Install

go install github.com/Warashi/wrapmsg/cmd/wrapmsg@latest

Usage

You can use wrapmsg as vettool.

go vet -vettool=$(which wrapmsg) ./...

You can also build your linter with singlechecker or multichecker. In this way, you can use --fix option to autocorrect.

package main

import (
	"github.com/Warashi/wrapmsg"
	"golang.org/x/tools/go/analysis/singlechecker"
)

func main() {
	singlechecker.Main(wrapmsg.Analyzer)
}