Constlit is an analysis package that identifies literal expressions that should be replaced by local or imported constants.
import "image/png"
var enc := png.Encoder{CompressionLevel: -2}
import "image/png"
var enc := png.Encoder{CompressionLevel: png.BestSpeed}
Constlit uses some arbitrary heuristics to avoid making horrible recommendations.
- Only recommend constants from the local package, or from packages it already imports
- Only recommend constants from imported packages that are of a defined type (not untyped, or plain int, etc.)
- Don't recommend constants to replace multiplied literals (i.e. 1 * time.Minute)