Skip to content

About

Tool for suggesting Go code refactoring

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

gorefactor

A Go tool that finds duplicated string literals in Go source files.

Project Structure

.
├── cmd/
│   └── gorefactor/       # Main application entry point
│       └── main.go
├── pkg/
│   └── duplicates/       # Core logic for finding duplicated literals
│       ├── duplicates.go
│       └── duplicates_test.go
├── Makefile              # Build automation
└── go.mod

Usage

Build the tool:

make build

Or using go directly:

go build -o gorefactor ./cmd/gorefactor

Run it on a Go file:

./gorefactor <path-to-go-file>

Example:

./gorefactor cmd/gorefactor/main.go
./gorefactor pkg/duplicates/duplicates.go

Makefile Targets

  • make build - Build the gorefactor binary (default)
  • make clean - Remove the binary
  • make test - Run tests
  • make install - Install to GOPATH/bin

Testing

Run the test suite:

make test

Or using go directly:

go test -v ./...

The test suite includes:

  • Finding duplicates in test files
  • Handling files with no duplicates
  • Error handling for invalid files
  • Error handling for invalid Go code
  • Multiple duplicate detection

How it works

The tool:

  1. Parses the provided Go file into an AST using Go's standard library (pkg/duplicates)
  2. Walks the AST to collect all string literals and their line numbers
  3. Identifies literals that appear more than once (exact string match)
  4. Outputs the duplicated literals with their locations (cmd/gorefactor)

Example Output

Duplicate string literals found:

String: "Hello, World!"
  Found 3 times at lines: [6 7 12]

String: "example"
  Found 2 times at lines: [5 9]

About

Tool for suggesting Go code refactoring

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages