use credo style

This commit is contained in:
shibao 2023-02-04 17:36:27 -05:00
parent cd7220cea3
commit ad7810a8ea
19 changed files with 46 additions and 45 deletions

View File

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

View File

@ -7,7 +7,9 @@ defmodule Memex.Release do
def rollback(repo, version) do
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
defp load_app do
@ -18,7 +20,8 @@ defmodule Memex.Release do
load_app()
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

View File

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

View File

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

View File

@ -11,7 +11,7 @@ defmodule MemexWeb.ContextLive.Show do
@impl true
def handle_params(
%{"slug" => slug},
_,
_params,
%{assigns: %{live_action: live_action, current_user: current_user}} = socket
) do
context =

View File

@ -3,12 +3,12 @@ defmodule MemexWeb.HomeLive do
Liveview for the main home page
"""
@version Mix.Project.config()[:version]
use MemexWeb, :live_view
alias Memex.Accounts
alias MemexWeb.{Endpoint, FaqLive}
@version Mix.Project.config()[:version]
@impl true
def mount(_params, _session, socket) do
admins = Accounts.list_users_by_role(:admin)

View File

@ -124,7 +124,7 @@ defmodule MemexWeb.InviteLive.Index do
end
@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")
{:noreply, socket |> put_flash(:info, prompt)}
end

View File

@ -11,7 +11,7 @@ defmodule MemexWeb.NoteLive.Show do
@impl true
def handle_params(
%{"slug" => slug},
_,
_params,
%{assigns: %{live_action: live_action, current_user: current_user}} = socket
) do
note =

View File

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

View File

@ -8,7 +8,7 @@ defmodule MemexWeb.ErrorView do
case error_path do
"404.html" -> dgettext("errors", "not found")
"401.html" -> dgettext("errors", "unauthorized")
_ -> dgettext("errors", "internal server error")
_other_path -> dgettext("errors", "internal server error")
end
render("error.html", %{error_string: error_string})

View File

@ -316,7 +316,7 @@ defmodule Memex.AccountsTest do
end
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.update_user_password(user, valid_user_password(), %{
@ -513,7 +513,7 @@ defmodule Memex.AccountsTest do
end
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"})
refute Repo.get_by(UserToken, user_id: user.id)
end

View File

@ -116,7 +116,7 @@ defmodule MemexWeb.UserAuthTest do
end
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, [])
refute get_session(conn, :user_token)
refute conn.assigns.current_user

View File

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

View File

@ -57,7 +57,7 @@ defmodule MemexWeb.ContextLiveTest do
|> form("#context-form", context: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
{:ok, _live, html} =
index_live
|> form("#context-form", context: @create_attrs)
|> render_submit()
@ -79,7 +79,7 @@ defmodule MemexWeb.ContextLiveTest do
|> form("#context-form", context: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
{:ok, _live, html} =
index_live
|> form("#context-form", context: @update_attrs)
|> render_submit()
@ -122,7 +122,7 @@ defmodule MemexWeb.ContextLiveTest do
assert html =~ "can&#39;t be blank"
assert html =~ "tags must be comma-delimited"
{:ok, _, html} =
{:ok, _live, html} =
show_live
|> form("#context-form", context: Map.put(@update_attrs, "slug", context.slug))
|> render_submit()

View File

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

View File

@ -62,7 +62,7 @@ defmodule MemexWeb.NoteLiveTest do
assert html =~ "can&#39;t be blank"
assert html =~ "tags must be comma-delimited"
{:ok, _, html} =
{:ok, _live, html} =
index_live
|> form("#note-form", note: @create_attrs)
|> render_submit()
@ -84,7 +84,7 @@ defmodule MemexWeb.NoteLiveTest do
|> form("#note-form", note: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
{:ok, _live, html} =
index_live
|> form("#note-form", note: @update_attrs)
|> render_submit()
@ -123,7 +123,7 @@ defmodule MemexWeb.NoteLiveTest do
|> form("#note-form", note: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
{:ok, _live, html} =
show_live
|> form("#note-form", note: Map.put(@update_attrs, "slug", note.slug))
|> render_submit()

View File

@ -68,7 +68,7 @@ defmodule MemexWeb.PipelineLiveTest do
|> form("#pipeline-form", pipeline: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
{:ok, _live, html} =
index_live
|> form("#pipeline-form", pipeline: @create_attrs)
|> render_submit()
@ -90,7 +90,7 @@ defmodule MemexWeb.PipelineLiveTest do
|> form("#pipeline-form", pipeline: @invalid_attrs)
|> render_change() =~ "can&#39;t be blank"
{:ok, _, html} =
{:ok, _live, html} =
index_live
|> form("#pipeline-form", pipeline: @update_attrs)
|> render_submit()
@ -136,7 +136,7 @@ defmodule MemexWeb.PipelineLiveTest do
assert html =~ "can&#39;t be blank"
assert html =~ "tags must be comma-delimited"
{:ok, _, html} =
{:ok, _live, html} =
show_live
|> form("#pipeline-form", pipeline: Map.put(@update_attrs, "slug", pipeline.slug))
|> render_submit()

View File

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

View File

@ -26,6 +26,7 @@ defmodule MemexWeb.ConnCase do
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import Memex.Fixtures
import MemexWeb.ConnCase
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import Phoenix.ConnTest
import Plug.Conn