ExDNA.Credo (ExDNA v1.5.1)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of higher and works with any version of Elixir.

Explanation

Code should not be copy-pasted in a codebase when there is room to abstract the copied functionality in a meaningful way.

ExDNA detects three types of clones:

  • Type I — exact copies (modulo whitespace/comments)
  • Type II — same structure with renamed variables or different literals
  • Type III — near-miss clones (similar structure with minor edits)

Each clone comes with a refactoring suggestion: extract function, extract macro, or extract behaviour.

Run mix ex_dna.explain N for a detailed breakdown of any clone.

Check-Specific Parameters

Use the following parameters to configure this check:

:min_mass

Minimum AST node count for a code fragment to be considered.

This parameter defaults to 30.

:min_occurrences

Minimum number of code occurrences to label a clone

This parameter defaults to 2.

:literal_mode

keep for exact clones only (Type-I), abstract to also detect renamed-variable clones (Type-II).

This parameter defaults to :keep.

:excluded_macros

List of macro names whose bodies are skipped entirely (e.g. [:schema, :pipe_through]).

This parameter defaults to [].

:normalize_pipes

When true, x |> f() and f(x) are treated as identical.

This parameter defaults to false.

:min_similarity

Similarity threshold for near-miss clones (0.0–1.0). Values below 1.0 enable Type-III detection.

This parameter defaults to 1.0.

:paths

Files or directories to analyze. Defaults to ExDNA's CLI default: lib/.

This parameter defaults to ["lib/"].

:ignore

Glob patterns to exclude from analysis.

This parameter defaults to [].

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.

Summary

Functions

Initializes ExDNA as a Credo plugin.

Functions

init(exec)

Initializes ExDNA as a Credo plugin.

Registers the duplication check and disables the built-in DuplicatedCode. Plugin params are forwarded as check params:

plugins: [{ExDNA.Credo, [min_mass: 40, literal_mode: :abstract]}]