use credo style

This commit is contained in:
shibao 2023-02-04 17:28:53 -05:00 committed by oliviasculley
parent 30d3f76fe1
commit 5c05f3b6fe
18 changed files with 47 additions and 46 deletions

View File

@ -157,17 +157,17 @@
# #
# Controversial and experimental checks (opt-in, just replace `false` with `[]`) # Controversial and experimental checks (opt-in, just replace `false` with `[]`)
# #
{Credo.Check.Consistency.MultiAliasImportRequireUse, false}, {Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.UnusedVariableNames, false}, {Credo.Check.Consistency.UnusedVariableNames, [force: :meaningful]},
{Credo.Check.Design.DuplicatedCode, false}, {Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.AliasAs, false}, {Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.BlockPipe, false}, {Credo.Check.Readability.BlockPipe, false},
{Credo.Check.Readability.ImplTrue, false}, {Credo.Check.Readability.ImplTrue, false},
{Credo.Check.Readability.MultiAlias, false}, {Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.SeparateAliasRequire, false}, {Credo.Check.Readability.SeparateAliasRequire, []},
{Credo.Check.Readability.SinglePipe, false}, {Credo.Check.Readability.SinglePipe, false},
{Credo.Check.Readability.Specs, false}, {Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.StrictModuleLayout, false}, {Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Readability.WithCustomTaggedTuple, false}, {Credo.Check.Readability.WithCustomTaggedTuple, false},
{Credo.Check.Refactor.ABCSize, false}, {Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false}, {Credo.Check.Refactor.AppendSingleItem, false},
@ -176,9 +176,9 @@
{Credo.Check.Refactor.NegatedIsNil, false}, {Credo.Check.Refactor.NegatedIsNil, false},
{Credo.Check.Refactor.PipeChainStart, false}, {Credo.Check.Refactor.PipeChainStart, false},
{Credo.Check.Refactor.VariableRebinding, false}, {Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.LeakyEnvironment, false}, {Credo.Check.Warning.LeakyEnvironment, []},
{Credo.Check.Warning.MapGetUnsafePass, false}, {Credo.Check.Warning.MapGetUnsafePass, []},
{Credo.Check.Warning.UnsafeToAtom, false} {Credo.Check.Warning.UnsafeToAtom, []}
# #
# Custom checks can be created using `mix credo.gen.check`. # Custom checks can be created using `mix credo.gen.check`.

View File

@ -15,7 +15,9 @@ defmodule Lokal.Accounts.User do
:email, :email,
:confirmed_at, :confirmed_at,
:role, :role,
:locale :locale,
:inserted_at,
:updated_at
]} ]}
@derive {Inspect, except: [:password]} @derive {Inspect, except: [:password]}
@primary_key {:id, :binary_id, autogenerate: true} @primary_key {:id, :binary_id, autogenerate: true}

View File

@ -7,7 +7,9 @@ defmodule Lokal.Release do
def rollback(repo, version) do def rollback(repo, version) do
load_app() load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
{:ok, _fun_return, _apps} =
Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end end
defp load_app do defp load_app do
@ -18,7 +20,8 @@ defmodule Lokal.Release do
load_app() load_app()
for repo <- Application.fetch_env!(@app, :ecto_repos) do for repo <- Application.fetch_env!(@app, :ecto_repos) do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) {:ok, _fun_return, _apps} =
Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end end
end end
end end

View File

@ -6,11 +6,11 @@ defmodule Lokal.Repo.Migrator do
use GenServer use GenServer
require Logger require Logger
def start_link(_) do def start_link(_opts) do
GenServer.start_link(__MODULE__, [], []) GenServer.start_link(__MODULE__, [], [])
end end
def init(_) do def init(_opts) do
migrate!() migrate!()
{:ok, nil} {:ok, nil}
end end

View File

@ -72,15 +72,16 @@ defmodule LokalWeb do
quote do quote do
use Phoenix.Router use Phoenix.Router
import Phoenix.{Controller, LiveView.Router}
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import Plug.Conn import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
end end
end end
def channel do def channel do
quote do quote do
use Phoenix.Channel use Phoenix.Channel
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import LokalWeb.Gettext import LokalWeb.Gettext
end end
end end
@ -88,15 +89,14 @@ defmodule LokalWeb do
defp view_helpers do defp view_helpers do
quote do quote do
# Use all HTML functionality (forms, tags, etc) # Use all HTML functionality (forms, tags, etc)
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
use Phoenix.HTML use Phoenix.HTML
# Import LiveView and .heex helpers (live_render, link, <.form>, etc) # Import LiveView and .heex helpers (live_render, link, <.form>, etc)
import Phoenix.Component
# Import basic rendering functionality (render, render_layout, etc) # Import basic rendering functionality (render, render_layout, etc)
import Phoenix.View import Phoenix.{Component, View}
import LokalWeb.{ErrorHelpers, Gettext, LiveHelpers, ViewHelpers} import LokalWeb.{ErrorHelpers, Gettext, LiveHelpers, ViewHelpers}
alias LokalWeb.Router.Helpers, as: Routes alias LokalWeb.Router.Helpers, as: Routes
end end
end end

