Rbtz.CredoChecks.Readability.AtomHttpStatusCodes (rbtz_credo_checks v0.7.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 normal and works with any version of Elixir.

Explanation

Forbids passing integer HTTP status codes to Plug.Conn, Phoenix controller, and Phoenix.ConnTest helpers; use the corresponding atoms instead.

Atoms (:ok, :not_found, :unprocessable_entity, ...) read more naturally than three-digit numbers, surface typos at compile time, and work uniformly across all these helpers.

The check fires when a literal integer in the 100-599 range is passed as the status argument to send_resp/3, put_status/2, resp/3, or the Phoenix.ConnTest assertion helpers response/2, json_response/2, html_response/2, and redirected_to/2 (whether called directly or via |>, locally or as remote calls).

Bad

put_status(conn, 404)
send_resp(conn, 200, body)
Plug.Conn.resp(conn, 500, "oops")
conn |> json_response(200)

Good

put_status(conn, :not_found)
send_resp(conn, :ok, body)
Plug.Conn.resp(conn, :internal_server_error, "oops")
conn |> json_response(:ok)

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.