# `Bylaw.Credo.Check.Ecto.NamedBinding`
[🔗](https://github.com/ryanzidago/bylaw/blob/v0.1.0-alpha.1/lib/bylaw/credo/check/ecto/named_binding.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 `higher` and works with any version of Elixir.

## Explanation

Prefer named Ecto bindings over positional bindings in composed queries.

## Examples

Avoid:

      User
      |> join(:inner, [u], p in assoc(u, :profile))
      |> where([u, p], p.active)
      |> select([u, p], {u.id, p.display_name})

Prefer:

      User
      |> from(as: :user)
      |> join(:inner, [user: u], p in assoc(u, :profile), as: :profile)
      |> where([profile: p], p.active)
      |> select([user: u, profile: p], {u.id, p.display_name})

## Notes

Positional bindings make every later query clause depend on the order of
earlier joins. Adding, removing, or reordering a join can silently change
what `[u, p]` means in the rest of the pipeline.

Named bindings make each clause say which relationship it is using, so
query changes are easier to review and less sensitive to join order.

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.Ecto.NamedBinding,
         [
           excluded_paths: ["test/support/"]
         ]}
      ]
    }
  ]
}
```

- `:excluded_paths` - Paths containing any configured string are skipped. Use this for generated files or transitional areas that cannot yet follow named binding conventions.

## Usage

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

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

## Check-Specific Parameters

Use the following parameters to configure this check:

### `:excluded_paths`

  Paths containing any configured string are skipped. Use this for
  generated files or transitional areas that cannot yet follow named
  binding conventions.
  

*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*
