1
1
Fork 0
mirror of https://github.com/0x5eal/luau-unzip.git synced 2025-04-13 18:40:53 +01:00

style: apply stylua formatter

This commit is contained in:
Erica Marigold 2025-02-21 19:46:57 +00:00
parent cc6a56d2d4
commit 5d123d0459
Signed by: DevComp
SSH key fingerprint: SHA256:jD3oMT4WL3WHPJQbrjC3l5feNCnkv7ndW8nYaHX5wFw
9 changed files with 514 additions and 550 deletions

View file

@ -8,24 +8,24 @@ local logger = require("./log")
local writeMarkdown = require("./markdown") local writeMarkdown = require("./markdown")
local function extract(input: string): (number, { moonwave.Item }?) local function extract(input: string): (number, { moonwave.Item }?)
local res = process.spawn("moonwave-extractor", { "extract", input }, { local res = process.spawn("moonwave-extractor", { "extract", input }, {
stdio = { stdio = {
stderr = "forward" stderr = "forward",
} },
}) })
if not res.ok then if not res.ok then
print() print()
logger.log("error", "`moonwave-extractor` failed with exit code", res.code) logger.log("error", "`moonwave-extractor` failed with exit code", res.code)
return res.code, nil return res.code, nil
end end
local ok, items: { moonwave.Item } = pcall(serde.decode, "json" :: "json", res.stdout) local ok, items: { moonwave.Item } = pcall(serde.decode, "json" :: "json", res.stdout)
if not ok then if not ok then
return 1, nil return 1, nil
end end
return 0, items return 0, items
end end
local code, items = extract("lib/init.luau") local code, items = extract("lib/init.luau")

View file

@ -8,17 +8,17 @@ local STYLE_ERROR = base .. `{stdio.color("red")}error{stdio.color("reset")}:`
export type LogType = "info" | "warn" | "error" export type LogType = "info" | "warn" | "error"
local styleMappings: { [LogType]: string } = { local styleMappings: { [LogType]: string } = {
info = STYLE_INFO, info = STYLE_INFO,
warn = STYLE_WARN, warn = STYLE_WARN,
error = STYLE_ERROR, error = STYLE_ERROR,
} }
return { return {
styles = styleMappings, styles = styleMappings,
log = function<T...>(type: LogType, ...: T...): () log = function<T...>(type: LogType, ...: T...): ()
local writer: (string) -> () = if type == "info" then stdio.write else stdio.ewrite local writer: (string) -> () = if type == "info" then stdio.write else stdio.ewrite
local fmtMsg = stdio.format(styleMappings[type], ...) local fmtMsg = stdio.format(styleMappings[type], ...)
return writer(fmtMsg .. "\n") return writer(fmtMsg .. "\n")
end end,
} }

View file

@ -97,9 +97,9 @@ end
local function writeMarkdown(path: string, items: { moonwave.Item }) local function writeMarkdown(path: string, items: { moonwave.Item })
local start = os.clock() local start = os.clock()
local buf = "" local buf = ""
for _, item in items do for _, item in items do
logger.log("info", "Generating docs for", item.name) logger.log("info", "Generating docs for", item.name)
buf = writeClass(buf, item.name, item.desc) buf = writeClass(buf, item.name, item.desc)
local props: { moonwave.Property } = {} local props: { moonwave.Property } = {}
@ -147,12 +147,12 @@ local function writeMarkdown(path: string, items: { moonwave.Item })
end end
buf ..= `### \`{type.name}\`\n` buf ..= `### \`{type.name}\`\n`
if type.private then if type.private then
buf ..= `> [!IMPORTANT]\n` buf ..= `> [!IMPORTANT]\n`
buf ..= `> This is a private type. It may be exported publicly, but try to avoid\n` buf ..= `> This is a private type. It may be exported publicly, but try to avoid\n`
buf ..= `> using it, since its definition can have a breaking change at any time\n` buf ..= `> using it, since its definition can have a breaking change at any time\n`
buf ..= `> without warning.\n\n` buf ..= `> without warning.\n\n`
end end
buf ..= `{type.desc}\n` buf ..= `{type.desc}\n`
if type.lua_type ~= nil then if type.lua_type ~= nil then
buf = writeType(buf, type.name, type.desc, type.lua_type) buf = writeType(buf, type.name, type.desc, type.lua_type)
@ -169,8 +169,8 @@ local function writeMarkdown(path: string, items: { moonwave.Item })
buf = writeRef(buf, item.name) buf = writeRef(buf, item.name)
end end
logger.log("info", string.format("Generated docs in %.2fms", (os.clock() - start) * 1000)) logger.log("info", string.format("Generated docs in %.2fms", (os.clock() - start) * 1000))
logger.log("info", "Writing to", path) logger.log("info", "Writing to", path)
fs.writeFile(path, buf) fs.writeFile(path, buf)
end end

View file

