Examples of Code Duplication Metrics and Code Smells Severity




Module Acceptance Criteria v2.0: https://github.com/folio-org/tech-council/blob/master/MODULE_ACCEPTANCE_CRITERIA.MD

Example for code Dupliction Detection (an example from  MegaLinter based on jscpd analysing Grails based mod-serials-management (dashboard)) :

┌────────────┬────────────────┬─────────────┬──────────────┬──────────────┬──────────────────┬───────────────────┐
│ Format     │ Files analyzed │ Total lines │ Total tokens │ Clones found │ Duplicated lines │ Duplicated tokens │
├────────────┼────────────────┼─────────────┼──────────────┼──────────────┼──────────────────┼───────────────────┤
│ groovy     │ 96             │ 4890        │ 32306        │ 23           │ 202 (4.13%)      │ 2633 (8.15%)      │
├────────────┼────────────────┼─────────────┼──────────────┼──────────────┼──────────────────┼───────────────────┤
│ properties │ 20             │ 893         │ 3301         │ 0            │ 0 (0%)           │ 0 (0%)            │
├────────────┼────────────────┼─────────────┼──────────────┼──────────────┼──────────────────┼───────────────────┤
│ sql        │ 1              │ 26          │ 261          │ 0            │ 0 (0%)           │ 0 (0%)            │
├────────────┼────────────────┼─────────────┼──────────────┼──────────────┼──────────────────┼───────────────────┤
│ bash       │ 8              │ 231         │ 1343         │ 2            │ 64 (27.71%)      │ 359 (26.73%)      │
├────────────┼────────────────┼─────────────┼──────────────┼──────────────┼──────────────────┼───────────────────┤
│ Total:     │ 125            │ 6040        │ 37211        │ 25           │ 266 (4.4%)       │ 2992 (8.04%)      │
└────────────┴────────────────┴─────────────┴──────────────┴──────────────┴──────────────────┴───────────────────┘
Configuration used to exclude domain classes that cannot be written without duplication:
COPYPASTE_JSCPD_ARGUMENTS: '--ignore-pattern "import .*| *@Defaults.*"'

Sonar example page for raml-module-builder https://sonarcloud.io/summary/overall?id=org.folio%3Araml-module-builder :

Exclude automatically generated code from duplication detection.




Major Code Smells

  • The metric used for module acceptance is the the highest severity level
    • Sonarqube uses the severity levels High - Medium - Low.
    • CodeNarc uses the severity levels Critical - Medium - Minor.
  •