From 83104220c5a3756224a8739109a2a6fb4b102dcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Rodrigues?= Date: Thu, 21 Mar 2024 09:28:11 +0000 Subject: [PATCH] feat: doctest formatter --- .formatter.exs | 2 +- .github/workflows/style.yml | 2 +- lib/atomic/accounts.ex | 36 ++++++++++++++++++++-------- lib/atomic/activities.ex | 10 ++++---- lib/atomic/board.ex | 14 +++++++---- lib/atomic/departments.ex | 11 +++++---- lib/atomic/ecto/year.ex | 2 +- lib/atomic/exporter.ex | 17 ++++++++++--- lib/atomic/organizations.ex | 10 ++++---- lib/atomic/partnerships.ex | 2 +- lib/atomic_web/components/helpers.ex | 11 +++++---- mix.exs | 3 ++- mix.lock | 1 + 13 files changed, 80 insertions(+), 41 deletions(-) diff --git a/.formatter.exs b/.formatter.exs index 81d6a542b..5d9765e67 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,6 +1,6 @@ [ import_deps: [:ecto, :phoenix], - plugins: [Phoenix.LiveView.HTMLFormatter, TailwindFormatter.MultiFormatter], + plugins: [Phoenix.LiveView.HTMLFormatter, TailwindFormatter.MultiFormatter, DoctestFormatter], heex_line_length: 300, inputs: [ "*.{heex,ex,exs}", diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index a49136b48..45eea3494 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -30,4 +30,4 @@ jobs: run: mix format --check-formatted - name: 🔍 Lint the code - run: mix credo --all --strict + run: mix credo --all --strict \ No newline at end of file diff --git a/lib/atomic/accounts.ex b/lib/atomic/accounts.ex index a53cf0a8f..c79f0ec60 100644 --- a/lib/atomic/accounts.ex +++ b/lib/atomic/accounts.ex @@ -257,7 +257,11 @@ defmodule Atomic.Accounts do ## Examples - iex> deliver_update_email_instructions(user, current_email, &Routes.user_update_email_url(conn, :edit, &1)) + iex> deliver_update_email_instructions( + ...> user, + ...> current_email, + ...> &Routes.user_update_email_url(conn, :edit, &1) + ...> ) {:ok, %{to: ..., body: ...}} """ @@ -349,10 +353,16 @@ defmodule Atomic.Accounts do ## Examples - iex> deliver_user_confirmation_instructions(user, &Routes.user_confirmation_url(conn, :edit, &1)) + iex> deliver_user_confirmation_instructions( + ...> user, + ...> &Routes.user_confirmation_url(conn, :edit, &1) + ...> ) {:ok, %{to: ..., body: ...}} - iex> deliver_user_confirmation_instructions(confirmed_user, &Routes.user_confirmation_url(conn, :edit, &1)) + iex> deliver_user_confirmation_instructions( + ...> confirmed_user, + ...> &Routes.user_confirmation_url(conn, :edit, &1) + ...> ) {:error, :already_confirmed} """ @@ -396,7 +406,10 @@ defmodule Atomic.Accounts do ## Examples - iex> deliver_user_reset_password_instructions(user, &Routes.user_reset_password_url(conn, :edit, &1)) + iex> deliver_user_reset_password_instructions( + ...> user, + ...> &Routes.user_reset_password_url(conn, :edit, &1) + ...> ) {:ok, %{to: ..., body: ...}} """ @@ -433,7 +446,10 @@ defmodule Atomic.Accounts do ## Examples - iex> reset_user_password(user, %{password: "new long password", password_confirmation: "new long password"}) + iex> reset_user_password(user, %{ + ...> password: "new long password", + ...> password_confirmation: "new long password" + ...> }) {:ok, %User{}} iex> reset_user_password(user, %{password: "valid", password_confirmation: "not the same"}) @@ -496,7 +512,7 @@ defmodule Atomic.Accounts do ## Examples iex> list_courses() - {:ok,[%Course{}]} + {:ok, [%Course{}]} iex> list_courses() {:error, %Ecto.Changeset{}} @@ -528,10 +544,10 @@ defmodule Atomic.Accounts do ## Examples - iex> has_master_permissions?(a534b2c3-4d5e-6f7g-8h9i-0j1k2l3m4n5o6) + iex> has_master_permissions?("a534b2c3-4d5e-6f7g-8h9i-0j1k2l3m4n5o6") true - iex> has_master_permissions?(dcba4321-1a2b-3c4d-5e6f-7g8h9i0j1k2l3m) + iex> has_master_permissions?("dcba4321-1a2b-3c4d-5e6f-7g8h9i0j1k2l3m") false """ def has_master_permissions?(user_id) do @@ -546,10 +562,10 @@ defmodule Atomic.Accounts do ## Examples - iex> has_permissions_inside_organization?(a534b2c3-4d5e-6f7g-8h9i-0j1k2l3m4n5o6, 1) + iex> has_permissions_inside_organization?("a534b2c3-4d5e-6f7g-8h9i-0j1k2l3m4n5o6", 1) true - iex> has_permissions_inside_organization?(dcba4321-1a2b-3c4d-5e6f-7g8h9i0j1k2l3m, 1) + iex> has_permissions_inside_organization?("dcba4321-1a2b-3c4d-5e6f-7g8h9i0j1k2l3m", 1) false """ def has_permissions_inside_organization?(user_id, organization_id) do diff --git a/lib/atomic/activities.ex b/lib/atomic/activities.ex index 205f7f7c5..fc917fe1b 100644 --- a/lib/atomic/activities.ex +++ b/lib/atomic/activities.ex @@ -41,10 +41,10 @@ defmodule Atomic.Activities do ## Examples - iex> list_activities_by_organization_id((99d7c9e5-4212-4f59-a097-28aaa33c2621, opts) + iex> list_activities_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621", opts) [%Activity{}, ...] - iex> list_activities_by_organization_id((99d7c9e5-4212-4f59-a097-28aaa33c2621, opts) + iex> list_activities_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621", opts) ** (Ecto.NoResultsError) """ def list_activities_by_organization_id(organization_id, params \\ %{}) @@ -180,13 +180,13 @@ defmodule Atomic.Activities do ## Examples - iex> create_activity_with_post(%{field: value, ~N[2020-01-01 00:00:00]}) + iex> create_activity_with_post(%{field: value, field: ~N[2020-01-01 00:00:00]}) {:ok, %Activity{}} iex> create_activity_with_post(%{field: value}) {:error, %Ecto.Changeset{}} - iex> create_activity_with_post(%{field: bad_value, ~N[2020-01-01 00:00:00]}) + iex> create_activity_with_post(%{field: bad_value, field: ~N[2020-01-01 00:00:00]}) {:error, %Ecto.Changeset{}} iex> create_activit__with_post(%{field: bad_value}) @@ -541,7 +541,7 @@ defmodule Atomic.Activities do ## Examples - iex> list_speakers_by_organization_id(99d7c9e5-4212-4f59-a097-28aaa33c2621) + iex> list_speakers_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") [%Speaker{}, ...] """ diff --git a/lib/atomic/board.ex b/lib/atomic/board.ex index 04503fbb1..b37cf65c6 100644 --- a/lib/atomic/board.ex +++ b/lib/atomic/board.ex @@ -26,7 +26,7 @@ defmodule Atomic.Board do ## Examples - iex> list_boards_by_organization_id(99d7c9e5-4212-4f59-a097-28aaa33c2621) + iex> list_boards_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") [%Board{}, ...] """ @@ -39,7 +39,10 @@ defmodule Atomic.Board do ## Examples - iex> get_boards([99d7c9e5-4212-4f59-a097-28aaa33c2621, 99d7c9e5-4212-4f59-a097-28aaa33c2621]) + iex> get_boards([ + ...> "99d7c9e5-4212-4f59-a097-28aaa33c2621", + ...> "99d7c9e5-4212-4f59-a097-28aaa33c2621" + ...> ]) [%Board{}, ...] iex> get_boards(nil) @@ -158,7 +161,7 @@ defmodule Atomic.Board do ## Examples - iex> list_board_departments_by_organization_id(99d7c9e5-4212-4f59-a097-28aaa33c2621) + iex> list_board_departments_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") [%BoardDepartments{}, ...] """ @@ -171,7 +174,10 @@ defmodule Atomic.Board do ## Examples - iex> get_board_departments([99d7c9e5-4212-4f59-a097-28aaa33c2621, 99d7c9e5-4212-4f59-a097-28aaa33c2621]) + iex> get_board_departments([ + ...> "99d7c9e5-4212-4f59-a097-28aaa33c2621", + ...> "99d7c9e5-4212-4f59-a097-28aaa33c2621" + ...> ]) [%BoardDepartments{}, ...] iex> get_board_departments(nil) diff --git a/lib/atomic/departments.ex b/lib/atomic/departments.ex index 113d4d44d..facb25a1a 100644 --- a/lib/atomic/departments.ex +++ b/lib/atomic/departments.ex @@ -24,7 +24,7 @@ defmodule Atomic.Departments do ## Examples - iex> list_departments_by_organization_id(99d7c9e5-4212-4f59-a097-28aaa33c2621) + iex> list_departments_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") [%Department{}, ...] """ @@ -40,7 +40,10 @@ defmodule Atomic.Departments do ## Examples - iex> get_departments([99d7c9e5-4212-4f59-a097-28aaa33c2621, 99d7c9e5-4212-4f59-a097-28aaa33c2621]) + iex> get_departments([ + ...> "99d7c9e5-4212-4f59-a097-28aaa33c2621", + ...> "99d7c9e5-4212-4f59-a097-28aaa33c2621" + ...> ]) [%Department{}, ...] iex> get_departments(nil) @@ -155,7 +158,7 @@ defmodule Atomic.Departments do ## Examples - iex> list_collaborators_by_organization_id(99d7c9e5-4212-4f59-a097-28aaa33c2621) + iex> list_collaborators_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") [%Collaborator{}, ...] """ @@ -282,7 +285,7 @@ defmodule Atomic.Departments do ## Examples - iex> list_collaborators_by_department_id(99d7c9e5-4212-4f59-a097-28aaa33c2621) + iex> list_collaborators_by_department_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") [%Collaborator{}, ...] """ diff --git a/lib/atomic/ecto/year.ex b/lib/atomic/ecto/year.ex index 25bbe054f..ab135b060 100644 --- a/lib/atomic/ecto/year.ex +++ b/lib/atomic/ecto/year.ex @@ -19,7 +19,7 @@ defmodule Atomic.Ecto.Year do {:ok, "2019/2020"} iex> Year.cast("2019-2020") - {:error, [message: "Invalid string format"]} + {:error, [message: "Invalid string format"]} iex> Year.cast("2019-2021") {:error, [message: gettext("Second year is not the first + 1")]} diff --git a/lib/atomic/exporter.ex b/lib/atomic/exporter.ex index 3354bb3c1..750ab0ace 100644 --- a/lib/atomic/exporter.ex +++ b/lib/atomic/exporter.ex @@ -13,10 +13,16 @@ defmodule Atomic.Exporter do ## Examples - iex> entities_to_csv([%{name: "John Doe", age: 23}, %{name: "Jane Doe", age: 25}], [[:name], [:age]]) + iex> entities_to_csv([%{name: "John Doe", age: 23}, %{name: "Jane Doe", age: 25}], [ + ...> [:name], + ...> [:age] + ...> ]) "name,age\\nJohn Doe,23\\nJane Doe,25" - iex> entities_to_csv([%{name: "John Doe", age: 23, dog: %{name: "Cooper", breed: "Beagle"}}], [[:name], [:dog, :breed]]) + iex> entities_to_csv([%{name: "John Doe", age: 23, dog: %{name: "Cooper", breed: "Beagle"}}], [ + ...> [:name], + ...> [:dog, :breed] + ...> ]) "name,breed\\nJohn Doe,Beagle" """ def entities_to_csv(entities, columns) do @@ -38,7 +44,12 @@ defmodule Atomic.Exporter do ## Examples - iex> entities_to_xlsx_workbook([%{name: "John Doe", age: 23}, %{name: "Jane Doe", age: 25}], [[[:name], 20], [[:age], 10]], [], "People") + iex> entities_to_xlsx_workbook( + ...> [%{name: "John Doe", age: 23}, %{name: "Jane Doe", age: 25}], + ...> [[[:name], 20], [[:age], 10]], + ...> [], + ...> "People" + ...> ) %Elixlsx.Workbook{ sheets: [ %Elixlsx.Sheet{ diff --git a/lib/atomic/organizations.ex b/lib/atomic/organizations.ex index 8b9ba784b..3024a6cf5 100644 --- a/lib/atomic/organizations.ex +++ b/lib/atomic/organizations.ex @@ -504,11 +504,11 @@ defmodule Atomic.Organizations do ## Examples - iex> count_followers(organization_id) + iex> count_followers("99d7c9e5-4212-4f59-a097-28aaa33c2621") 5 - iex> count_followers(organization_id) when organization_id == CeSIUM.id - 100000000000000000000000000 + iex> count_followers("9as7c9e5-4212-4f59-a097-28aaa33c2621") + 100_000_000_000_000_000_000_000_000 """ def count_followers(organization_id) do Membership @@ -665,7 +665,7 @@ defmodule Atomic.Organizations do ## Examples - iex> list_announcements_by_organization_id(99d7c9e5-4212-4f59-a097-28aaa33c2621) + iex> list_announcements_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") [%Announcement{}, ...] """ @@ -681,7 +681,7 @@ defmodule Atomic.Organizations do ## Examples - iex> list_announcements_by_organization_id(99d7c9e5-4212-4f59-a097-28aaa33c2621) + iex> list_announcements_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") [%Announcement{}, ...] """ diff --git a/lib/atomic/partnerships.ex b/lib/atomic/partnerships.ex index 519393396..ce90de4b8 100644 --- a/lib/atomic/partnerships.ex +++ b/lib/atomic/partnerships.ex @@ -30,7 +30,7 @@ defmodule Atomic.Partners do ## Examples - iex> list_partners_by_organization_id(99d7c9e5-4212-4f59-a097-28aaa33c2621) + iex> list_partners_by_organization_id("99d7c9e5-4212-4f59-a097-28aaa33c2621") [%Partner{}, ...] """ diff --git a/lib/atomic_web/components/helpers.ex b/lib/atomic_web/components/helpers.ex index 8563303a3..beee3c9b2 100644 --- a/lib/atomic_web/components/helpers.ex +++ b/lib/atomic_web/components/helpers.ex @@ -19,17 +19,17 @@ defmodule AtomicWeb.Components.Helpers do [] iex> f = %Flop{order_by: [:name, :age], order_directions: [:desc, :asc]} - iex> to_query(f) + ...> to_query(f) [order_directions: [:desc, :asc], order_by: [:name, :age]] iex> f |> to_query |> Plug.Conn.Query.encode() "order_directions[]=desc&order_directions[]=asc&order_by[]=name&order_by[]=age" iex> f = %Flop{page: 5, page_size: 20} - iex> to_query(f) + ...> to_query(f) [page_size: 20, page: 5] iex> f = %Flop{first: 20, after: "g3QAAAABZAAEbmFtZW0AAAAFQXBwbGU="} - iex> to_query(f) + ...> to_query(f) [first: 20, after: "g3QAAAABZAAEbmFtZW0AAAAFQXBwbGU="] iex> f = %Flop{ @@ -38,7 +38,8 @@ defmodule AtomicWeb.Components.Helpers do ...> %Flop.Filter{field: :age, op: :>, value: 25} ...> ] ...> } - iex> to_query(f) + ...> + ...> to_query(f) [ filters: %{ 0 => %{field: :name, op: :=~, value: "Mag"}, @@ -49,7 +50,7 @@ defmodule AtomicWeb.Components.Helpers do "filters[0][field]=name&filters[0][op]=%3D~&filters[0][value]=Mag&filters[1][field]=age&filters[1][op]=%3E&filters[1][value]=25" iex> f = %Flop{page: 5, page_size: 20} - iex> to_query(f, default_limit: 20) + ...> to_query(f, default_limit: 20) [page: 5] """ diff --git a/mix.exs b/mix.exs index 3c7b6b305..b91337c56 100644 --- a/mix.exs +++ b/mix.exs @@ -91,7 +91,8 @@ defmodule Atomic.MixProject do {:pdf_generator, "~> 0.6.2"}, {:quantum, "~> 3.0"}, {:credo, "~> 1.6", only: [:dev, :test], runtime: false}, - {:elixlsx, "~> 0.5.1"} + {:elixlsx, "~> 0.5.1"}, + {:doctest_formatter, "~> 0.2.0", runtime: false} ] end diff --git a/mix.lock b/mix.lock index ec5f995fd..3a5e04069 100644 --- a/mix.lock +++ b/mix.lock @@ -12,6 +12,7 @@ "crontab": {:hex, :crontab, "1.1.13", "3bad04f050b9f7f1c237809e42223999c150656a6b2afbbfef597d56df2144c5", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm", "d67441bec989640e3afb94e123f45a2bc42d76e02988c9613885dc3d01cf7085"}, "db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, + "doctest_formatter": {:hex, :doctest_formatter, "0.2.0", "fe6198e8d81d833269314696b5bb55c0db0e16f609de53cdcafe1758f53ecf6c", [:mix], [], "hexpm", "34fb0da7cbb704d5caf477e77268fcf7ee9c87e13d94a04ea1865afb9e82e3f5"}, "earmark": {:hex, :earmark, "1.4.46", "8c7287bd3137e99d26ae4643e5b7ef2129a260e3dcf41f251750cb4563c8fb81", [:mix], [], "hexpm", "798d86db3d79964e759ddc0c077d5eb254968ed426399fbf5a62de2b5ff8910a"}, "ecto": {:hex, :ecto, "3.11.0", "ff8614b4e70a774f9d39af809c426def80852048440e8785d93a6e91f48fec00", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7769dad267ef967310d6e988e92d772659b11b09a0c015f101ce0fff81ce1f81"}, "ecto_sql": {:hex, :ecto_sql, "3.11.0", "c787b24b224942b69c9ff7ab9107f258ecdc68326be04815c6cce2941b6fad1c", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.11.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "77aa3677169f55c2714dda7352d563002d180eb33c0dc29cd36d39c0a1a971f5"},