Output Formats Overview
Relevant source files
The following files were used as context for generating this wiki page:
The Duplicate Code Detection Tool provides several output formats to accommodate different use cases, ranging from human-readable console logs to machine-parsable data for CI/CD pipelines. These formats ensure that similarity analysis results can be easily integrated into developer workflows, automated testing gates, and documentation.
The tool supports four primary output types: structured Python objects for library usage, JSON for automated processing, CSV for spreadsheet reporting, and Markdown specifically designed for GitHub Action comments.
Sources: README.md:94-98, duplicate_code_detection.py:202-282
Structured Data Models
When used as a Python library, the tool returns results through a hierarchy of dataclasses. This is the foundation for all other output formats, providing a structured way to access similarity scores and metadata.
Data Model Hierarchy
The diagram shows the relationship between core result classes, where a single detection run produces multiple file reports, each containing specific similarity pairs.
Sources: core.py:27-104
Key Result Components
| Component | Description | Source File |
|---|---|---|
DetectionResult | The top-level object containing the ReturnCode and a list of reports. | core.py:73-104 |
SimilarityReport | Encapsulates all duplications found for a specific file, including its line count (LoC). | core.py:53-71 |
FileSimilarity | Details the similarity percentage and LoC between a source and target file. | core.py:27-51 |
JSON Output
The JSON format is designed for machine readability and is the primary output for CI/CD integrations. It can be triggered via the -j or --json flag in the CLI or by calling to_json() on a DetectionResult object.
When show_loc is enabled, the JSON structure expands to include nested objects for #LoC (Lines of Code) and Similarity values.
{
"file_path.py": {
"#LoC": 120,
"target_file.py": {
"#LoC": 115,
"Similarity": 85.5
}
}
}
Sources: duplicate_code_detection.py:236-258, core.py:101-104
CSV Reporting
For spreadsheet analysis, the tool generates CSV files via the --csv-output argument. The structure of the CSV changes dynamically based on whether the show_loc flag is active.
CSV Layouts
| Mode | Columns |
|---|---|
| Standard | File A, File B, Similarity |
| With LoC | File A, #LoC A, File B, #LoC B, Similarity |
Sources: duplicate_code_detection.py:265-288
GitHub Action Markdown
The run_action.py module transforms raw similarity data into a formatted Markdown report. This is specifically used to post comments on Pull Requests.
Markdown Structure
- Summary Collapsible: Each analyzed file is placed inside a
<details>block with a<summary>. - Comparison Table: Inside the block, a table displays the target files and their similarity percentages.
- Warning Indicators: Similarities exceeding the
warn_threshold(defined inaction.yml) are appended with a⚠️emoji.
The flow shows how internal data is processed into a GitHub-compatible Markdown table with embedded links to the repository's source code.
Sources: run_action.py:12-108, action.yml:41-52
Console Output
The command-line interface provides colored, human-readable output to the terminal. It uses ANSI escape codes to highlight different severity levels of duplication.
| Similarity Level | Color | ANSI Class |
|---|---|---|
| < 10% | Green | OKGREEN |
| 10% - 20% | Yellow/Orange | WARNING |
| > 20% | Red | FAIL |
The console output includes a header, a formatted table with column labels, and the probability percentage for each file pair.
Sources: duplicate_code_detection.py:38-47, duplicate_code_detection.py:218-261
Conclusion
The Duplicate Code Detection Tool offers a versatile suite of output formats. By supporting structured objects for developers, JSON/CSV for automation and analysis, and specialized Markdown for GitHub Actions, the tool ensures that code duplication data is accessible and actionable across various stages of the software development lifecycle.