Skip to content

Commit c9db839

Browse files
committed
style: stylua formatting for render.lua and hints_spec.lua
1 parent 8ddee69 commit c9db839

2 files changed

Lines changed: 70 additions & 17 deletions

File tree

‎lua/effect-error-pretty/render.lua‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,14 @@ local function render_effect_mismatch(parsed, hint)
428428
if #parsed.missing_services > 0 then
429429
vim.list_extend(
430430
lines,
431-
missing_services_lines(name, parsed.missing_services, is_layer, is_scope_only(parsed), parsed.scope_required, hint)
431+
missing_services_lines(
432+
name,
433+
parsed.missing_services,
434+
is_layer,
435+
is_scope_only(parsed),
436+
parsed.scope_required,
437+
hint
438+
)
432439
)
433440
push_signatures()
434441
table.insert(lines, "╰─")

‎tests/hints_spec.lua‎

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@ local parse = require("effect-error-pretty.parse")
55
local render = require("effect-error-pretty.render")
66
local hints = require("effect-error-pretty.hints")
77

8-
local SUFFIX = " with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties."
9-
local MISSING = "Argument of type 'Effect<string, NotFound, Greeter | Database>' is not assignable to parameter of type 'Effect<string, NotFound, never>'" .. SUFFIX
10-
local UNHANDLED = "Type 'Effect<string, NotFound, Database>' is not assignable to type 'Effect<string, never, Database>'" .. SUFFIX
8+
local SUFFIX =
9+
" with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties."
10+
local MISSING = "Argument of type 'Effect<string, NotFound, Greeter | Database>' is not assignable to parameter of type 'Effect<string, NotFound, never>'"
11+
.. SUFFIX
12+
local UNHANDLED = "Type 'Effect<string, NotFound, Database>' is not assignable to type 'Effect<string, never, Database>'"
13+
.. SUFFIX
1114
local LS_ERRORS = "Missing 'NotFound | Timeout' in the expected Effect errors."
1215
local LS_CTX = "This Effect requires a service that is missing from the expected Effect context: `Greeter`."
1316
local SCOPE = "Type 'Effect<string, never, Scope>' is not assignable to type 'Effect<string, never, never>'"
14-
local LAYER_RIN = "Type 'Layer<{ readonly get: (id: string) => Effect<User, DbError, never>; }, never, Database>' is not assignable to type 'Layer<{ readonly get: (id: string) => Effect<User, DbError, never>; }, never, never>'."
17+
local LAYER_RIN =
18+
"Type 'Layer<{ readonly get: (id: string) => Effect<User, DbError, never>; }, never, Database>' is not assignable to type 'Layer<{ readonly get: (id: string) => Effect<User, DbError, never>; }, never, never>'."
1519
local LS_LAYER = "Missing 'Database' in the expected Layer context."
16-
local WIDE_R = "Argument of type 'Effect<string, never, unknown>' is not assignable to parameter of type 'Effect<string, never, never>'" .. SUFFIX
17-
local WIDE_E = "Type 'Effect<string, unknown, never>' is not assignable to type 'Effect<string, never, never>'" .. SUFFIX
20+
local WIDE_R = "Argument of type 'Effect<string, never, unknown>' is not assignable to parameter of type 'Effect<string, never, never>'"
21+
.. SUFFIX
22+
local WIDE_E = "Type 'Effect<string, unknown, never>' is not assignable to type 'Effect<string, never, never>'"
23+
.. SUFFIX
1824
local LS_WIDE_E = "Missing 'unknown' in the expected Effect errors."
1925
local LS_WIDE_RIN = "Missing 'any' in the expected Layer context."
20-
local MULTI = "Type 'Effect<string, NotFound, Database>' is not assignable to type 'Effect<number, never, never>'" .. SUFFIX
26+
local MULTI = "Type 'Effect<string, NotFound, Database>' is not assignable to type 'Effect<number, never, never>'"
27+
.. SUFFIX
2128

