Skip to content

Latest commit

 

History

History
27 lines (17 loc) · 694 Bytes

README.md

File metadata and controls

27 lines (17 loc) · 694 Bytes

constlit

Constlit is an analysis package that identifies literal expressions that should be replaced by local or imported constants.

Before

import "image/png"

var enc := png.Encoder{CompressionLevel: -2}

After

import "image/png"

var enc := png.Encoder{CompressionLevel: png.BestSpeed}

Notes

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)