AshCredo.Check.Warning.PinnedTimeInExpression (ash_credo v0.5.2)

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

Explanation

Using ^Date.utc_today() or ^DateTime.utc_now() inside an Ash expression freezes the value at compile time. The pinned value never changes after compilation, leading to subtle bugs that only manifest after time passes.

Use Ash's built-in expression functions instead:

# Bad — frozen at compile time
filter expr(start_date <= ^Date.utc_today())

# Good — evaluated at runtime
filter expr(start_date <= today())

# Bad
filter expr(inserted_at >= ^DateTime.utc_now())

# Good
filter expr(inserted_at >= now())

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

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