Configuration Options
Relevant source files
The following files were used as context for generating this wiki page:
The Duplicate Code Detection Tool provides a flexible configuration system designed to support library usage, command-line interface (CLI) execution, and GitHub Actions integration. Users can fine-tune analysis parameters such as similarity thresholds, file exclusions, and output formats to suit specific code quality requirements.
Configuration options govern how the underlying run function processes source files, including the removal of comments for stricter analysis and the inclusion of Lines of Code (LoC) metrics in reports. These settings ensure the tool can be adapted for various environments, from local development pre-commit hooks to automated CI/CD pipelines.
Sources: core.py:108-125, duplicate_code_detection.py:129-188, README.md:209-220
Core Detection Parameters
The fundamental behavior of the duplication analysis is controlled by threshold settings and file filtering logic. These parameters determine what constitutes a "duplicate" and which files are eligible for comparison.
Threshold Settings
The tool utilizes two primary thresholds to categorize results:
- Fail Threshold: Defines the maximum allowed similarity percentage. Exceeding this value triggers a
THRESHOLD_EXCEEDEDreturn code. - Ignore Threshold: Filters out minor similarities from the output to reduce noise.
File Selection and Filtering
Users can specify target directories or individual files. The tool also supports recursive directory walking while respecting ignore patterns for both files and directories.
| Option | Type | Default | Description |
|---|---|---|---|
fail_threshold | int | 100 | Max similarity (%) before returning an error code. |
ignore_threshold | int | 15 | Similarities below this % are not reported. |
file_extensions | list | [h, c, cpp, py, etc] | Extensions included in the analysis. |
only_code | bool | False | If True, strips comments/docstrings from Python files. |
show_loc | bool | True | Includes line counts for analyzed files. |
Sources: duplicate_code_detection.py:133-188, core.py:128-135, README.md:213-219
Library and CLI Configuration
When using the DuplicateCodeDetector class or the CLI, configurations are passed via constructor arguments or command-line flags.
Class Architecture
The DuplicateCodeDetector acts as a high-level wrapper that encapsulates configuration state and delegates execution to the core logic.
The diagram above illustrates how the configuration parameters are stored within the detector instance and influence the resulting DetectionResult.
Sources: core.py:108-142, duplicate_code_detection.py:129-188
CLI Options Mapping
The CLI maps short and long flags directly to the detection engine parameters:
-t,--fail-threshold: Maps tofail_threshold.-d,--directories: Mutually exclusive with-f.-f,--files: Mutually exclusive with-d.-j,--json: Toggles machine-readable output.
Sources: duplicate_code_detection.py:133-188
GitHub Actions Configuration
For CI/CD integration, configuration is handled via action.yml inputs. The run_action.py script bridges GitHub environment variables to the core detection engine.
Integration Workflow
The workflow involves fetching input variables and formatting the results into Markdown for pull request comments.
The flow shows how configuration inputs travel from the GitHub environment through the action runner to the detection logic.
GitHub-Specific Inputs
| Input Key | Mapping | Default |
|---|---|---|
INPUT_FAIL_ABOVE | fail_threshold | 100 |
INPUT_IGNORE_BELOW | ignore_threshold | 10 |
INPUT_WARN_ABOVE | warn_threshold | 100 |
INPUT_ONLY_CODE | only_code | false |
INPUT_ONE_COMMENT | Update vs Post | false |
Sources: action.yml:4-46, run_action.py:116-150
Output and Formatting Options
The tool supports various output modes, which are configured via the json_output, csv_output, and show_loc flags.
Logic Flow for Reporting
The reporting logic filters data based on the ignore_threshold and appends LoC metadata if show_loc is enabled.
This diagram demonstrates how output configuration flags determine the final data structure presented to the user.
Sources: duplicate_code_detection.py:330-413, core.py:218-266
Summary
Configuration in the Duplicate Code Detection Tool is centralized around the run function, allowing consistent behavior across CLI, library, and Action environments. By adjusting thresholds and filtering options, developers can integrate the tool into various quality gates to ensure code maintainability.