fix(python): Bare-returns are filtered from docstring output (#145)
* Python docstrings - bare-returns are filtered from docstring output * Stylua * doc: Version --------- Co-authored-by: danymat <d.danymat@gmail.com>
This commit is contained in:
@@ -12,6 +12,31 @@ local parent = {
|
|||||||
type = { "expression_statement" },
|
type = { "expression_statement" },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--- Modify `nodes` if the found return(s) are **all** bare-returns.
|
||||||
|
---
|
||||||
|
--- A bare-return is used to return early from a function and aren't meant to be
|
||||||
|
--- assigned so they should not be included in docstring output.
|
||||||
|
---
|
||||||
|
--- If at least one return is not a bare-return then this function does nothing.
|
||||||
|
---
|
||||||
|
---@param nodes table
|
||||||
|
local validate_bare_returns = function(nodes)
|
||||||
|
local return_node = nodes[i.Return]
|
||||||
|
local has_data = false
|
||||||
|
|
||||||
|
for _, value in pairs(return_node) do
|
||||||
|
if value:child_count() > 1
|
||||||
|
then
|
||||||
|
has_data = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not has_data
|
||||||
|
then
|
||||||
|
nodes[i.Return] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
-- Search for these nodes
|
-- Search for these nodes
|
||||||
parent = parent,
|
parent = parent,
|
||||||
@@ -119,6 +144,11 @@ return {
|
|||||||
table.insert(temp[i.Tparam], typed_parameters)
|
table.insert(temp[i.Tparam], typed_parameters)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if nodes[i.Return] then
|
||||||
|
validate_bare_returns(nodes)
|
||||||
|
end
|
||||||
|
|
||||||
local res = extractors:extract_from_matched(nodes)
|
local res = extractors:extract_from_matched(nodes)
|
||||||
res[i.Tparam] = temp[i.Tparam]
|
res[i.Tparam] = temp[i.Tparam]
|
||||||
|
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ end
|
|||||||
--- with multiple annotation conventions.
|
--- with multiple annotation conventions.
|
||||||
---@tag neogen-changelog
|
---@tag neogen-changelog
|
||||||
---@toc_entry Changes in neogen plugin
|
---@toc_entry Changes in neogen plugin
|
||||||
neogen.version = "2.14.0"
|
neogen.version = "2.14.1"
|
||||||
--minidoc_afterlines_end
|
--minidoc_afterlines_end
|
||||||
|
|
||||||
return neogen
|
return neogen
|
||||||
|
|||||||
Reference in New Issue
Block a user