Search documentation of Metastatic

# mix metastatic.detect_duplicates (Metastatic v0.2.0)

View Source

Detects code duplication across MetaAST documents.

This task analyzes one or more files for code duplication, supporting cross-language detection when files are parsed to MetaAST.

## Usage

    mix metastatic.detect_duplicates FILE1 FILE2 [OPTIONS]
    mix metastatic.detect_duplicates --dir PATH [OPTIONS]

## Options

- `--format FORMAT` - Output format: text (default), json, or detailed
- `--threshold FLOAT` - Similarity threshold for Type III detection (default: 0.8)
- `--output PATH` - Write output to file instead of stdout
- `--cross-language` - Enable cross-language detection (default: true)
- `--dir PATH` - Scan all files in directory recursively
- `--help` - Display this help message

## Examples

    # Detect duplicates between two files
    mix metastatic.detect_duplicates lib/foo.ex lib/bar.ex

    # Scan entire directory
    mix metastatic.detect_duplicates --dir lib/

    # Output as JSON with custom threshold
    mix metastatic.detect_duplicates lib/foo.ex lib/bar.ex --format json --threshold 0.85

    # Save detailed report to file
    mix metastatic.detect_duplicates --dir lib/ --format detailed --output report.txt

## Note

This task currently works with MetaAST documents. Language adapter support (to parse real source files) will be added in future phases.

For now, you can use this task programmatically via the API:

    alias Metastatic.{Document, Analysis.Duplication}

    # Create documents
    doc1 = Document.new(ast1, :elixir)
    doc2 = Document.new(ast2, :python)

    # Detect duplicates
    {:ok, result} = Duplication.detect(doc1, doc2)

    # Or detect across multiple documents
    {:ok, groups} = Duplication.detect_in_list([doc1, doc2, doc3])