From 046094aa2d762c01207adea55416573d95eea263 Mon Sep 17 00:00:00 2001 From: Robert Prehn <3952444+prehnRA@users.noreply.github.com> Date: Tue, 20 Jul 2021 15:50:51 -0500 Subject: [PATCH] chore: Upgrade credo and address issues --- apps/admin/lib/admin/routes.ex | 5 +++++ apps/admin/lib/admin/telemetry.ex | 4 ++++ apps/admin/lib/kaffy/config.ex | 4 ++++ apps/admin/lib/kaffy/editor_extension.ex | 5 +++++ apps/app/lib/app_web/telemetry.ex | 4 ++++ apps/content/lib/content/comment_admin.ex | 4 ++++ apps/content/lib/content/markup_field.ex | 4 ++++ apps/content/lib/content/post_admin.ex | 4 ++++ .../lib/content_web/controllers/posts_controller.ex | 3 ++- apps/content/lib/content_web/routes.ex | 4 ++++ apps/content/test/content/posts_test.exs | 2 +- apps/core/lib/auth/mnesia_cluster_supervisor.ex | 5 +++++ apps/core/lib/auth/roles.ex | 7 ++++++- apps/core/lib/auth/user.ex | 2 +- apps/core/lib/auth/user_admin.ex | 6 ++++++ apps/core/lib/auth_web/helpers.ex | 8 ++++++-- apps/core/lib/core/map_utils.ex | 2 +- apps/core/lib/core_web/routes.ex | 6 ++++++ apps/core/lib/mix/legendary.ex | 4 ++++ mix.lock | 2 +- 20 files changed, 77 insertions(+), 8 deletions(-) diff --git a/apps/admin/lib/admin/routes.ex b/apps/admin/lib/admin/routes.ex index 64d2b94c..c07121bb 100644 --- a/apps/admin/lib/admin/routes.ex +++ b/apps/admin/lib/admin/routes.ex @@ -1,4 +1,9 @@ defmodule Legendary.Admin.Routes do + @moduledoc """ + Routes from the admin app. Use like: + + use Legendary.Admin.Routes + """ defmacro __using__(_opts \\ []) do quote do use Kaffy.Routes, scope: "/admin", pipe_through: [:require_admin] diff --git a/apps/admin/lib/admin/telemetry.ex b/apps/admin/lib/admin/telemetry.ex index 44ee3dc0..09add976 100644 --- a/apps/admin/lib/admin/telemetry.ex +++ b/apps/admin/lib/admin/telemetry.ex @@ -1,4 +1,8 @@ defmodule Legendary.Admin.Telemetry do + @moduledoc """ + Collect metrics from the admin app. + """ + use Supervisor import Telemetry.Metrics diff --git a/apps/admin/lib/kaffy/config.ex b/apps/admin/lib/kaffy/config.ex index 431b809a..ec0ac3d3 100644 --- a/apps/admin/lib/kaffy/config.ex +++ b/apps/admin/lib/kaffy/config.ex @@ -1,4 +1,8 @@ defmodule Legendary.Admin.Kaffy.Config do + @moduledoc """ + Pull in the resource list for the admin from the application config. + """ + def create_resources(_conn) do config = Application.get_env(:admin, Legendary.Admin) diff --git a/apps/admin/lib/kaffy/editor_extension.ex b/apps/admin/lib/kaffy/editor_extension.ex index bf0d0b5d..140df393 100644 --- a/apps/admin/lib/kaffy/editor_extension.ex +++ b/apps/admin/lib/kaffy/editor_extension.ex @@ -1,4 +1,9 @@ defmodule Legendary.Admin.Kaffy.EditorExtension do + @moduledoc """ + Bring in additional CSS and JS for the admin interface e.g. the + markdown editor library. + """ + def stylesheets(_conn) do [ {:safe, ~s()}, diff --git a/apps/app/lib/app_web/telemetry.ex b/apps/app/lib/app_web/telemetry.ex index 84cd681f..0fa5661d 100644 --- a/apps/app/lib/app_web/telemetry.ex +++ b/apps/app/lib/app_web/telemetry.ex @@ -1,4 +1,8 @@ defmodule AppWeb.Telemetry do + @moduledoc """ + Collect metrics on your app. + """ + use Supervisor import Telemetry.Metrics diff --git a/apps/content/lib/content/comment_admin.ex b/apps/content/lib/content/comment_admin.ex index 32a1efcc..afe398f5 100644 --- a/apps/content/lib/content/comment_admin.ex +++ b/apps/content/lib/content/comment_admin.ex @@ -1,4 +1,8 @@ defmodule Legendary.Content.CommentAdmin do + @moduledoc """ + Custom admin logic for blog post comments. + """ + def index(_) do [ id: nil, diff --git a/apps/content/lib/content/markup_field.ex b/apps/content/lib/content/markup_field.ex index 35abda4a..051e7611 100644 --- a/apps/content/lib/content/markup_field.ex +++ b/apps/content/lib/content/markup_field.ex @@ -1,4 +1,8 @@ defmodule Legendary.Content.MarkupField do + @moduledoc """ + Custom field type definition for markdown fields. Currently uses simplemde + to provide a markdown editing GUI. + """ use Ecto.Type def type, do: :string diff --git a/apps/content/lib/content/post_admin.ex b/apps/content/lib/content/post_admin.ex index a76f22c3..c846c1e2 100644 --- a/apps/content/lib/content/post_admin.ex +++ b/apps/content/lib/content/post_admin.ex @@ -1,4 +1,8 @@ defmodule Legendary.Content.PostAdmin do + @moduledoc """ + Custom admin logic for content posts and pages. + """ + import Ecto.Query, only: [from: 2] def singular_name(_) do diff --git a/apps/content/lib/content_web/controllers/posts_controller.ex b/apps/content/lib/content_web/controllers/posts_controller.ex index a1eb7444..903d00f8 100644 --- a/apps/content/lib/content_web/controllers/posts_controller.ex +++ b/apps/content/lib/content_web/controllers/posts_controller.ex @@ -87,11 +87,12 @@ defmodule Legendary.Content.PostsController do end # The static page we're looking for is missing, so this is just a 404 + # credo:disable-for-next-line raise Phoenix.Router.NoRouteError.exception(conn: conn, router: router) _ -> # We aren't missing the static page, we're missing a partial. This is probably # a developer error, so bubble it up - raise e + reraise e, System.stacktrace end end end diff --git a/apps/content/lib/content_web/routes.ex b/apps/content/lib/content_web/routes.ex index a4b3244b..a8969739 100644 --- a/apps/content/lib/content_web/routes.ex +++ b/apps/content/lib/content_web/routes.ex @@ -1,4 +1,8 @@ defmodule Legendary.Content.Routes do + @moduledoc """ + Routes for the content engine, including blog posts, feeds, and pages. + """ + defmacro __using__(_opts \\ []) do quote do pipeline :feed do diff --git a/apps/content/test/content/posts_test.exs b/apps/content/test/content/posts_test.exs index a3f44412..971ee9cb 100644 --- a/apps/content/test/content/posts_test.exs +++ b/apps/content/test/content/posts_test.exs @@ -52,7 +52,7 @@ defmodule Legendary.Content.PostsTest do test "delete_posts/1", %{public_post: post} do assert Enum.count(Posts.list_posts()) == 1 assert {:ok, _} = Posts.delete_posts(post) - assert Enum.count(Posts.list_posts()) == 0 + assert Enum.empty?(Posts.list_posts()) end test "change_posts/1", %{public_post: post} do diff --git a/apps/core/lib/auth/mnesia_cluster_supervisor.ex b/apps/core/lib/auth/mnesia_cluster_supervisor.ex index f3336624..1a25120f 100644 --- a/apps/core/lib/auth/mnesia_cluster_supervisor.ex +++ b/apps/core/lib/auth/mnesia_cluster_supervisor.ex @@ -1,4 +1,9 @@ defmodule Legendary.Auth.MnesiaClusterSupervisor do + @moduledoc """ + Manages the cache in Mnesia for Pow. This allows users to remain logged in + even if their traffic is hitting different nodes in the cluster. + """ + use Supervisor def start_link(init_arg) do diff --git a/apps/core/lib/auth/roles.ex b/apps/core/lib/auth/roles.ex index 39293d9e..fca4562b 100644 --- a/apps/core/lib/auth/roles.ex +++ b/apps/core/lib/auth/roles.ex @@ -1,7 +1,12 @@ defmodule Legendary.Auth.Roles do + @moduledoc """ + Functions for working with roles on users, such as testing whether a user has + a role. + """ + def has_role?(userlike, role) when is_atom(role), do: has_role?(userlike, Atom.to_string(role)) def has_role?(nil, _), do: false - def has_role?(user = %Legendary.Auth.User{}, role) do + def has_role?(%Legendary.Auth.User{} = user, role) do Enum.any?(user.roles || [], & &1 == role) end end diff --git a/apps/core/lib/auth/user.ex b/apps/core/lib/auth/user.ex index 931c48cd..e1396c30 100644 --- a/apps/core/lib/auth/user.ex +++ b/apps/core/lib/auth/user.ex @@ -40,7 +40,7 @@ defmodule Legendary.Auth.User do |> pow_extension_changeset(attrs) end - def reset_password_changeset(user = %Legendary.Auth.User{}, params) do + def reset_password_changeset(%Legendary.Auth.User{} = user, params) do user |> new_password_changeset(params, @pow_config) |> Changeset.validate_required([:password]) diff --git a/apps/core/lib/auth/user_admin.ex b/apps/core/lib/auth/user_admin.ex index 73292c29..83c40ffa 100644 --- a/apps/core/lib/auth/user_admin.ex +++ b/apps/core/lib/auth/user_admin.ex @@ -1,9 +1,15 @@ defmodule Legendary.Auth.UserAdmin do + @moduledoc """ + Custom admin login for user records. + """ import Ecto.Query, only: [from: 2] alias Legendary.Auth.User alias Legendary.Core.Repo def custom_links(_schema) do + # We add the funwithflags admin URL under this custom admin because kaffy + # doesn't have global custom links that work in this way and user is the + # closest fit. [ %{name: "Feature Flags", url: "/admin/feature-flags", order: 2, location: :top, icon: "flag"}, ] diff --git a/apps/core/lib/auth_web/helpers.ex b/apps/core/lib/auth_web/helpers.ex index 9b512b98..04fe3ce6 100644 --- a/apps/core/lib/auth_web/helpers.ex +++ b/apps/core/lib/auth_web/helpers.ex @@ -1,6 +1,10 @@ defmodule Legendary.AuthWeb.Helpers do - def current_user(socket = %Phoenix.LiveView.Socket{assigns: %{current_user: user}}), do: user - def current_user(socket = %Phoenix.LiveView.Socket{assigns: %{__assigns__: %{current_user: user}}}), do: user + @moduledoc """ + Utility functions for working with users and roles. + """ + + def current_user(%Phoenix.LiveView.Socket{assigns: %{current_user: user}}), do: user + def current_user(%Phoenix.LiveView.Socket{assigns: %{__assigns__: %{current_user: user}}}), do: user def current_user(%Phoenix.LiveView.Socket{}), do: nil def current_user(conn), do: Pow.Plug.current_user(conn) diff --git a/apps/core/lib/core/map_utils.ex b/apps/core/lib/core/map_utils.ex index 920e4b39..7fdb016e 100644 --- a/apps/core/lib/core/map_utils.ex +++ b/apps/core/lib/core/map_utils.ex @@ -7,7 +7,7 @@ defmodule Legendary.Core.MapUtils do Map.merge(base, override, &deep_value/3) end - defp deep_value(_key, base = %{}, override = %{}) do + defp deep_value(_key, %{} = base, %{} = override) do deep_merge(base, override) end diff --git a/apps/core/lib/core_web/routes.ex b/apps/core/lib/core_web/routes.ex index 6acc091b..ab4357e1 100644 --- a/apps/core/lib/core_web/routes.ex +++ b/apps/core/lib/core_web/routes.ex @@ -1,4 +1,10 @@ defmodule Legendary.Core.Routes do + @moduledoc """ + Router module that brings in core framework routes, such as the feature flag + admin interface. Can be included like: + + use Legendary.Core.Routes + """ defmacro __using__(_opts \\ []) do quote do scope path: "/admin/feature-flags" do diff --git a/apps/core/lib/mix/legendary.ex b/apps/core/lib/mix/legendary.ex index 0fdebdcb..2e56db05 100644 --- a/apps/core/lib/mix/legendary.ex +++ b/apps/core/lib/mix/legendary.ex @@ -1,4 +1,8 @@ defmodule Mix.Legendary do + @moduledoc """ + Parent module for all Legendary framework mix tasks. Provides some helpers + used by tasks and generators. + """ alias Mix.Phoenix.{Schema} @doc false diff --git a/mix.lock b/mix.lock index d791998f..35399717 100644 --- a/mix.lock +++ b/mix.lock @@ -11,7 +11,7 @@ "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"}, "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"}, - "credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"}, + "credo": {:hex, :credo, "1.5.6", "e04cc0fdc236fefbb578e0c04bd01a471081616e741d386909e527ac146016c6", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4b52a3e558bd64e30de62a648518a5ea2b6e3e5d2b164ef5296244753fc7eb17"}, "crontab": {:hex, :crontab, "1.1.10", "dc9bb1f4299138d47bce38341f5dcbee0aa6c205e864fba7bc847f3b5cb48241", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "1347d889d1a0eda997990876b4894359e34bfbbd688acbb0ba28a2795ca40685"}, "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"}, "decimal": {:hex, :decimal, "1.9.0", "83e8daf59631d632b171faabafb4a9f4242c514b0a06ba3df493951c08f64d07", [:mix], [], "hexpm", "b1f2343568eed6928f3e751cf2dffde95bfaa19dd95d09e8a9ea92ccfd6f7d85"},