# `Bylaw.Credo.Check.Phoenix.ContextFunctionNaming`
[🔗](https://github.com/ryanzidago/bylaw/blob/v0.1.0-alpha.1/lib/bylaw/credo/check/phoenix/context_function_naming.ex#L1)

## Basics

> #### This check is disabled by default. {: .neutral}
>
> [Learn how to enable it](`e:credo:config_file.html#checks`) via `.credo.exs`.

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

## Explanation

Context lookup functions must follow a naming convention that signals their
return type, consistent with `Ecto.Repo` (e.g. `Repo.get/2`, `Repo.get!/2`):

## Examples

- `get_*`   functions return `record | nil`
- `get_*!`  functions return `record` (raise on not found)
- `fetch_*` functions return `{:ok, record} | {:error, reason}`
Avoid:

      @spec get_workspace(binary()) :: {:ok, Workspace.t()} | {:error, :not_found}
      def get_workspace(id), do: ...
Prefer:

      @spec fetch_workspace(binary()) :: {:ok, Workspace.t()} | {:error, :not_found}
      def fetch_workspace(id), do: ...

Or this:

      @spec get_workspace(binary()) :: Workspace.t() | nil
      def get_workspace(id), do: ...

## Notes

Path exclusions are matched against the source filename and are intended for generated files or temporary migration areas.

The check uses static AST analysis, so dynamic code generation and macro-expanded code may fall outside its signal.

## Options

Configure options in `.credo.exs` with the check tuple:

```elixir
%{
  configs: [
    %{
      name: "default",
      checks: [
        {Bylaw.Credo.Check.Phoenix.ContextFunctionNaming,
         [
           excluded_paths: ["test/support/"]
         ]}
      ]
    }
  ]
}
```

- `:excluded_paths` - List of paths or regex to exclude from this check

## Usage

Add this check to Credo's `checks:` list in `.credo.exs`:

```elixir
%{
  configs: [
    %{
      name: "default",
      checks: [
        {Bylaw.Credo.Check.Phoenix.ContextFunctionNaming, []}
      ]
    }
  ]
}
```

## Check-Specific Parameters

Use the following parameters to configure this check:

### `:excluded_paths`

  List of paths or regex to exclude from this check

*This parameter defaults to* `[]`.

## General Parameters

Like with all checks, [general params](`e:credo:check_params.html`) can be applied.

Parameters can be configured via the [`.credo.exs` config file](`e:credo:config_file.html`).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
