Reporters

Badge reporter

Two SVG badges with the duplication and the duplicated lines of a run, for a README.

-r badge writes shields-style SVGs that show the numbers of the last run with no badge service in between: commit them or publish them from CI and link them from the README. The color of the duplication badge follows the percentage, so a README shows at a glance whether the project sits below 10%, below 20% or above.

Run it

Terminal
jscpd . -r badge --output report
Badge saved to report/jscpd-badge.svg
Terminal
ls report
jscpd-badge.svg
jscpd-lines-badge.svg
.jscpd.json
{
  "reporters": ["console", "badge"],
  "output": "report"
}

The output

FileLabelValueColor
jscpd-badge.svgduplicationthe duplication of the run, 17.7% heregreen up to 10%, orange above 10%, red above 20%
jscpd-lines-badge.svgdup linesthe duplicated lines, 34 hereblue

Each badge is a 20 px high SVG with the label on grey and the value on the color, in 11 px DejaVu Sans. The file below is the duplication badge of the sample run without its gradient and shadow text:

report/jscpd-badge.svg
<svg xmlns="http://www.w3.org/2000/svg" width="132" height="20">
  <rect rx="3" width="132" height="20" fill="#555"/>
  <rect rx="3" x="87" width="45" height="20" fill="#f39c12"/>
  <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11">
    <text x="43" y="14">duplication</text>
    <text x="109" y="14">17.7%</text>
  </g>
</svg>

Where it shows up

README.md
![duplication](./report/jscpd-badge.svg)

The image has to be reachable from the README: commit the file after a local run, or let the CI job that runs jscpd commit or publish it.

With gates

The badges show numbers only. --threshold and a baseline do not change them; --kind does, because the statistics follow the clones that are reported. --health -r badge writes a third file, jscpd-health-badge.svg, with the grade and score of the health score (health | B 73): green for A and B, yellow for C, orange for D and red for E.

Options

The badge reporter reads -o/--output only. CLI options lists it with the rest.

  • Reporters for the other formats.
  • Dashboard for --dashboard, which writes the health badge too.