Skip to content

Commit

Permalink
feat: doctest formatter (#496)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 authored Mar 21, 2024
1 parent 1968d58 commit 3466050
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -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}",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
run: mix format --check-formatted

- name: 🔍 Lint the code
run: mix credo --all --strict
run: mix credo --all --strict
36 changes: 26 additions & 10 deletions lib/atomic/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...}}
"""
Expand Down Expand Up @@ -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}
"""
Expand Down Expand Up @@ -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: ...}}
"""
Expand Down Expand Up @@ -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"})
Expand Down Expand Up @@ -496,7 +512,7 @@ defmodule Atomic.Accounts do
## Examples
iex> list_courses()
{:ok,[%Course{}]}
{:ok, [%Course{}]}
iex> list_courses()
{:error, %Ecto.Changeset{}}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/atomic/activities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 \\ %{})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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{}, ...]
"""
Expand Down
14 changes: 10 additions & 4 deletions lib/atomic/board.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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{}, ...]
"""
Expand All @@ -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)
Expand Down Expand Up @@ -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{}, ...]
"""
Expand All @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions lib/atomic/departments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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{}, ...]
"""
Expand All @@ -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)
Expand Down Expand Up @@ -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{}, ...]
"""
Expand Down Expand Up @@ -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{}, ...]
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/atomic/ecto/year.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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")]}
Expand Down
17 changes: 14 additions & 3 deletions lib/atomic/exporter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand Down
10 changes: 5 additions & 5 deletions lib/atomic/organizations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}, ...]
"""
Expand All @@ -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{}, ...]
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/atomic/partnerships.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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{}, ...]
"""
Expand Down
11 changes: 6 additions & 5 deletions lib/atomic_web/components/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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"},
Expand All @@ -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]
"""
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit 3466050

Please sign in to comment.