@ -4,10 +4,4 @@ local process = require("@lune/process")
local CommandBuilder = require("./util/exec") local CommandBuilder = require("./util/exec")
process.exit( process.exit(CommandBuilder.new("stylua"):withArg("."):withArgs(process.args):withStdioStrategy("forward"):exec().code)
CommandBuilder.new("stylua")
:withArg(".")
:withArgs(process.args)
:withStdioStrategy("forward")
:exec().code
)

View file

@ -9,28 +9,18 @@ local watch = require("../util/channel")
local STYLE = table.freeze({ local STYLE = table.freeze({
suite = function(name: string) suite = function(name: string)
return `{stdio.style("bold")}{stdio.color("purple")}SUITE{stdio.style( return `{stdio.style("bold")}{stdio.color("purple")}SUITE{stdio.style("reset")} {name}`
"reset"
)} {name}`
end, end,
report = function( report = function(name: string, state: "success" | "error" | "skip", elapsed: number)
name: string,
state: "success" | "error" | "skip",
elapsed: number
)
local state_color: stdio.Color = if state == "success" local state_color: stdio.Color = if state == "success"
then "green" then "green"
elseif state == "error" then "red" elseif state == "error" then "red"
elseif state == "skip" then "yellow" elseif state == "skip" then "yellow"
else error("Invalid test state") else error("Invalid test state")
return ` {stdio.style("bold")}{stdio.color(state_color)}{if state return ` {stdio.style("bold")}{stdio.color(state_color)}{if state == "skip" then "SKIP" else "TEST"}{stdio.style(
== "skip" "reset"
then "SKIP" )} {name} [{stdio.style("dim")}{string.format("%.2fms", elapsed)}{stdio.style("reset")}]`
else "TEST"}{stdio.style("reset")} {name} [{stdio.style("dim")}{string.format(
"%.2fms",
elapsed
)}{stdio.style("reset")}]`
end, end,
}) })

View file

@ -5,10 +5,7 @@ local stdio = require("@lune/stdio")
local CommandBuilder = {} local CommandBuilder = {}
export type CommandBuilder = typeof(setmetatable( export type CommandBuilder = typeof(setmetatable({} :: CommandBuilderFields, { __index = CommandBuilder }))
{} :: CommandBuilderFields,
{ __index = CommandBuilder }
))
type CommandBuilderFields = { type CommandBuilderFields = {
program: string, program: string,
args: { string }, args: { string },
@ -37,18 +34,12 @@ function CommandBuilder.new(program: string)
) )
end end
function CommandBuilder.withArg( function CommandBuilder.withArg(self: CommandBuilder, arg: string): CommandBuilder
self: CommandBuilder,
arg: string
): CommandBuilder
table.insert(self.args, arg) table.insert(self.args, arg)
return self return self
end end
function CommandBuilder.withArgs( function CommandBuilder.withArgs(self: CommandBuilder, args: { string }): CommandBuilder
self: CommandBuilder,
args: { string }
): CommandBuilder
for _, arg in args do for _, arg in args do
self:withArg(arg) self:withArg(arg)
end end
@ -69,9 +60,7 @@ function CommandBuilder.withStdioStrategy(
return self return self
end end
local function intoSpawnOptionsStdioKind( local function intoSpawnOptionsStdioKind(strategy: StdioStrategy): process.SpawnOptionsStdioKind
strategy: StdioStrategy
): process.SpawnOptionsStdioKind
if strategy == "pipe" then if strategy == "pipe" then
return "default" return "default"
end end
@ -88,11 +77,7 @@ local function intoSpawnOptionsStdioKind(
end end
function CommandBuilder.exec(self: CommandBuilder): process.SpawnResult function CommandBuilder.exec(self: CommandBuilder): process.SpawnResult
print( print("$", stdio.style("dim") .. self.program, table.concat(self.args, " ") .. stdio.style("reset"))
"$",
stdio.style("dim") .. self.program,
table.concat(self.args, " ") .. stdio.style("reset")
)
local function translateIoStrategyMappings(mappings: IoStrategyMapping) local function translateIoStrategyMappings(mappings: IoStrategyMapping)
local translatedMappings: process.SpawnOptionsStdio = {} local translatedMappings: process.SpawnOptionsStdio = {}
@ -105,16 +90,11 @@ function CommandBuilder.exec(self: CommandBuilder): process.SpawnResult
local child = process.spawn(self.program, self.args, { local child = process.spawn(self.program, self.args, {
shell = true, shell = true,
stdio = translateIoStrategyMappings( stdio = translateIoStrategyMappings(self.stdioStrategy or DEFAULT_STDIO_STRATEGY),
self.stdioStrategy or DEFAULT_STDIO_STRATEGY
),
}) })
if not child.ok then if not child.ok then
print( print(`\n{stdio.color("red")}[luau-lsp]{stdio.color("reset")} Exited with code`, child.code)
`\n{stdio.color("red")}[luau-lsp]{stdio.color("reset")} Exited with code`,
child.code
)
end end
return child return child