No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2018-06-10 17:16:41 +03:00
cmd/goconst Support multiple arg paths. (#3) 2017-07-03 19:01:52 +02:00
LICENSE Create LICENSE 2015-12-25 23:26:14 +01:00
parser.go accept ast.File-s 2018-06-10 17:16:41 +03:00
README.md Implement -min-length, closes #2 2016-05-14 21:25:19 +02:00
visitor.go Implement -min-length, closes #2 2016-05-14 21:25:19 +02:00

goconst

Find repeated strings that could be replaced by a constant.

Motivation

There are obvious benefits to using constants instead of repeating strings, mostly to ease maintenance. Cannot argue against changing a single constant versus many strings.

While this could be considered a beginner mistake, across time, multiple packages and large codebases, some repetition could have slipped in.

Get Started

$ go get github.com/jgautheron/goconst/cmd/goconst
$ goconst ./...

Usage

Usage:

  goconst ARGS <directory>

Flags:

  -ignore            exclude files matching the given regular expression
  -ignore-tests      exclude tests from the search (default: true)
  -min-occurrences   report from how many occurrences (default: 2)
  -min-length        only report strings with the minimum given length (default: 3)
  -match-constant    look for existing constants matching the values
  -numbers           search also for duplicated numbers
  -min          	   minimum value, only works with -numbers
  -max          	   maximum value, only works with -numbers
  -output            output formatting (text or json)

Examples:

  goconst ./...
  goconst -ignore "yacc|\.pb\." $GOPATH/src/github.com/cockroachdb/cockroach/...
  goconst -min-occurrences 3 -output json $GOPATH/src/github.com/cockroachdb/cockroach
  goconst -numbers -min 60 -max 512 .

Other static analysis tools

  • gogetimports: Get a JSON-formatted list of imports.
  • usedexports: Find exported variables that could be unexported.

License

MIT