Skip to content

Commit bff117c

Browse files
committed
Add Styler to enforce code style
1 parent bf38e99 commit bff117c

32 files changed

+132
-126
lines changed

.formatter.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ locals_without_parens = [error_tracker_dashboard: 1, error_tracker_dashboard: 2]
44
[
55
import_deps: [:ecto, :ecto_sql, :plug, :phoenix],
66
inputs: ["{mix,.formatter,dev,dev.*}.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
7-
plugins: [Phoenix.LiveView.HTMLFormatter],
7+
plugins: [Phoenix.LiveView.HTMLFormatter, Styler],
88
locals_without_parens: locals_without_parens,
99
export: [locals_without_parens: locals_without_parens]
1010
]

config/dev.example.exs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
import Config
22

3-
config :tailwind,
4-
version: "3.4.3",
5-
default: [
6-
args: ~w(
7-
--config=tailwind.config.js
8-
--input=css/app.css
9-
--output=../priv/static/app.css
10-
),
11-
cd: Path.expand("../assets", __DIR__)
12-
]
13-
143
config :bun,
154
version: "1.1.18",
165
default: [
@@ -19,32 +8,40 @@ config :bun,
198
env: %{}
209
]
2110

22-
# PostgreSQL adapter
23-
#
24-
# To use SQLite3 on your local development machine uncomment these lines and
25-
# comment the lines of other adapters.
26-
27-
config :error_tracker, :ecto_adapter, :postgres
28-
29-
config :error_tracker, ErrorTrackerDev.Repo,
30-
url: "ecto://postgres:postgres@127.0.0.1/error_tracker_dev"
31-
3211
# MySQL/MariaDB adapter
3312
#
3413
# To use MySQL/MariaDB on your local development machine uncomment these lines and
3514
# comment the lines of other adapters.
36-
15+
#
3716
# config :error_tracker, :ecto_adapter, :mysql
38-
17+
#
3918
# config :error_tracker, ErrorTrackerDev.Repo,
4019
# url: "ecto://root:root@127.0.0.1/error_tracker_dev"
41-
20+
#
4221
# SQLite3 adapter
4322
#
4423
# To use SQLite3 on your local development machine uncomment these lines and
4524
# comment the lines of other adapters.
46-
25+
#
4726
# config :error_tracker, :ecto_adapter, :sqlite3
48-
27+
#
4928
# config :error_tracker, ErrorTrackerDev.Repo,
5029
# database: System.get_env("SQLITE_DB") || "dev.db"
30+
#
31+
# PostgreSQL adapter
32+
#
33+
# To use PostgreSQL on your local development machine uncomment these lines and
34+
# comment the lines of other adapters.
35+
config :error_tracker, ErrorTrackerDev.Repo, url: "ecto://postgres:postgres@127.0.0.1/error_tracker_dev"
36+
config :error_tracker, :ecto_adapter, :postgres
37+
38+
config :tailwind,
39+
version: "3.4.3",
40+
default: [
41+
args: ~w(
42+
--config=tailwind.config.js
43+
--input=css/app.css
44+
--output=../priv/static/app.css
45+
),
46+
cd: Path.expand("../assets", __DIR__)
47+
]

config/test.example.exs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
import Config
22

3-
config :error_tracker, ErrorTracker.Test.Repo,
4-
url: "ecto://postgres:postgres@127.0.0.1/error_tracker_test",
5-
pool: Ecto.Adapters.SQL.Sandbox,
6-
log: false
3+
alias Ecto.Adapters.SQL.Sandbox
4+
alias ErrorTracker.Test.Repo
75

8-
config :error_tracker, ErrorTracker.Test.MySQLRepo,
9-
url: "ecto://root:root@127.0.0.1/error_tracker_test",
10-
pool: Ecto.Adapters.SQL.Sandbox,
6+
config :error_tracker, ErrorTracker.Test.LiteRepo,
7+
database: "priv/lite_repo/test.db",
8+
pool: Sandbox,
119
log: false,
1210
# Use the same migrations as the PostgreSQL repo
1311
priv: "priv/repo"
1412

15-
config :error_tracker, ErrorTracker.Test.LiteRepo,
16-
database: "priv/lite_repo/test.db",
17-
pool: Ecto.Adapters.SQL.Sandbox,
13+
config :error_tracker, ErrorTracker.Test.MySQLRepo,
14+
url: "ecto://root:root@127.0.0.1/error_tracker_test",
15+
pool: Sandbox,
1816
log: false,
1917
# Use the same migrations as the PostgreSQL repo
2018
priv: "priv/repo"
2119

22-
config :error_tracker, ecto_repos: [ErrorTracker.Test.Repo]
20+
config :error_tracker, Repo,
21+
url: "ecto://postgres:postgres@127.0.0.1/error_tracker_test",
22+
pool: Sandbox,
23+
log: false
24+
25+
config :error_tracker, ecto_repos: [Repo]
2326

2427
# Repo is selected in the test_helper.exs based on the given ENV vars
2528
config :error_tracker, otp_app: :error_tracker

dev.exs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ Application.put_all_env(
2222
)
2323

2424
defmodule ErrorTrackerDev.Repo do
25-
require Logger
2625
use Ecto.Repo, otp_app: otp_app, adapter: Ecto.Adapters.SQLite3
2726

27+
require Logger
28+
2829
defmodule Migration do
30+
@moduledoc false
2931
use Ecto.Migration
3032

3133
def up, do: ErrorTracker.Migration.up()
@@ -80,6 +82,7 @@ defmodule ErrorTrackerDev.Controller do
8082
end
8183

8284
defmodule ErrorTrackerDev.Live do
85+
@moduledoc false
8386
use Phoenix.LiveView
8487

8588
def mount(params, _session, socket) do
@@ -226,7 +229,7 @@ defmodule ErrorTrackerDev.Endpoint do
226229
|> Plug.Conn.put_resp_header("content-security-policy", Enum.join(policies, " "))
227230
end
228231

229-
defp plug_exception(conn = %Plug.Conn{path_info: path_info}, _opts) when is_list(path_info) do
232+
defp plug_exception(%Plug.Conn{path_info: path_info} = conn, _opts) when is_list(path_info) do
230233
if "plug_exception" in path_info,
231234
do: raise("Crashed in Endpoint"),
232235
else: conn
@@ -244,6 +247,7 @@ defmodule ErrorTrackerDev.ErrorView do
244247
end
245248

246249
defmodule ErrorTrackerDev.GenServer do
250+
@moduledoc false
247251
use GenServer
248252

249253
# Client
@@ -267,10 +271,12 @@ defmodule ErrorTrackerDev.GenServer do
267271
end
268272

269273
defmodule ErrorTrackerDev.Exception do
274+
@moduledoc false
270275
defexception [:message, :bread_crumbs]
271276
end
272277

273278
defmodule ErrorTrackerDev.Telemetry do
279+
@moduledoc false
274280
def handle_event(event, measure, metadata, _opts) do
275281
dbg([event, measure, metadata])
276282
end

lib/error_tracker.ex

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ defmodule ErrorTracker do
7979
Breadcrumbs can be viewed in the dashboard on the details page of an occurrence.
8080
"""
8181

82+
import Ecto.Query
83+
84+
alias ErrorTracker.Error
85+
alias ErrorTracker.Occurrence
86+
alias ErrorTracker.Repo
87+
alias ErrorTracker.Telemetry
88+
8289
@typedoc """
8390
A map containing the relevant context for a particular error.
8491
"""
@@ -89,13 +96,6 @@ defmodule ErrorTracker do
8996
"""
9097
@type exception :: Exception.t() | {:error, any()} | {Exception.non_error_kind(), any()}
9198

92-
import Ecto.Query
93-
94-
alias ErrorTracker.Error
95-
alias ErrorTracker.Occurrence
96-
alias ErrorTracker.Repo
97-
alias ErrorTracker.Telemetry
98-
9999
@doc """
100100
Report an exception to be stored.
101101
@@ -154,7 +154,7 @@ defmodule ErrorTracker do
154154
appear as unresolved again.
155155
"""
156156
@spec resolve(Error.t()) :: {:ok, Error.t()} | {:error, Ecto.Changeset.t()}
157-
def resolve(error = %Error{status: :unresolved}) do
157+
def resolve(%Error{status: :unresolved} = error) do
158158
changeset = Ecto.Changeset.change(error, status: :resolved)
159159

160160
with {:ok, updated_error} <- Repo.update(changeset) do
@@ -167,7 +167,7 @@ defmodule ErrorTracker do
167167
Marks an error as unresolved.
168168
"""
169169
@spec unresolve(Error.t()) :: {:ok, Error.t()} | {:error, Ecto.Changeset.t()}
170-
def unresolve(error = %Error{status: :resolved}) do
170+
def unresolve(%Error{status: :resolved} = error) do
171171
changeset = Ecto.Changeset.change(error, status: :unresolved)
172172

173173
with {:ok, updated_error} <- Repo.update(changeset) do
@@ -188,7 +188,7 @@ defmodule ErrorTracker do
188188
receive notifications about.
189189
"""
190190
@spec mute(Error.t()) :: {:ok, Error.t()} | {:error, Ecto.Changeset.t()}
191-
def mute(error = %Error{}) do
191+
def mute(%Error{} = error) do
192192
changeset = Ecto.Changeset.change(error, muted: true)
193193

194194
Repo.update(changeset)
@@ -201,7 +201,7 @@ defmodule ErrorTracker do
201201
for new occurrences of this error again.
202202
"""
203203
@spec unmute(Error.t()) :: {:ok, Error.t()} | {:error, Ecto.Changeset.t()}
204-
def unmute(error = %Error{}) do
204+
def unmute(%Error{} = error) do
205205
changeset = Ecto.Changeset.change(error, muted: false)
206206

207207
Repo.update(changeset)
@@ -341,7 +341,7 @@ defmodule ErrorTracker do
341341
{:ok, {error, occurrence}} =
342342
Repo.transaction(fn ->
343343
error =
344-
ErrorTracker.Repo.with_adapter(fn
344+
Repo.with_adapter(fn
345345
:mysql ->
346346
Repo.insert!(error,
347347
on_conflict: [set: [status: :unresolved, last_occurrence_at: DateTime.utc_now()]]

lib/error_tracker/integrations/phoenix.ex

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,7 @@ defmodule ErrorTracker.Integrations.Phoenix do
119119
})
120120
end
121121

122-
def handle_event(
123-
[:phoenix, :live_component, :handle_event, :exception],
124-
_,
125-
metadata,
126-
:no_config
127-
) do
122+
def handle_event([:phoenix, :live_component, :handle_event, :exception], _, metadata, :no_config) do
128123
ErrorTracker.report({metadata.kind, metadata.reason}, metadata.stacktrace, %{
129124
"live_view.component" => metadata.component,
130125
"live_view.event" => metadata.event,

lib/error_tracker/integrations/plug.ex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ defmodule ErrorTracker.Integrations.Plug do
9797

9898
@doc false
9999
def report_error(conn, reason, stack) do
100-
unless Process.get(:error_tracker_router_exception_reported) do
100+
if !Process.get(:error_tracker_router_exception_reported) do
101101
try do
102102
ErrorTracker.report(reason, stack, build_context(conn))
103103
after
@@ -107,13 +107,13 @@ defmodule ErrorTracker.Integrations.Plug do
107107
end
108108

109109
@doc false
110-
def set_context(conn = %Plug.Conn{}) do
111-
conn |> build_context |> ErrorTracker.set_context()
110+
def set_context(%Plug.Conn{} = conn) do
111+
conn |> build_context() |> ErrorTracker.set_context()
112112
end
113113

114114
@sensitive_headers ["cookie", "authorization"]
115115

116-
defp build_context(conn = %Plug.Conn{}) do
116+
defp build_context(%Plug.Conn{} = conn) do
117117
%{
118118
"request.host" => conn.host,
119119
"request.path" => conn.request_path,
@@ -122,11 +122,11 @@ defmodule ErrorTracker.Integrations.Plug do
122122
"request.ip" => remote_ip(conn),
123123
"request.headers" => conn.req_headers |> Map.new() |> Map.drop(@sensitive_headers),
124124
# Depending on the error source, the request params may have not been fetched yet
125-
"request.params" => unless(is_struct(conn.params, Plug.Conn.Unfetched), do: conn.params)
125+
"request.params" => if(!is_struct(conn.params, Plug.Conn.Unfetched), do: conn.params)
126126
}
127127
end
128128

129-
defp remote_ip(conn = %Plug.Conn{}) do
129+
defp remote_ip(%Plug.Conn{} = conn) do
130130
remote_ip =
131131
case Plug.Conn.get_req_header(conn, "x-forwarded-for") do
132132
[x_forwarded_for | _] ->

lib/error_tracker/migration/mysql.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule ErrorTracker.Migration.MySQL do
44
@behaviour ErrorTracker.Migration
55

66
use Ecto.Migration
7+
78
alias ErrorTracker.Migration.SQLMigrator
89

910
@initial_version 3

lib/error_tracker/migration/postgres.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule ErrorTracker.Migration.Postgres do
44
@behaviour ErrorTracker.Migration
55

66
use Ecto.Migration
7+
78
alias ErrorTracker.Migration.SQLMigrator
89

910
@initial_version 1

lib/error_tracker/migration/postgres/v01.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule ErrorTracker.Migration.Postgres.V01 do
55

66
import Ecto.Query
77

8-
def up(opts = %{create_schema: create_schema, prefix: prefix}) do
8+
def up(%{create_schema: create_schema, prefix: prefix} = opts) do
99
# Prior to V02 the migration version was stored in table comments.
1010
# As of now the migration version is stored in a new table (created in V02).
1111
#

0 commit comments

Comments
 (0)