Skip to main content

PMD CPD

note

This is BETA. The behavior of this tool might change.

Supported VersionLanguageWebsite
6.36.0Programming languageshttps://pmd.github.io

PMD CPD is the copy-paste detector shipped with PMD. CPD works with Java, JSP, C/C++, C#, Go, Kotlin, Ruby, Swift and many more languages.

Getting Started#

To start using PMD CPD, enable it in your repository settings.

Configuration#

You can customize the analysis via sider.yml:

linter:  pmd_cpd:    minimum-tokens: 70    target: src    language: cpp    encoding: UTF-8    skip-duplicate-files: true    non-recursive: true    skip-lexical-errors: true    ignore-annotations: true    ignore-identifiers: true    ignore-literals: true    ignore-usings: true    no-skip-blocks: true    skip-blocks-pattern: "#ifdef TEST|#endif"
NameTypeDefault
root_dirstring-
minimum-tokensnumber100
targetstring, string[].
languagestring, string[](see below)
encodingstring(PMD's default)
skip-duplicate-filesbooleanfalse
non-recursivebooleanfalse
skip-lexical-errorsbooleanfalse
ignore-annotationsbooleanfalse
ignore-identifiersbooleanfalse
ignore-literalsbooleanfalse
ignore-usingsbooleanfalse
no-skip-blocksbooleanfalse
skip-blocks-patternstring(PMD's default)

minimum-tokens#

The minimum token length which should be reported as a duplicate.

target#

This option allows you to specify files or directories to be analyzed.

alias: files

language#

This option allows you to specify one or more languages you want to analyze, e.g.:

linter:  pmd_cpd:    language: cpp    # or    # language: [cpp, java, python]

Here are available:

  • apex
  • cpp *
  • cs *
  • dart
  • ecmascript *
  • fortran
  • go *
  • groovy
  • java *
  • jsp
  • kotlin *
  • lua
  • matlab
  • modelica
  • objectivec
  • perl
  • php *
  • plsql
  • python *
  • ruby *
  • scala
  • swift *
  • vf
  • xml

The default languages marked with * are used if you omit the option.

See also the PMD CPD document.

encoding#

This option allows you to specify an encoding of your source code.

skip-duplicate-files#

This option allows you to ignore multiple copies of files of the same name and length in comparison.

non-recursive#

If you do not want to analyze the sub-directories, set this option to true.

skip-lexical-errors#

If you want to skip files which cannot be tokenized due to invalid characters, set this option to true.

ignore-annotations#

(Java only) If you want to ignore annotations on classes and methods, set this option to true.

ignore-identifiers#

(Java only) If you want to ignore constant and variable names, set this option to true.

ignore-literals#

(Java only) If you want to ignore number values and string contents, set this option to true.

ignore-usings#

(C# only) If you want to ignore using directives, set this option to true.

no-skip-blocks#

(C/C++ only) If you do not want to skip code blocks matched by the skip-blocks-pattern option, set this option to true.

skip-blocks-pattern#

(C/C++ only) You can configure the pattern, to find the blocks to skip:

linter:  pmd_cpd:    language: c    skip-blocks-pattern: "#ifdef TEST|#endif"

This option value consists of two parts, separated by |. The first part is the start pattern, the second part is the ending pattern.