Skip to content

Commit b7fac14

Browse files
committed
β0.1.0 Improve type annotations
Improve readme Add versioning
1 parent 002fefc commit b7fac14

File tree

16 files changed

+56
-35
lines changed

16 files changed

+56
-35
lines changed

configs.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local utils = require("core.utils")
22
local Path = require("core.path")
33

4-
---@type { [string]: PartialConfigTable }
4+
---@type table<string, PartialConfigTable>
55
local configs = {
66

77
DEFAULT = {

core/config.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Config.__name = "Config"
7575
Config.errors = {
7676

7777
--- @param list table
78-
--- @return string
78+
--- @return string errmsg
7979
missing_item_in_note_schema_list = function(list, idx)
8080
return "Missing "
8181
.. (#list <= 1 and "open-tag" or "close-tag")
@@ -84,7 +84,7 @@ Config.errors = {
8484
.. "]."
8585
end,
8686

87-
--- @return string
87+
--- @return string errmsg
8888
root_reserved = function()
8989
return "Cannot use "
9090
.. "ROOT"
@@ -98,7 +98,8 @@ Config.errors = {
9898
}
9999

100100
--- @param config_table PartialConfigTable
101-
--- @return Config?, string?
101+
--- @return Config? config
102+
--- @return string? errmsg
102103
function Config:new(config_table)
103104
self = {}
104105
--- @cast self Config

core/context.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ Context.errors = {
9090
---@param text_stream Stream
9191
---@param preserve boolean
9292
---@param ansi_enabled boolean
93-
---@return Context?, string?
93+
---@return Context? ctx
94+
---@return string? errmsg
9495
function Context:new(
9596
config,
9697
src_path,

core/fold.lua

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ M.__name = "fold"
1414
M.errors = {
1515

1616
---@param section Section?
17-
---@return string
17+
---@return string errmsg
1818
unterminated_section = function(section)
1919
return "Unterminated section: " .. (tostring(section) or "nil")
2020
end,
2121

2222
---@param line number
23-
---@return string
23+
---@return string errmsg
2424
inconsistent_indent = function(line)
2525
return "Inconsistent indent on line " .. line
2626
end,
2727

2828
---@param retry_count number
2929
---@param section Section?
3030
---@param is_local boolean?
31-
---@return string
31+
---@return string errmsg
3232
maximum_retry_count = function(retry_count, section, is_local)
3333
return "Maximum "
3434
.. (is_local and "local " or "")
@@ -39,7 +39,7 @@ M.errors = {
3939
end,
4040

4141
---@param path Path
42-
---@return string
42+
---@return string errmsg
4343
path_should_not_be_directory = function(path)
4444
return "`config.resolve_path` returned directory-type Path ("
4545
.. path:escaped()
@@ -48,14 +48,14 @@ M.errors = {
4848

4949
---@param path string
5050
---@param section Section?
51-
---@return string
51+
---@return string errmsg
5252
cannot_write = function(path, section)
5353
return "Cannot write to path " .. path .. "\n" .. tostring(section)
5454
end,
5555

5656
---@param command string
5757
---@param err string?
58-
---@return string
58+
---@return string errmsg
5959
command_failed = function(command, err)
6060
return "Failed to execute command: "
6161
.. command
@@ -64,14 +64,15 @@ M.errors = {
6464
end,
6565

6666
---@param path string
67-
---@return string
67+
---@return string errmsg
6868
expected_file_to_be_writable = function(path)
6969
return "Expected file " .. tostring(path) .. " to be writable"
7070
end,
7171
}
7272

7373
---@param ctx Context
74-
---@return Section?, string?
74+
---@return Section? section
75+
---@return string? errmsg
7576
M.parse = function(ctx)
7677
local curr_section, err = Section:new(
7778
0,
@@ -160,7 +161,8 @@ end
160161

161162
---@param section_root Section
162163
---@param ctx Context
163-
---@return nil, string?
164+
---@return nil
165+
---@return string? errmsg
164166
M.prepare = function(section_root, ctx)
165167
---@type { [string]: Section }
166168
local created_files = {}
@@ -265,7 +267,8 @@ end
265267
---@param section_root Section
266268
---@param ctx Context
267269
---@param is_dry_run boolean?
268-
---@return Plan?, string?
270+
---@return Plan? plan
271+
---@return string? errmsg
269272
M.execute = function(section_root, ctx, is_dry_run)
270273
is_dry_run = is_dry_run or false
271274
local io = ctx.io
@@ -308,7 +311,7 @@ M.execute = function(section_root, ctx, is_dry_run)
308311
---@param lines string[]
309312
---@param path Path
310313
---@param is_overwrite boolean?
311-
---@return string?
314+
---@return string? errmsg
312315
local function write(handle, lines, path, is_overwrite)
313316
is_overwrite = is_overwrite or false
314317
created_or_modified_paths[tostring(path)] = 1
@@ -325,7 +328,7 @@ M.execute = function(section_root, ctx, is_dry_run)
325328
end
326329

327330
---@param directory Path
328-
---@return string?
331+
---@return string? errmsg
329332
local function mkdir(directory)
330333
created_or_modified_paths[tostring(directory)] = 1
331334
if not is_dry_run then

core/parser.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local validate = require("core.validate")
22

3-
---@alias Equivalences { [string]: EquivalenceClass|string|nil }
3+
---@alias Equivalences table<string, EquivalenceClass|string|nil>
44

55
---@class (exact) EquivalenceClass
66
---@field equivalences string[]

core/path.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ end
3535
---@param path string|string[]
3636
---`allow_relative` IS INTENDED FOR INTERNAL USE ONLY.
3737
---@param allow_relative boolean?
38-
---@return Path?, string?
38+
---@return Path? path
39+
---@return string? errmsg
3940
function Path:new(path, allow_relative)
4041
self = {}
4142
setmetatable(self, Path)
@@ -137,7 +138,7 @@ end
137138
--- assert(path:pop_directory() == "baz")
138139
--- assert(path == Path:new("/foo/"))
139140
--- ```
140-
--- @return string?
141+
--- @return string? errmsg
141142
function Path:pop_directory()
142143
handle_is_void(self)
143144
if #self.parts <= 2 then
@@ -200,7 +201,7 @@ end
200201
--- assert(path == Path:new("/foo/"))
201202
--- ```
202203
--- @param filename string
203-
--- @return string
204+
--- @return string old_filename
204205
function Path:set_filename(filename)
205206
handle_is_void(self)
206207
if #self.parts < 1 then
@@ -252,7 +253,7 @@ end
252253
--- assert(Path:new("/foo/bar"):join("./baz") == Path:new("/foo/baz"))
253254
--- ```
254255
--- @param path string
255-
--- @return Path?
256+
--- @return Path? new_path
256257
--- @return string? errmsg
257258
function Path:join(path)
258259
local err = validate.types("Path:join", { { path, "string", "path" } })

core/section.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ Section.ROOT = "ROOT"
5555
---@param children Section[]
5656
---@param parent Section?
5757
---@param indent string?
58-
---@return Section?, string?
58+
---@return Section? section
59+
---@return string? errmsg
5960
function Section:new(
6061
id,
6162
type,
@@ -205,7 +206,7 @@ function Section:type_name_is(name)
205206
return name == self:type_name()
206207
end
207208

208-
---@return string?
209+
---@return string
209210
function Section:__tostring()
210211
return "Section {"
211212
.. '\n\ttype = {"'

core/validate.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ M.RETVAL = "RETVAL"
99
---@param expected_type string
1010
---@param actual string
1111
---@overload fun(function_name: string, triplet: {[1]: any, [2]: string, [3]: string?}): string
12-
---@return string
12+
---@return string errmsg
1313
M.invalid_type_error = function(function_name, arg_name, expected_type, actual)
1414
arg_name = arg_name or M.RETVAL
1515
if type(arg_name) == type({}) then
@@ -36,6 +36,7 @@ end
3636
---@param expected_class table
3737
---@param actual any
3838
---@overload fun(function_name: string, triplet: {[1]: any, [2]: table, [3]: string?}): string
39+
---@return string
3940
M.invalid_instance_error = function(
4041
function_name,
4142
arg_name,
@@ -72,7 +73,7 @@ end
7273

7374
---@param function_name string
7475
---@param data {[1]: any, [2]: string, [3]: string?}[]
75-
---@return string?
76+
---@return string? errmsg
7677
M.types = function(function_name, data)
7778
for _, item in ipairs(data) do
7879
local elem = item[1]
@@ -105,7 +106,7 @@ end
105106
---@param list any[]
106107
---@param arg_name string
107108
---@param expected_type string
108-
---@return string?
109+
---@return string? errmsg
109110
M.types_in_list = function(function_name, list, arg_name, expected_type)
110111
arg_name = arg_name or M.RETVAL
111112
local err = M.types(function_name, { { list, "table", arg_name } })
@@ -131,7 +132,7 @@ end
131132

132133
---@param function_name string
133134
---@param data {[1]: any, [2]: table, [3]: string?}[]
134-
---@return string?
135+
---@return string? errmsg
135136
M.are_instances = function(function_name, data)
136137
for _, item in ipairs(data) do
137138
if not item[1] then

core/version.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
return "β0.1.0"

examples/bible/configs.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local Path = require("core.path")
22
local utils = require("core.utils")
33

4-
---@type { [string]: PartialConfigTable }
4+
---@type table<string, PartialConfigTable>
55
local configs = {
66

77
bible = {

0 commit comments

Comments
 (0)