Bylaw.Credo.Check.Ecto.PreferDateTimeOverDate (bylaw_credo v0.1.0-alpha.1)

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

Prefer :naive_datetime or :utc_datetime over :date in Ecto schemas and migrations when you need precise timestamps.

Examples

Avoid:

  schema "events" do
    field :starts_on, :date
  end

  alter table(:events) do
    add :starts_on, :date
    modify :ends_on, :date
  end

Prefer:

  schema "events" do
    field :starts_at, :utc_datetime
  end

  alter table(:events) do
    add :starts_at, :utc_datetime
    timestamps(type: :utc_datetime)
  end

Notes

Use :naive_datetime, :utc_datetime, or timestamps/1 unless the field is intentionally a calendar-only value. If a true date-only field is required, disable the check locally with Credo.

This check uses static AST analysis, so it favors clear source-level patterns over runtime behavior.

Options

This check has no check-specific options. Configure it with an empty option list.

Usage

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

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

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.