View File

@ -124,7 +124,7 @@ defmodule LokalWeb.InviteLive.Index do
end end
@impl true @impl true
def handle_event("copy_to_clipboard", _, socket) do def handle_event("copy_to_clipboard", _params, socket) do
prompt = dgettext("prompts", "Copied to clipboard") prompt = dgettext("prompts", "Copied to clipboard")
{:noreply, socket |> put_flash(:info, prompt)} {:noreply, socket |> put_flash(:info, prompt)}
end end

View File

@ -49,7 +49,7 @@ defmodule LokalWeb.LiveHelpers do
id="modal-content" id="modal-content"
class="fade-in-scale w-full max-w-3xl relative class="fade-in-scale w-full max-w-3xl relative
pointer-events-auto overflow-hidden pointer-events-auto overflow-hidden
px-8 py-4 sm:py-8 flex flex-col justify-center items-center px-8 py-4 sm:py-8
flex flex-col justify-start items-center flex flex-col justify-start items-center
bg-white border-2 rounded-lg" bg-white border-2 rounded-lg"
> >

View File

@ -2,7 +2,6 @@ defmodule LokalWeb.EmailView do
@moduledoc """ @moduledoc """
A view for email-related helper functions A view for email-related helper functions
""" """
alias LokalWeb.{Endpoint, HomeLive}
use LokalWeb, :view use LokalWeb, :view
alias LokalWeb.{Endpoint, HomeLive}
end end

View File

@ -8,7 +8,7 @@ defmodule LokalWeb.ErrorView do
case error_path do case error_path do
"404.html" -> dgettext("errors", "Not found") "404.html" -> dgettext("errors", "Not found")
"401.html" -> dgettext("errors", "Unauthorized") "401.html" -> dgettext("errors", "Unauthorized")
_ -> dgettext("errors", "Internal Server Error") _other_path -> dgettext("errors", "Internal Server Error")
end end
render("error.html", %{error_string: error_string}) render("error.html", %{error_string: error_string})

View File

@ -179,22 +179,22 @@ msgstr ""
msgid "You must confirm your account and log in to access this page." msgid "You must confirm your account and log in to access this page."
msgstr "" msgstr ""
#: lib/lokal/accounts/user.ex:142 #: lib/lokal/accounts/user.ex:144
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "did not change" msgid "did not change"
msgstr "" msgstr ""
#: lib/lokal/accounts/user.ex:163 #: lib/lokal/accounts/user.ex:165
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "does not match password" msgid "does not match password"
msgstr "" msgstr ""
#: lib/lokal/accounts/user.ex:200 #: lib/lokal/accounts/user.ex:202
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "is not valid" msgid "is not valid"
msgstr "" msgstr ""
#: lib/lokal/accounts/user.ex:97 #: lib/lokal/accounts/user.ex:99
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "must have the @ sign and no spaces" msgid "must have the @ sign and no spaces"
msgstr "" msgstr ""

View File

@ -176,22 +176,22 @@ msgstr ""
msgid "You must confirm your account and log in to access this page." msgid "You must confirm your account and log in to access this page."
msgstr "" msgstr ""
#: lib/lokal/accounts/user.ex:142 #: lib/lokal/accounts/user.ex:144
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "did not change" msgid "did not change"
msgstr "" msgstr ""
#: lib/lokal/accounts/user.ex:163 #: lib/lokal/accounts/user.ex:165
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "does not match password" msgid "does not match password"
msgstr "" msgstr ""
#: lib/lokal/accounts/user.ex:200 #: lib/lokal/accounts/user.ex:202
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "is not valid" msgid "is not valid"
msgstr "" msgstr ""
#: lib/lokal/accounts/user.ex:97 #: lib/lokal/accounts/user.ex:99
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "must have the @ sign and no spaces" msgid "must have the @ sign and no spaces"
msgstr "" msgstr ""

View File

