Reporters
OpenMetrics Reporter
Generate OpenMetrics reports for GitLab CI metrics integration.
Installation
The OpenMetrics reporter is included in jscpd v5 by default — no separate installation needed.
Usage
jscpd --reporters openmetrics ./src
Output file: ./report/jscpd-metrics.txt
The file follows the OpenMetrics text exposition format (a superset of the Prometheus text format), so it can be consumed by GitLab CI metrics reports, Prometheus tooling, or any OpenMetrics-compatible parser.
Exposed Metrics
Each metric is a gauge with an unlabeled sample for the project total, plus one format="..." labeled sample per detected format:
| Metric | Description |
|---|---|
jscpd_source_files | Number of source files analyzed |
jscpd_lines_analyzed | Total number of lines analyzed |
jscpd_tokens_analyzed | Total number of tokens analyzed |
jscpd_clones_found | Number of duplicated code blocks found |
jscpd_duplicated_lines | Number of duplicated lines |
jscpd_duplicated_tokens | Number of duplicated tokens |
jscpd_new_clones | Number of duplicated code blocks absent from the configured baseline (0 without --baseline) |
jscpd_new_duplicated_lines | Number of duplicated lines in clones absent from the configured baseline (0 without --baseline) |
jscpd_duplicated_lines_percent | Percentage of duplicated lines |
jscpd_duplicated_tokens_percent | Percentage of duplicated tokens |
jscpd_detection_duration_seconds | Time spent detecting duplicates (total only) |
Example output:
# HELP jscpd_duplicated_lines Number of duplicated lines.
# TYPE jscpd_duplicated_lines gauge
jscpd_duplicated_lines 132
jscpd_duplicated_lines{format="javascript"} 120
jscpd_duplicated_lines{format="css"} 12
# HELP jscpd_duplicated_lines_percent Percentage of duplicated lines.
# TYPE jscpd_duplicated_lines_percent gauge
# UNIT jscpd_duplicated_lines_percent percent
jscpd_duplicated_lines_percent 8.63
# EOF
GitLab CI Metrics Integration
Declare the output file as a metrics report artifact and GitLab shows metric changes directly in merge requests:
.gitlab-ci.yml
jscpd:
script:
- jscpd --reporters openmetrics --output ./reports .
artifacts:
reports:
metrics: reports/jscpd-metrics.txt
Merge requests then display how each metric (duplicated lines, duplication percentage, …) changed compared to the target branch.
Configuration
.jscpd.json
{
"reporters": ["openmetrics"],
"output": "./reports"
}