# `GitHoox.Hook`
[🔗](https://github.com/sgerrand/git_hoox/blob/v0.5.0/lib/git_hoox/hook.ex#L1)

Behaviour for git_hoox hooks.

Implement `run/2` to execute logic. Optionally implement `default_opts/0`
to supply per-hook defaults (e.g. `stage_fixed: true` for formatters).

## Example

    defmodule MyApp.Hooks.Sobelow do
      @behaviour GitHoox.Hook

      @impl true
      def default_opts, do: [files: ~w(lib/**/*.ex)]

      @impl true
      def run([], _opts), do: :ok
      def run(files, _opts) do
        case System.cmd("mix", ["sobelow", "--exit" | files], stderr_to_stdout: true) do
          {_, 0} -> :ok
          {out, code} -> {:error, {code, out}}
        end
      end
    end

# `files`

```elixir
@type files() :: [GitHoox.path()]
```

Files matched by hook's `:files` glob, after staging filter.

# `opts`

```elixir
@type opts() :: keyword()
```

Hook options merged from `default_opts/0` and user config.

# `default_opts`
*optional* 

```elixir
@callback default_opts() :: keyword()
```

Per-hook default options. Merged with user config; user wins on conflict.

# `opts_schema`
*optional* 

```elixir
@callback opts_schema() :: keyword()
```

Hook-specific [NimbleOptions](https://hexdocs.pm/nimble_options) schema.

Used by `GitHoox.Config` to validate any opts the user passes that are
not part of the global schema (`:files`, `:stage_fixed`, `:timeout`,
`:env`). Hooks that do not implement this callback accept arbitrary
extra opts without validation.

# `run`

```elixir
@callback run(files(), opts()) :: GitHoox.hook_result()
```

Run hook against `files`.

Return `:ok` for read-only success. Return `{:ok, modified}` listing files
the hook mutated — runner re-stages them if `stage_fixed: true`. Return
`{:error, reason}` to fail. The runner accepts no other shapes; anything
else is a contract violation. The runner emits its own
`[:git_hoox, :hook, :skip]` telemetry event when a hook's `:files` glob
filters every candidate out — hook authors should not return `:skip`
themselves.

# `merge_defaults`

```elixir
@spec merge_defaults(module(), opts()) :: opts()
```

Merge a hook module's `default_opts/0` with user-supplied opts.

User opts win on conflict. Modules without `default_opts/0` contribute
an empty list.

---

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