2229
local NO_OVERLOAD = table.concat({
2330
"No overload matches this call.",
@@ -96,17 +103,35 @@ describe("hints.templates", function()
96103
it("renders provide for each placement", function()
97104
assert.are.equal(".pipe(Effect.provide(AppLive))", hints.templates.provide("AppLive", { "Greeter" }, "here"))
98105
assert.are.equal(".pipe(Effect.provide(AppLive))", hints.templates.provide("AppLive", { "Greeter" }, nil))
99-
assert.are.equal("keep Greeter | Database in R; provide AppLive higher up", hints.templates.provide("AppLive", { "Greeter", "Database" }, "caller"))
100-
assert.are.equal("Layer.provide(LoggerLive) inside this layer", hints.templates.provide("LoggerLive", { "Logger" }, "layer"))
106+
assert.are.equal(
107+
"keep Greeter | Database in R; provide AppLive higher up",
108+
hints.templates.provide("AppLive", { "Greeter", "Database" }, "caller")
109+
)
110+
assert.are.equal(
111+
"Layer.provide(LoggerLive) inside this layer",
112+
hints.templates.provide("LoggerLive", { "Logger" }, "layer")
113+
)
101114
end)
102115

103116
it("renders each unhandled-error fix", function()
104117
local t = hints.templates.unhandled
105-
assert.are.equal('.pipe(Effect.catchTag("NotFound", () => Effect.succeed(fallback)))', t("catch_tag", { "NotFound" }))
106-
assert.are.equal(".pipe(Effect.catchTags({ NotFound: () => Effect.succeed(fallback), Timeout: () => Effect.succeed(fallback) }))", t("catch_tag", { "NotFound", "Timeout" }))
118+
assert.are.equal(
119+
'.pipe(Effect.catchTag("NotFound", () => Effect.succeed(fallback)))',
120+
t("catch_tag", { "NotFound" })
121+
)
122+
assert.are.equal(
123+
".pipe(Effect.catchTags({ NotFound: () => Effect.succeed(fallback), Timeout: () => Effect.succeed(fallback) }))",
124+
t("catch_tag", { "NotFound", "Timeout" })
125+
)
107126
assert.are.equal(".pipe(Effect.orDie) — treat as a defect here", t("or_die", { "NotFound" }))
108-
assert.are.equal("declare NotFound | Timeout in this function's E channel; let the caller handle it", t("declare", { "NotFound", "Timeout" }))
109-
assert.are.equal(".pipe(Effect.mapError((e) => new UserServiceError({ cause: e })))", t("map_error", { "NotFound" }, "UserServiceError"))
127+
assert.are.equal(
128+
"declare NotFound | Timeout in this function's E channel; let the caller handle it",
129+
t("declare", { "NotFound", "Timeout" })
130+
)
131+
assert.are.equal(
132+
".pipe(Effect.mapError((e) => new UserServiceError({ cause: e })))",
133+
t("map_error", { "NotFound" }, "UserServiceError")
134+
)
110135
assert.are.equal(".pipe(Effect.mapError((e) => new DomainError({ cause: e })))", t("map_error", { "NotFound" }))
111136
assert.is_nil(t("nope", { "NotFound" }))
112137
end)
@@ -140,7 +165,11 @@ describe("hints resolver seam", function()
140165
hints.set_resolver(function(parsed, family, names)
141166
assert.are.equal("services", family)
142167
assert.are.equal("layer", parsed.tag)
143-
return { label = "Jev", line = hints.templates.provide("DatabaseLive", names, "layer"), detail = "layer DatabaseLive 0.93" }
168+
return {
169+
label = "Jev",
170+
line = hints.templates.provide("DatabaseLive", names, "layer"),
171+
detail = "layer DatabaseLive 0.93",
172+
}
144173
end)
145174
for _, case in ipairs({ { LAYER_RIN, "typescript" }, { LS_LAYER, "effect" } }) do
146175
local box = render.artistic(diag(case[1], case[2]), { effect = true })
@@ -160,7 +189,11 @@ describe("hints resolver seam", function()
160189
it("lets the resolver name where a widened channel lost its type", function()
161190
hints.set_resolver(function(_, family, names)
162191
assert.are.equal("widened", family)
163-
return { label = "Jev", line = hints.templates.widened(names[1], "fromRegistry", "app.ts", 12), detail = "widened fromRegistry 0.81" }
192+
return {
193+
label = "Jev",
194+
line = hints.templates.widened(names[1], "fromRegistry", "app.ts", 12),
195+
detail = "widened fromRegistry 0.81",
196+
}
164197
end)
165198
local box = render.artistic(diag(WIDE_R), { effect = true })
166199
assert.is_truthy(box:find("R Not Inferred", 1, true))
@@ -240,7 +273,20 @@ describe("overload picker seam", function()
240273
end)
241274

242275
it("ignores nil, out-of-range, non-numeric and throwing pickers", function()
243-
for _, bad in ipairs({ function() return nil end, function() return 99 end, function() return "2" end, function() error("boom") end }) do
276+
for _, bad in ipairs({
277+
function()
278+
return nil
279+
end,
280+
function()
281+
return 99
282+
end,
283+
function()
284+
return "2"
285+
end,
286+
function()
287+
error("boom")
288+
end,
289+
}) do
244290
local r = parse.parse(NO_OVERLOAD, { pick_overload = bad })
245291
assert.are.equal("effect_mismatch", r.kind)
246292
end

0 commit comments

Comments
 (0)