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:

MetricDescription
jscpd_source_filesNumber of source files analyzed
jscpd_lines_analyzedTotal number of lines analyzed
jscpd_tokens_analyzedTotal number of tokens analyzed
jscpd_clones_foundNumber of duplicated code blocks found
jscpd_duplicated_linesNumber of duplicated lines
jscpd_duplicated_tokensNumber of duplicated tokens
jscpd_new_clonesNumber of duplicated code blocks absent from the configured baseline (0 without --baseline)
jscpd_new_duplicated_linesNumber of duplicated lines in clones absent from the configured baseline (0 without --baseline)
jscpd_duplicated_lines_percentPercentage of duplicated lines
jscpd_duplicated_tokens_percentPercentage of duplicated tokens
jscpd_detection_duration_secondsTime 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"
}