CPD (Copy/Paste Detector)

Finding duplicated code.

Version

6.12.0

Runtime

Java Versions

Supported Languages

C C++ C# Go Java JavaScript Kotlin Objective-C PHP Python Ruby Scala Swift

Official Documentation

https://pmd.github.io/pmd-6.6.0/pmd_userdocs_cpd.html

YAML Configuration

cpd:

  • input:

    Patterns to include in execution and reports.

  • ignore:

    Patterns to exclude from execution and reports.

  • auto-fix:

    N/A

  • config-file:

    N/A

  • machine:

    • cpu:

      Amount of CPU. The default machine has 0.5 CPU with 1920 MiB RAM.

      Inspecode configures the maximum heap size of the Java virtual machine (JVM) through HEAPSIZE environment variable according to this value. Inspecode reserves 240 MiB RAM for system, and makes the rest of RAM available to JVM for heap allocation. For example, HEAPSIZE=1680m is exported by default (for 0.5 CPU), HEAPSIZE=5520m is exported for 1.5 CPU.

  • options:

    Below is the list of options that are supported:

    --encoding
       Character encoding to use when processing files
    --exclude
       Files to be excluded from CPD check
    --filelist
       Path to a file containing a list of files to analyze.
    --files
       List of files and directories to process
    --ignore-annotations
       Ignore language annotations when comparing text
       Default: false
    --ignore-identifiers
       Ignore constant and variable names when comparing text
       Default: false
    --ignore-literals
       Ignore number values and string contents when comparing text
       Default: false
    --ignore-usings
       Ignore using directives in C#
       Default: false
    --minimum-tokens
       The minimum token length which should be reported as a duplicate.
       Default: 0
    --no-skip-blocks
       Do not skip code blocks marked with --skip-blocks-pattern (e.g. #if 0
       until #endif)
       Default: false
    --non-recursive
       Don't scan subdirectiories
       Default: false
    --skip-blocks-pattern
       Pattern to find the blocks to skip. Start and End pattern separated by |.
       Default: #if 0|#endif
    --skip-duplicate-files
       Ignore multiple copies of files of the same name and length in comparison
       Default: false
    --skip-lexical-errors
       Skip files which can't be tokenized due to invalid characters instead of
       aborting CPD
       Default: false
    --uri
       URI to process
    
  • thresholds:

    • num-issues:

      No tool specific severity levels are available.

  • experimental:

    • incremental:

      N/A

      Note: The incremental analysis cannot be supported for CPD. This is because unchanged files also need to be compared with changed ones.

YAML Examples

  • With default options:

    inspecode:
      cpd: default
    

    The above configuration is equivalent to:

    inspecode:
      cpd:
        options:
          --files: .
          --minimum-tokens: 100
          --encoding: UTF-8
    
  • With custom machine:

    inspecode:
      cpd:
        machine:
          cpu: 1.5 # 1.5 CPU, 5760 MiB RAM
    
  • With custom options:

    inspecode:
      cpd:
        options:
          --ignore-annotations:
          --minimum-tokens: 50
    

results matching ""

    No results matching ""