# `LexCredo.Check.Warning.UsePositiveTypeGuards`
[🔗](https://github.com/sippy-platform/lex_credo/blob/main/lib/lex_credo/check/warning/use_positive_type_guards.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

Use positive type guards instead of negated type checks in function guards.

Negating a type guard is imprecise — `not is_nil(x)` passes integers, lists,
and anything else that is not nil. `not is_binary(x)` passes nil, integers,
atoms, and more. State what you expect, not what you want to exclude.

    # BAD: passes any non-nil value, including integers, lists, etc.
    def call_service(%{req: req}) when not is_nil(req), do: ...
    def call_service(%{req: req}) when req != nil, do: ...

    # BAD: passes nil, integers, atoms, …
    def validate(x) when not is_binary(x), do: ...

    # GOOD: precise about what is actually expected
    def call_service(%{req: req}) when is_binary(req), do: ...

## 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](`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*
