From 1b020a4fe94a70bedc923e47e37e51fb2dd2b400 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 24 Jun 2024 23:23:43 -0400 Subject: [PATCH] Fix some credo issues --- .credo.exs | 11 +++++++++++ lib/philomena/galleries.ex | 2 +- lib/philomena/users/user.ex | 1 - lib/philomena_query/parse/parser.ex | 4 +--- lib/philomena_query/parse/string.ex | 3 +-- .../plugs/content_security_policy_plug.ex | 5 +---- lib/philomena_web/views/app_view.ex | 4 +--- 7 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 .credo.exs diff --git a/.credo.exs b/.credo.exs new file mode 100644 index 00000000..8e6be303 --- /dev/null +++ b/.credo.exs @@ -0,0 +1,11 @@ +%{ + configs: %{ + name: "default", + checks: %{ + disabled: [ + {Credo.Check.Refactor.CondStatements, false}, + {Credo.Check.Refactor.NegatedConditionsWithElse, false} + ] + } + } +} diff --git a/lib/philomena/galleries.ex b/lib/philomena/galleries.ex index b0a61bd9..1943fc25 100644 --- a/lib/philomena/galleries.ex +++ b/lib/philomena/galleries.ex @@ -333,7 +333,7 @@ defmodule Philomena.Galleries do end) changes - |> Enum.map(fn change -> + |> Enum.each(fn change -> id = Keyword.fetch!(change, :id) change = Keyword.delete(change, :id) diff --git a/lib/philomena/users/user.ex b/lib/philomena/users/user.ex index 1972241d..182412d7 100644 --- a/lib/philomena/users/user.ex +++ b/lib/philomena/users/user.ex @@ -535,7 +535,6 @@ defmodule Philomena.Users.User do "data:image/png;base64," <> png end - @spec totp_secret(%Philomena.Users.User{}) :: binary() def totp_secret(user) do Philomena.Users.Encryptor.decrypt_model( user.encrypted_otp_secret, diff --git a/lib/philomena_query/parse/parser.ex b/lib/philomena_query/parse/parser.ex index a9d40222..a89434d2 100644 --- a/lib/philomena_query/parse/parser.ex +++ b/lib/philomena_query/parse/parser.ex @@ -212,9 +212,7 @@ defmodule PhilomenaQuery.Parse.Parser do end defp debug_tokens(tokens) do - tokens - |> Enum.map(fn {_k, v} -> v end) - |> Enum.join("") + Enum.map_join(tokens, fn {_k, v} -> v end) end # diff --git a/lib/philomena_query/parse/string.ex b/lib/philomena_query/parse/string.ex index f6dc2fa0..497274d1 100644 --- a/lib/philomena_query/parse/string.ex +++ b/lib/philomena_query/parse/string.ex @@ -26,7 +26,6 @@ defmodule PhilomenaQuery.Parse.String do str |> String.replace("\r", "") |> String.split("\n", trim: true) - |> Enum.map(fn s -> "(#{s})" end) - |> Enum.join(" || ") + |> Enum.map_join(" || ", &"(#{&1})") end end diff --git a/lib/philomena_web/plugs/content_security_policy_plug.ex b/lib/philomena_web/plugs/content_security_policy_plug.ex index 34cca2d6..854cb613 100644 --- a/lib/philomena_web/plugs/content_security_policy_plug.ex +++ b/lib/philomena_web/plugs/content_security_policy_plug.ex @@ -37,10 +37,7 @@ defmodule PhilomenaWeb.ContentSecurityPolicyPlug do {:media_src, ["'self'", "blob:", "data:", cdn_uri, camo_uri]} ] - csp_value = - csp_config - |> Enum.map(&cspify_element/1) - |> Enum.join("; ") + csp_value = Enum.map_join(csp_config, "; ", &cspify_element/1) csp_relaxed? do if conn.status == 500 do diff --git a/lib/philomena_web/views/app_view.ex b/lib/philomena_web/views/app_view.ex index 1b0febd5..9feaf46d 100644 --- a/lib/philomena_web/views/app_view.ex +++ b/lib/philomena_web/views/app_view.ex @@ -117,9 +117,7 @@ defmodule PhilomenaWeb.AppView do def escape_nl2br(text) do text |> String.split("\n") - |> Enum.map(&html_escape/1) - |> Enum.map(&safe_to_string/1) - |> Enum.join("
") + |> Enum.map_intersperse("
", &safe_to_string(html_escape(&1))) |> raw() end