src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

sa4028.go (879B)


      1 package sa4028
      2 
      3 import (
      4 	"honnef.co/go/tools/analysis/code"
      5 	"honnef.co/go/tools/analysis/lint"
      6 	"honnef.co/go/tools/analysis/report"
      7 	"honnef.co/go/tools/pattern"
      8 
      9 	"golang.org/x/tools/go/analysis"
     10 )
     11 
     12 var SCAnalyzer = lint.InitializeAnalyzer(&lint.Analyzer{
     13 	Analyzer: &analysis.Analyzer{
     14 		Name:     "SA4028",
     15 		Run:      run,
     16 		Requires: code.RequiredAnalyzers,
     17 	},
     18 	Doc: &lint.RawDocumentation{
     19 		Title:    `\'x % 1\' is always zero`,
     20 		Since:    "2022.1",
     21 		Severity: lint.SeverityWarning,
     22 		MergeIf:  lint.MergeIfAny, // MergeIfAny if we only flag literals, not named constants
     23 	},
     24 })
     25 
     26 var Analyzer = SCAnalyzer.Analyzer
     27 
     28 var moduloOneQ = pattern.MustParse(`(BinaryExpr _ "%" (IntegerLiteral "1"))`)
     29 
     30 func run(pass *analysis.Pass) (any, error) {
     31 	for node := range code.Matches(pass, moduloOneQ) {
     32 		report.Report(pass, node, "x % 1 is always zero")
     33 	}
     34 	return nil, nil
     35 }