LexCredo.Check.Readability.DocExamplesSection (LexCredo v0.1.0)

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 normal and works with any version of Elixir.

Explanation

Every @doc string on a public function should include a ## Examples section.

Examples are the fastest way for a reader to understand what a function does. Use iex> doctests for deterministic output; use a plain code block when the result depends on runtime state.

# BAD — no Examples section
@doc """
Adds two numbers.
"""
def add(a, b), do: a + b

# GOOD
@doc """
Adds two numbers.

## Examples

    iex> MyModule.add(1, 2)
    3

"""
def add(a, b), do: a + b

Check-Specific Parameters

Use the following parameters to configure this check:

:exclude_test_files

When true, skips test files. Default: false.

This parameter defaults to false.

General Parameters

Like with all checks, general params can be applied.

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