diff --git a/.github/workflows/elixir-ci.yaml b/.github/workflows/elixir-ci.yaml
new file mode 100644
index 00000000..5d7ae659
--- /dev/null
+++ b/.github/workflows/elixir-ci.yaml
@@ -0,0 +1,45 @@
+# This workflow uses actions that are not certified by GitHub.
+# They are provided by a third-party and are governed by
+# separate terms of service, privacy policy, and support
+# documentation.
+
+name: Elixir CI
+
+on:
+ push:
+ branches: ["main"]
+ pull_request:
+ branches: ["main"]
+
+permissions:
+ contents: read
+
+jobs:
+ build:
+ name: Build and test
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+ - name: Set up Elixir
+ uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0
+ with:
+ elixir-version: "1.17.3" # [Required] Define the Elixir version
+ otp-version: "27.1.2" # [Required] Define the Erlang/OTP version
+ - name: Restore dependencies cache
+ uses: actions/cache@v3
+ with:
+ path: deps
+ key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
+ restore-keys: ${{ runner.os }}-mix-
+
+ - name: Setup project
+ run: mix setup
+ - name: Check formatting
+ run: mix format --check-formatted
+ - name: Check credo
+ run: mix credo
+ - name: Check prettier
+ run: (cd assets && npx prettier . --check)
+ - name: Run tests
+ run: mix test
diff --git a/lib/live_debugger.ex b/lib/live_debugger.ex
index ef548c59..6c0a5feb 100644
--- a/lib/live_debugger.ex
+++ b/lib/live_debugger.ex
@@ -1,4 +1,8 @@
defmodule LiveDebugger do
+ @moduledoc """
+ Debugger for LiveView applications.
+ """
+
use Phoenix.Component
attr(:redirect_url, :string, required: true, doc: "The URL of the debugger, e.g. `/dbg`")
diff --git a/lib/live_debugger/components/tooltip.ex b/lib/live_debugger/components/tooltip.ex
index 9c860d3b..e971ac74 100644
--- a/lib/live_debugger/components/tooltip.ex
+++ b/lib/live_debugger/components/tooltip.ex
@@ -1,4 +1,8 @@
defmodule LiveDebugger.Components.Tooltip do
+ @moduledoc """
+ This module provides a Tooltip component.
+ """
+
use LiveDebuggerWeb, :component
@doc """
diff --git a/lib/live_debugger/components/tree.ex b/lib/live_debugger/components/tree.ex
index 73240411..fe9dbafb 100644
--- a/lib/live_debugger/components/tree.ex
+++ b/lib/live_debugger/components/tree.ex
@@ -1,4 +1,8 @@
defmodule LiveDebugger.Components.Tree do
+ @moduledoc """
+ Tree component which show nested tree of live view and live components.
+ """
+
use LiveDebuggerWeb, :component
alias LiveDebugger.Components.Collapsible
diff --git a/lib/live_debugger/layout.ex b/lib/live_debugger/layout.ex
index 63a3adb5..1307452e 100644
--- a/lib/live_debugger/layout.ex
+++ b/lib/live_debugger/layout.ex
@@ -49,7 +49,6 @@ defmodule LiveDebugger.Layout do
"""
end
- # TODO: Remove this and the conditional on Phoenix v1.7+
@compile {:no_warn_undefined, Phoenix.VerifiedRoutes}
defp asset_path(conn, asset) when asset in [:css, :js] do
diff --git a/lib/live_debugger/live_views/socket_dashboard_live.ex b/lib/live_debugger/live_views/socket_dashboard_live.ex
index a652434c..64c20e64 100644
--- a/lib/live_debugger/live_views/socket_dashboard_live.ex
+++ b/lib/live_debugger/live_views/socket_dashboard_live.ex
@@ -19,20 +19,12 @@ defmodule LiveDebugger.LiveViews.SocketDashboardLive do
def render(assigns) do
~H"""
<.loading_variant :if={@debugged_pid.status == :loading} />
-
-
- <.live_component
- :if={@debugged_pid.status == :ok}
- id="sidebar"
- module={LiveDebugger.LiveComponents.Sidebar}
- pid={@debugged_pid.result}
- socket_id={@socket_id}
- />
-
- <.not_found_component :if={@debugged_pid.status == :not_found} />
- <.error_component :if={@debugged_pid.status == :error} />
-
-
+ <.not_found_component :if={@debugged_pid.status == :not_found} />
+ <.error_component :if={@debugged_pid.status == :error} />
+ <.container :if={@debugged_pid.status == :ok} max_width="full">
+ Monitored socket: {@socket_id}
+ Debugged PID: {inspect(@debugged_pid.result)}
+
"""
end
@@ -124,6 +116,7 @@ defmodule LiveDebugger.LiveViews.SocketDashboardLive do
defp assign_async_debugged_pid(socket) do
socket_id = socket.assigns.socket_id
+ # credo:disable-for-lines:9
socket
|> assign(:debugged_pid, %{status: :loading})
|> start_async(:fetch_debugged_pid, fn ->
diff --git a/lib/live_debugger/services/channel_state_scraper.ex b/lib/live_debugger/services/channel_state_scraper.ex
index 8244cbd2..458b045a 100644
--- a/lib/live_debugger/services/channel_state_scraper.ex
+++ b/lib/live_debugger/services/channel_state_scraper.ex
@@ -1,4 +1,8 @@
defmodule LiveDebugger.Services.ChannelStateScraper do
+ @moduledoc """
+ This module provides functions that performs operation on state of LiveView channel.
+ """
+
alias LiveDebugger.Services.TreeNode
alias LiveDebugger.Services.LiveViewScraper
diff --git a/lib/live_debugger/services/live_view_scraper.ex b/lib/live_debugger/services/live_view_scraper.ex
index c1672ea3..25a627da 100644
--- a/lib/live_debugger/services/live_view_scraper.ex
+++ b/lib/live_debugger/services/live_view_scraper.ex
@@ -1,4 +1,6 @@
defmodule LiveDebugger.Services.LiveViewScraper do
+ @moduledoc false
+
@callback channel_state_from_pid(pid :: pid()) :: {:ok, map()} | {:error, term()}
@callback pid_by_socket_id(socket_id :: String.t()) :: pid() | nil
@callback pids() :: [pid()]
diff --git a/lib/live_debugger/services/module_discovery.ex b/lib/live_debugger/services/module_discovery.ex
index 4894bef5..fdac2d3c 100644
--- a/lib/live_debugger/services/module_discovery.ex
+++ b/lib/live_debugger/services/module_discovery.ex
@@ -1,4 +1,8 @@
defmodule LiveDebugger.Services.ModuleDiscovery do
+ @moduledoc """
+ This module provides functions to discover LiveViews and LiveComponents in the current application.
+ """
+
@live_view_behaviour Phoenix.LiveView
@live_component_behaviour Phoenix.LiveComponent
@@ -18,6 +22,7 @@ defmodule LiveDebugger.Services.ModuleDiscovery do
loaded_modules
|> Enum.map(fn {module, _} -> module end)
|> Enum.filter(&loaded?/1)
+ |> Enum.reject(&debugger?/1)
|> Enum.filter(&behaviour?(&1, behaviour))
end
@@ -27,4 +32,11 @@ defmodule LiveDebugger.Services.ModuleDiscovery do
module_behaviours = module.module_info(:attributes)[:behaviour] || []
Enum.member?(module_behaviours, behaviour_to_find)
end
+
+ defp debugger?(module) do
+ stringified_module = Atom.to_string(module)
+
+ String.starts_with?(stringified_module, "LiveDebugger.") or
+ String.starts_with?(stringified_module, "Elixir.LiveDebugger.")
+ end
end
diff --git a/lib/live_debugger/services/tree_node.ex b/lib/live_debugger/services/tree_node.ex
index c187cf76..8c04eae2 100644
--- a/lib/live_debugger/services/tree_node.ex
+++ b/lib/live_debugger/services/tree_node.ex
@@ -1,5 +1,5 @@
defmodule LiveDebugger.Services.TreeNode do
- @doc """
+ @moduledoc """
This module provides functions to work with the tree of LiveView and LiveComponent nodes (TreeNodes).
"""
alias LiveDebugger.Services.TreeNode.LiveView, as: LiveViewNode
diff --git a/lib/live_debugger/services/tree_node/live_component.ex b/lib/live_debugger/services/tree_node/live_component.ex
index 911a9120..4950136d 100644
--- a/lib/live_debugger/services/tree_node/live_component.ex
+++ b/lib/live_debugger/services/tree_node/live_component.ex
@@ -1,4 +1,6 @@
defmodule LiveDebugger.Services.TreeNode.LiveComponent do
+ @moduledoc false
+
defstruct [:id, :cid, :module, :assigns, :children]
@type cid() :: integer() | nil
diff --git a/lib/live_debugger/utils/callbacks.ex b/lib/live_debugger/utils/callbacks.ex
index 9991b809..8479f491 100644
--- a/lib/live_debugger/utils/callbacks.ex
+++ b/lib/live_debugger/utils/callbacks.ex
@@ -1,4 +1,8 @@
defmodule LiveDebugger.Utils.Callbacks do
+ @moduledoc """
+ This module provides functions to generate a list of callbacks for LiveViews and LiveComponents.
+ """
+
alias LiveDebugger.Services.ModuleDiscovery
@common_callbacks [
diff --git a/lib/live_debugger_web.ex b/lib/live_debugger_web.ex
index 1e2e3b68..c65e2678 100644
--- a/lib/live_debugger_web.ex
+++ b/lib/live_debugger_web.ex
@@ -1,4 +1,6 @@
defmodule LiveDebuggerWeb do
+ @moduledoc false
+
def live_view do
quote do
use Phoenix.LiveView,
@@ -51,6 +53,8 @@ defmodule LiveDebuggerWeb do
end
defmodule LiveDebuggerWeb.Helpers do
+ @moduledoc false
+
def ok(socket), do: {:ok, socket}
def noreply(socket), do: {:noreply, socket}
end
diff --git a/mix.exs b/mix.exs
index 81c61669..aefe330f 100644
--- a/mix.exs
+++ b/mix.exs
@@ -28,7 +28,6 @@ defmodule LiveDebugger.MixProject do
[
setup: ["deps.get", "cmd --cd assets npm install", "assets.setup", "assets.build"],
dev: "run --no-halt dev.exs",
- "js.format": ["cmd --cd assets prettier . --write"],
"assets.setup": ["esbuild.install --if-missing", "tailwind.install --if-missing"],
"assets.build": ["esbuild default --minify", "tailwind live_debugger --minify"]
]
@@ -49,7 +48,8 @@ defmodule LiveDebugger.MixProject do
{:phoenix_live_reload, "~> 1.5", only: :dev},
{:esbuild, "~> 0.7", only: :dev},
{:tailwind, "~> 0.2", only: :dev},
- {:mox, "~> 1.2", only: :test}
+ {:mox, "~> 1.2", only: :test},
+ {:credo, "~> 1.7", only: [:dev, :test], runtime: false}
]
end
end
diff --git a/mix.lock b/mix.lock
index 5d2bc48e..034e2057 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,6 +1,8 @@
%{
"bandit": {:hex, :bandit, "1.6.1", "9e01b93d72ddc21d8c576a704949e86ee6cde7d11270a1d3073787876527a48f", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5a904bf010ea24b67979835e0507688e31ac873d4ffc8ed0e5413e8d77455031"},
+ "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"castore": {:hex, :castore, "1.0.10", "43bbeeac820f16c89f79721af1b3e092399b3a1ecc8df1a472738fd853574911", [:mix], [], "hexpm", "1b0b7ea14d889d9ea21202c43a4fa015eb913021cb535e8ed91946f4b77a8848"},
+ "credo": {:hex, :credo, "1.7.11", "d3e805f7ddf6c9c854fd36f089649d7cf6ba74c42bc3795d587814e3c9847102", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "56826b4306843253a66e47ae45e98e7d284ee1f95d53d1612bb483f88a8cf219"},
"decimal": {:hex, :decimal, "2.2.0", "df3d06bb9517e302b1bd265c1e7f16cda51547ad9d99892049340841f3e15836", [:mix], [], "hexpm", "af8daf87384b51b7e611fb1a1f2c4d4876b65ef968fa8bd3adf44cff401c7f21"},
"ecto": {:hex, :ecto, "3.12.5", "4a312960ce612e17337e7cefcf9be45b95a3be6b36b6f94dfb3d8c361d631866", [: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", "6eb18e80bef8bb57e17f5a7f068a1719fbda384d40fc37acb8eb8aeca493b6ea"},
"esbuild": {:hex, :esbuild, "0.8.2", "5f379dfa383ef482b738e7771daf238b2d1cfb0222bef9d3b20d4c8f06c7a7ac", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "558a8a08ed78eb820efbfda1de196569d8bfa9b51e8371a1934fbb31345feda7"},
diff --git a/test/services/module_discovery_test.exs b/test/services/module_discovery_test.exs
index d041e022..7cd805c5 100644
--- a/test/services/module_discovery_test.exs
+++ b/test/services/module_discovery_test.exs
@@ -23,11 +23,12 @@ defmodule LiveDebugger.Services.ModuleDiscoveryTest do
Macro.Env.location(__ENV__)
)
- assert %{
- live_views: [LiveDebuggerTest.TestView],
- live_components: [LiveDebuggerTest.TestComponent]
- } =
- ModuleDiscovery.find_live_modules()
+ %{live_views: live_views, live_components: live_components} =
+ ModuleDiscovery.find_live_modules()
+
+ assert Enum.any?(live_views, &(&1 == LiveDebuggerTest.TestView))
+ assert Enum.any?(live_components, &(&1 == LiveDebuggerTest.TestComponent))
+ refute Enum.any?(live_views, &(&1 == LiveDebuggerTest.OtherModule))
end
end
diff --git a/test/support/process_case.ex b/test/support/process_case.ex
index 37e02649..28868cf6 100644
--- a/test/support/process_case.ex
+++ b/test/support/process_case.ex
@@ -1,4 +1,6 @@
defmodule LiveDebugger.ProcessCase do
+ @moduledoc false
+
use ExUnit.CaseTemplate
import Mox