forked from shibao/cannery
use credo style
This commit is contained in:
parent
30d3f76fe1
commit
5c05f3b6fe
14
.credo.exs
14
.credo.exs
@ -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`.
|
||||
|
@ -15,7 +15,9 @@ defmodule Lokal.Accounts.User do
|
||||
:email,
|
||||
:confirmed_at,
|
||||
:role,
|
||||
:locale
|
||||
:locale,
|
||||
:inserted_at,
|
||||
:updated_at
|
||||
]}
|
||||
@derive {Inspect, except: [:password]}
|
||||
@primary_key {:id, :binary_id, autogenerate: true}
|
||||
|
@ -7,7 +7,9 @@ defmodule Lokal.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 Lokal.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
|
||||
|
@ -6,11 +6,11 @@ defmodule Lokal.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
|
||||
|
@ -72,15 +72,16 @@ defmodule LokalWeb 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 LokalWeb.Gettext
|
||||
end
|
||||
end
|
||||
@ -88,15 +89,14 @@ defmodule LokalWeb 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, link, <.form>, etc)
|
||||
import Phoenix.Component
|
||||
|
||||
# Import basic rendering functionality (render, render_layout, etc)
|
||||
import Phoenix.View
|
||||
|
||||
import Phoenix.{Component, View}
|
||||
import LokalWeb.{ErrorHelpers, Gettext, LiveHelpers, ViewHelpers}
|
||||
|
||||
alias LokalWeb.Router.Helpers, as: Routes
|
||||
end
|
||||
end
|
||||
|
@ -124,7 +124,7 @@ defmodule LokalWeb.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
|
||||
|
@ -49,7 +49,7 @@ defmodule LokalWeb.LiveHelpers do
|
||||
id="modal-content"
|
||||
class="fade-in-scale w-full max-w-3xl relative
|
||||
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
|
||||
bg-white border-2 rounded-lg"
|
||||
>
|
||||
|
@ -2,7 +2,6 @@ defmodule LokalWeb.EmailView do
|
||||
@moduledoc """
|
||||
A view for email-related helper functions
|
||||
"""
|
||||
alias LokalWeb.{Endpoint, HomeLive}
|
||||
|
||||
use LokalWeb, :view
|
||||
alias LokalWeb.{Endpoint, HomeLive}
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ defmodule LokalWeb.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})
|
||||
|
@ -179,22 +179,22 @@ msgstr ""
|
||||
msgid "You must confirm your account and log in to access this page."
|
||||
msgstr ""
|
||||
|
||||
#: lib/lokal/accounts/user.ex:142
|
||||
#: lib/lokal/accounts/user.ex:144
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "did not change"
|
||||
msgstr ""
|
||||
|
||||
#: lib/lokal/accounts/user.ex:163
|
||||
#: lib/lokal/accounts/user.ex:165
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "does not match password"
|
||||
msgstr ""
|
||||
|
||||
#: lib/lokal/accounts/user.ex:200
|
||||
#: lib/lokal/accounts/user.ex:202
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "is not valid"
|
||||
msgstr ""
|
||||
|
||||
#: lib/lokal/accounts/user.ex:97
|
||||
#: lib/lokal/accounts/user.ex:99
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "must have the @ sign and no spaces"
|
||||
msgstr ""
|
||||
|
@ -176,22 +176,22 @@ msgstr ""
|
||||
msgid "You must confirm your account and log in to access this page."
|
||||
msgstr ""
|
||||
|
||||
#: lib/lokal/accounts/user.ex:142
|
||||
#: lib/lokal/accounts/user.ex:144
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "did not change"
|
||||
msgstr ""
|
||||
|
||||
#: lib/lokal/accounts/user.ex:163
|
||||
#: lib/lokal/accounts/user.ex:165
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "does not match password"
|
||||
msgstr ""
|
||||
|
||||
#: lib/lokal/accounts/user.ex:200
|
||||
#: lib/lokal/accounts/user.ex:202
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "is not valid"
|
||||
msgstr ""
|
||||
|
||||
#: lib/lokal/accounts/user.ex:97
|
||||
#: lib/lokal/accounts/user.ex:99
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "must have the @ sign and no spaces"
|
||||
msgstr ""
|
||||
|
@ -316,7 +316,7 @@ defmodule Lokal.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 Lokal.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
|
||||
|
@ -116,7 +116,7 @@ defmodule LokalWeb.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
|
||||
|
@ -5,8 +5,7 @@ defmodule LokalWeb.UserConfirmationControllerTest do
|
||||
|
||||
use LokalWeb.ConnCase, async: true
|
||||
import LokalWeb.Gettext
|
||||
alias Lokal.Accounts
|
||||
alias Lokal.Repo
|
||||
alias Lokal.{Accounts, Repo}
|
||||
|
||||
@moduletag :user_confirmation_controller_test
|
||||
|
||||
|
@ -40,7 +40,7 @@ defmodule LokalWeb.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 LokalWeb.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()
|
||||
|
@ -5,12 +5,11 @@ defmodule LokalWeb.ErrorViewTest do
|
||||
|
||||
use LokalWeb.ConnCase, async: true
|
||||
import LokalWeb.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(LokalWeb.ErrorView, "404.html", []) =~
|
||||
dgettext("errors", "Not found")
|
||||
|
@ -25,6 +25,7 @@ defmodule LokalWeb.ConnCase do
|
||||
# Import conveniences for testing with connections
|
||||
import Plug.Conn
|
||||
import Phoenix.ConnTest
|
||||
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
|
||||
import Lokal.Fixtures
|
||||
import LokalWeb.ConnCase
|
||||
|
||||
|
@ -22,10 +22,8 @@ defmodule Lokal.DataCase do
|
||||
alias Lokal.Repo
|
||||
|
||||
import Ecto
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
import Lokal.DataCase
|
||||
import Lokal.Fixtures
|
||||
import Ecto.{Changeset, Query}
|
||||
import Lokal.{DataCase, Fixtures}
|
||||
end
|
||||
end
|
||||
|
||||
@ -45,7 +43,7 @@ defmodule Lokal.DataCase do
|
||||
"""
|
||||
def errors_on(changeset) do
|
||||
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()
|
||||
end)
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user