@ -316,7 +316,7 @@ defmodule Lokal.AccountsTest do
end end
test "deletes all tokens for the given user", %{user: user} do test "deletes all tokens for the given user", %{user: user} do
_ = Accounts.generate_user_session_token(user) _session_token = Accounts.generate_user_session_token(user)
{:ok, _} = {:ok, _} =
Accounts.update_user_password(user, valid_user_password(), %{ Accounts.update_user_password(user, valid_user_password(), %{
@ -513,7 +513,7 @@ defmodule Lokal.AccountsTest do
end end
test "deletes all tokens for the given user", %{user: user} do test "deletes all tokens for the given user", %{user: user} do
_ = Accounts.generate_user_session_token(user) _session_token = Accounts.generate_user_session_token(user)
{:ok, _} = Accounts.reset_user_password(user, %{"password" => "new valid password"}) {:ok, _} = Accounts.reset_user_password(user, %{"password" => "new valid password"})
refute Repo.get_by(UserToken, user_id: user.id) refute Repo.get_by(UserToken, user_id: user.id)
end end

View File

@ -116,7 +116,7 @@ defmodule LokalWeb.UserAuthTest do
end end
test "does not authenticate if data is missing", %{conn: conn, current_user: current_user} do test "does not authenticate if data is missing", %{conn: conn, current_user: current_user} do
_ = Accounts.generate_user_session_token(current_user) _session_token = Accounts.generate_user_session_token(current_user)
conn = UserAuth.fetch_current_user(conn, []) conn = UserAuth.fetch_current_user(conn, [])
refute get_session(conn, :user_token) refute get_session(conn, :user_token)
refute conn.assigns.current_user refute conn.assigns.current_user

View File

@ -5,8 +5,7 @@ defmodule LokalWeb.UserConfirmationControllerTest do
use LokalWeb.ConnCase, async: true use LokalWeb.ConnCase, async: true
import LokalWeb.Gettext import LokalWeb.Gettext
alias Lokal.Accounts alias Lokal.{Accounts, Repo}
alias Lokal.Repo
@moduletag :user_confirmation_controller_test @moduletag :user_confirmation_controller_test

View File

@ -40,7 +40,7 @@ defmodule LokalWeb.InviteLiveTest do
# |> form("#invite-form", invite: @invalid_attrs) # |> form("#invite-form", invite: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "can't be blank") # |> render_change() =~ dgettext("errors", "can't be blank")
{:ok, _, html} = {:ok, _live, html} =
index_live index_live
|> form("#invite-form", invite: @create_attrs) |> form("#invite-form", invite: @create_attrs)
|> render_submit() |> render_submit()
@ -64,7 +64,7 @@ defmodule LokalWeb.InviteLiveTest do
# |> form("#invite-form", invite: @invalid_attrs) # |> form("#invite-form", invite: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "can't be blank") # |> render_change() =~ dgettext("errors", "can't be blank")
{:ok, _, html} = {:ok, _live, html} =
index_live index_live
|> form("#invite-form", invite: @update_attrs) |> form("#invite-form", invite: @update_attrs)
|> render_submit() |> render_submit()

View File

@ -5,12 +5,11 @@ defmodule LokalWeb.ErrorViewTest do
use LokalWeb.ConnCase, async: true use LokalWeb.ConnCase, async: true
import LokalWeb.Gettext import LokalWeb.Gettext
@moduletag :error_view_test
# Bring render/3 and render_to_string/3 for testing custom views # Bring render/3 and render_to_string/3 for testing custom views
import Phoenix.View import Phoenix.View
@moduletag :error_view_test
test "renders 404.html" do test "renders 404.html" do
assert render_to_string(LokalWeb.ErrorView, "404.html", []) =~ assert render_to_string(LokalWeb.ErrorView, "404.html", []) =~
dgettext("errors", "Not found") dgettext("errors", "Not found")

View File

@ -25,6 +25,7 @@ defmodule LokalWeb.ConnCase do
# Import conveniences for testing with connections # Import conveniences for testing with connections
import Plug.Conn import Plug.Conn
import Phoenix.ConnTest import Phoenix.ConnTest
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import Lokal.Fixtures import Lokal.Fixtures
import LokalWeb.ConnCase import LokalWeb.ConnCase

View File

@ -22,10 +22,8 @@ defmodule Lokal.DataCase do
alias Lokal.Repo alias Lokal.Repo
import Ecto import Ecto
import Ecto.Changeset import Ecto.{Changeset, Query}
import Ecto.Query import Lokal.{DataCase, Fixtures}
import Lokal.DataCase
import Lokal.Fixtures
end end
end end
@ -45,7 +43,7 @@ defmodule Lokal.DataCase do
""" """
def errors_on(changeset) do def errors_on(changeset) do
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} -> Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
Regex.replace(~r"%{(\w+)}", message, fn _, key -> Regex.replace(~r"%{(\w+)}", message, fn _capture, key ->
opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string() opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
end) end)
end) end)