Skip to content

Commit

Permalink
feat(docgen): add comment integrity checking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Feb 3, 2023
1 parent ecea630 commit 799886f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 13 additions & 0 deletions docgen/docgen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,17 @@ docgen.generators = {
end,
}

--- Check the integrity of the description comments found in configuration blocks
---@param comment string #The comment to check the integrity of
---@return nil|string #`nil` for success, `string` if there was an error
docgen.check_comment_integrity = function(comment)
if comment:match("^%s*%-%-+%s*") then
return "found leading `--` comment text."
elseif comment:sub(1, 1):upper() ~= comment:sub(1, 1) then
return "comment does not begin with a capital letter."
elseif comment:find(" neorg ") then
return "`neorg` written with lowercase letter. Use uppercase instead."
end
end

return docgen
11 changes: 10 additions & 1 deletion docgen/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ for module_name, module in pairs(modules) do
end

comments = table.concat(comments, "\n")
log.warn(comments)

local error = docgen.check_comment_integrity(comments)

if type(error) == "string" then
-- Get the exact location of the error with data.node and the file it was contained in
local start_row, start_col = data.node:start()

vim.notify(("Error when parsing annotation in module '%s' on line (%d, %d): %s"):format(module_name, start_row, start_col, error))
return
end
end)
end
end

0 comments on commit 799886f

Please sign in to comment.