From 410a509faaf730f321d4cdd53135419cb440254d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Dubas?= Date: Fri, 22 Apr 2022 00:49:00 +0000 Subject: [PATCH] chore: apply credo suggestions (#3) Mainly add module docs and fix some aliases. --- lib/wabanex/exercise.ex | 3 +++ lib/wabanex/imc.ex | 10 +++++----- lib/wabanex/training.ex | 3 +++ lib/wabanex/trainings/create.ex | 5 ++++- lib/wabanex/user.ex | 3 +++ lib/wabanex/users/create.ex | 3 +++ lib/wabanex/users/get.ex | 3 +++ lib/wabanex_web/resolvers/training.ex | 3 +++ lib/wabanex_web/resolvers/user.ex | 3 +++ lib/wabanex_web/schema.ex | 3 +++ lib/wabanex_web/schema/types/custom/date_range.ex | 3 +++ lib/wabanex_web/schema/types/custom/uuid4.ex | 3 +++ lib/wabanex_web/schema/types/exercise.ex | 3 +++ lib/wabanex_web/schema/types/root.ex | 5 ++++- lib/wabanex_web/schema/types/training.ex | 3 +++ lib/wabanex_web/schema/types/user.ex | 3 +++ lib/wabanex_web/telemetry.ex | 3 +++ test/support/channel_case.ex | 6 ++++-- test/support/conn_case.ex | 6 ++++-- test/support/data_case.ex | 6 ++++-- 20 files changed, 67 insertions(+), 13 deletions(-) diff --git a/lib/wabanex/exercise.ex b/lib/wabanex/exercise.ex index f131ed7..811e299 100644 --- a/lib/wabanex/exercise.ex +++ b/lib/wabanex/exercise.ex @@ -1,4 +1,7 @@ defmodule Wabanex.Exercise do + @moduledoc """ + Schema of a exercise contained within a training. + """ use Ecto.Schema import Ecto.Changeset diff --git a/lib/wabanex/imc.ex b/lib/wabanex/imc.ex index ef14632..f3f1799 100644 --- a/lib/wabanex/imc.ex +++ b/lib/wabanex/imc.ex @@ -1,4 +1,8 @@ defmodule Wabanex.IMC do + @moduledoc """ + Body mass index calculation + """ + def calculate(%{"filename" => filename}) do filename |> File.read() @@ -7,11 +11,7 @@ defmodule Wabanex.IMC do defp handle_file({:ok, content}) do data = - content - |> String.trim() - |> String.split("\n") - |> Enum.map(&parse_line/1) - |> Enum.into(%{}) + content |> String.trim() |> String.split("\n") |> Enum.map(&parse_line/1) |> Enum.into(%{}) {:ok, data} end diff --git a/lib/wabanex/training.ex b/lib/wabanex/training.ex index ef5e014..f85fe0b 100644 --- a/lib/wabanex/training.ex +++ b/lib/wabanex/training.ex @@ -1,4 +1,7 @@ defmodule Wabanex.Training do + @moduledoc """ + Schema of a training routine for a given period of time. + """ use Ecto.Schema import Ecto.Changeset diff --git a/lib/wabanex/trainings/create.ex b/lib/wabanex/trainings/create.ex index e3be003..0822bc3 100644 --- a/lib/wabanex/trainings/create.ex +++ b/lib/wabanex/trainings/create.ex @@ -1,5 +1,8 @@ defmodule Wabanex.Trainings.Create do - alias Wabanex.{Training, Repo} + @moduledoc """ + Context to create a training routine. + """ + alias Wabanex.{Repo, Training} def call(params) do params diff --git a/lib/wabanex/user.ex b/lib/wabanex/user.ex index c93e2ff..eebc773 100644 --- a/lib/wabanex/user.ex +++ b/lib/wabanex/user.ex @@ -1,4 +1,7 @@ defmodule Wabanex.User do + @moduledoc """ + Schema of a user in the system. + """ use Ecto.Schema import Ecto.Changeset diff --git a/lib/wabanex/users/create.ex b/lib/wabanex/users/create.ex index 240728f..5555a82 100644 --- a/lib/wabanex/users/create.ex +++ b/lib/wabanex/users/create.ex @@ -1,4 +1,7 @@ defmodule Wabanex.Users.Create do + @moduledoc """ + Context for user creation. + """ alias Wabanex.{Repo, User} def call(params) do diff --git a/lib/wabanex/users/get.ex b/lib/wabanex/users/get.ex index 22b0fc0..65a873f 100644 --- a/lib/wabanex/users/get.ex +++ b/lib/wabanex/users/get.ex @@ -1,4 +1,7 @@ defmodule Wabanex.Users.Get do + @moduledoc """ + Context to fetch a given user and its current training. + """ import Ecto.Query alias Wabanex.{Repo, Training, User} diff --git a/lib/wabanex_web/resolvers/training.ex b/lib/wabanex_web/resolvers/training.ex index 5d46085..897dbcb 100644 --- a/lib/wabanex_web/resolvers/training.ex +++ b/lib/wabanex_web/resolvers/training.ex @@ -1,4 +1,7 @@ defmodule WabanexWeb.Resolvers.Training do + @moduledoc """ + GraphQL resolver for training operations. + """ alias Wabanex.Trainings def create(%{input: params}, _context), do: Trainings.Create.call(params) diff --git a/lib/wabanex_web/resolvers/user.ex b/lib/wabanex_web/resolvers/user.ex index 219edb1..a70debc 100644 --- a/lib/wabanex_web/resolvers/user.ex +++ b/lib/wabanex_web/resolvers/user.ex @@ -1,4 +1,7 @@ defmodule WabanexWeb.Resolvers.User do + @moduledoc """ + GraphQL resolver for user operations. + """ alias Wabanex.Users def get(%{id: user_id}, _context), do: Users.Get.call(user_id) diff --git a/lib/wabanex_web/schema.ex b/lib/wabanex_web/schema.ex index e4b30ed..fc80596 100644 --- a/lib/wabanex_web/schema.ex +++ b/lib/wabanex_web/schema.ex @@ -1,4 +1,7 @@ defmodule WabanexWeb.Schema do + @moduledoc """ + GraphQL schema definition + """ use Absinthe.Schema import_types WabanexWeb.Schema.Types.Root diff --git a/lib/wabanex_web/schema/types/custom/date_range.ex b/lib/wabanex_web/schema/types/custom/date_range.ex index d57e1ab..c32d58e 100644 --- a/lib/wabanex_web/schema/types/custom/date_range.ex +++ b/lib/wabanex_web/schema/types/custom/date_range.ex @@ -1,4 +1,7 @@ defmodule WabanexWeb.Schema.Types.Custom.DateRange do + @moduledoc """ + Graphql date range custom type. + """ use Absinthe.Schema.Notation alias Absinthe.Blueprint.Input diff --git a/lib/wabanex_web/schema/types/custom/uuid4.ex b/lib/wabanex_web/schema/types/custom/uuid4.ex index 3c541fc..ab0745a 100644 --- a/lib/wabanex_web/schema/types/custom/uuid4.ex +++ b/lib/wabanex_web/schema/types/custom/uuid4.ex @@ -1,4 +1,7 @@ defmodule WabanexWeb.Schema.Types.Custom.UUID4 do + @moduledoc """ + GraphQL uuid v4 custom type. + """ use Absinthe.Schema.Notation alias Ecto.UUID diff --git a/lib/wabanex_web/schema/types/exercise.ex b/lib/wabanex_web/schema/types/exercise.ex index 8d2c2c4..a1ba703 100644 --- a/lib/wabanex_web/schema/types/exercise.ex +++ b/lib/wabanex_web/schema/types/exercise.ex @@ -1,4 +1,7 @@ defmodule WabanexWeb.Schema.Types.Exercise do + @moduledoc """ + GraphQL exercise type definition. + """ use Absinthe.Schema.Notation @desc "Logic exercise representation" diff --git a/lib/wabanex_web/schema/types/root.ex b/lib/wabanex_web/schema/types/root.ex index 2f2b542..5bfd8b3 100644 --- a/lib/wabanex_web/schema/types/root.ex +++ b/lib/wabanex_web/schema/types/root.ex @@ -1,10 +1,13 @@ defmodule WabanexWeb.Schema.Types.Root do + @moduledoc """ + GraphQL root query/mutation aggregator. + """ use Absinthe.Schema.Notation alias Crudry.Middlewares.TranslateErrors - alias WabanexWeb.Resolvers.User, as: UserResolver alias WabanexWeb.Resolvers.Training, as: TrainingResolver + alias WabanexWeb.Resolvers.User, as: UserResolver alias WabanexWeb.Schema.Types import_types Types.Custom.UUID4 diff --git a/lib/wabanex_web/schema/types/training.ex b/lib/wabanex_web/schema/types/training.ex index bbf9811..b8811c7 100644 --- a/lib/wabanex_web/schema/types/training.ex +++ b/lib/wabanex_web/schema/types/training.ex @@ -1,4 +1,7 @@ defmodule WabanexWeb.Schema.Types.Training do + @moduledoc """ + GraphQL training type definition. + """ use Absinthe.Schema.Notation import_types WabanexWeb.Schema.Types.Custom.DateRange diff --git a/lib/wabanex_web/schema/types/user.ex b/lib/wabanex_web/schema/types/user.ex index 149737d..a8b8c02 100644 --- a/lib/wabanex_web/schema/types/user.ex +++ b/lib/wabanex_web/schema/types/user.ex @@ -1,4 +1,7 @@ defmodule WabanexWeb.Schema.Types.User do + @moduledoc """ + GraphQL user type definition. + """ use Absinthe.Schema.Notation @desc "Logic user representation" diff --git a/lib/wabanex_web/telemetry.ex b/lib/wabanex_web/telemetry.ex index 9e4f9ab..0511bd4 100644 --- a/lib/wabanex_web/telemetry.ex +++ b/lib/wabanex_web/telemetry.ex @@ -1,4 +1,7 @@ defmodule WabanexWeb.Telemetry do + @moduledoc """ + Telemetry implementation + """ use Supervisor import Telemetry.Metrics diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex index 374f33b..25f13e6 100644 --- a/test/support/channel_case.ex +++ b/test/support/channel_case.ex @@ -17,6 +17,8 @@ defmodule WabanexWeb.ChannelCase do use ExUnit.CaseTemplate + alias Ecto.Adapters.SQL.Sandbox + using do quote do # Import conveniences for testing with channels @@ -29,10 +31,10 @@ defmodule WabanexWeb.ChannelCase do end setup tags do - :ok = Ecto.Adapters.SQL.Sandbox.checkout(Wabanex.Repo) + :ok = Sandbox.checkout(Wabanex.Repo) unless tags[:async] do - Ecto.Adapters.SQL.Sandbox.mode(Wabanex.Repo, {:shared, self()}) + Sandbox.mode(Wabanex.Repo, {:shared, self()}) end :ok diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 7ed6d82..5f48cdd 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -17,6 +17,8 @@ defmodule WabanexWeb.ConnCase do use ExUnit.CaseTemplate + alias Ecto.Adapters.SQL.Sandbox + using do quote do # Import conveniences for testing with connections @@ -32,10 +34,10 @@ defmodule WabanexWeb.ConnCase do end setup tags do - :ok = Ecto.Adapters.SQL.Sandbox.checkout(Wabanex.Repo) + :ok = Sandbox.checkout(Wabanex.Repo) unless tags[:async] do - Ecto.Adapters.SQL.Sandbox.mode(Wabanex.Repo, {:shared, self()}) + Sandbox.mode(Wabanex.Repo, {:shared, self()}) end {:ok, conn: Phoenix.ConnTest.build_conn()} diff --git a/test/support/data_case.ex b/test/support/data_case.ex index 9490696..11a2122 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -16,6 +16,8 @@ defmodule Wabanex.DataCase do use ExUnit.CaseTemplate + alias Ecto.Adapters.SQL.Sandbox + using do quote do alias Wabanex.Repo @@ -28,10 +30,10 @@ defmodule Wabanex.DataCase do end setup tags do - :ok = Ecto.Adapters.SQL.Sandbox.checkout(Wabanex.Repo) + :ok = Sandbox.checkout(Wabanex.Repo) unless tags[:async] do - Ecto.Adapters.SQL.Sandbox.mode(Wabanex.Repo, {:shared, self()}) + Sandbox.mode(Wabanex.Repo, {:shared, self()}) end :ok