/dupl

a tool for code clone detection

Primary LanguageGoMIT LicenseMIT

dupl Build Status

dupl is a tool for finding code clones written in Go. So far it can find clones only in the Go source files. The method uses suffix tree for serialized ASTs. It ignores values of AST nodes, it cares just about the types.

Installation

go get -u github.com/mibk/dupl

To be built, dupl requires Go 1.4 or later.

Usage

Usage of dupl:
  dupl [flags] [paths]

Paths:
  If the given path is a file, dupl will use it regardless of
  the file extension. If it is a directory it will recursively
  search for *.go files in that directory.

  If no path is given dupl will recursively search for *.go
  files in the current directory.

Flags:
  -c, -connect addr:port
        connect to the given 'addr:port'
  -files
        read file names from stdin one at each line
  -html
        output the results as HTML, including duplicate code fragments
  -plumbing
        plumbing (easy-to-parse) output for consumption by scripts or tools
  -serve port
        run server at port
  -t, -threshold size
        minimum token sequence size as a clone (default 15)
  -v, -verbose
        explain what is being done

Examples:
  dupl -t 100
        Search clones in the current directory of size at least
        100 tokens.
  dupl $(find app/ -name '*_test.go')
        Search for clones in tests in the app directory.
  find app/ -name '*_test.go' |dupl -files
        The same as above.

Example

The reduced output of this command with the following parameters for the Docker source code looks like this.

$ dupl -t 200 -html >docker.html