Skip to content

Commit 1620e5d

Browse files
committed
Respect docstring-min-length in docparams extension
Even though visit_functiondef is checking for docstring-min-length, it is not enough. This commit fixes the issue by adding the same check to visit_raise, visit_return and visit_yield
1 parent a4e91d7 commit 1620e5d

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

pylint/extensions/docparams.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,7 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
209209
return
210210

211211
# skip functions smaller than 'docstring-min-length'
212-
lines = checker_utils.get_node_last_lineno(node) - node.lineno
213-
max_lines = self.linter.config.docstring_min_length
214-
if max_lines > -1 and lines < max_lines:
212+
if self._is_shorter_than_min_length(node):
215213
return
216214

217215
self.check_functiondef_params(node, node_doc)
@@ -281,6 +279,10 @@ def visit_raise(self, node: nodes.Raise) -> None:
281279
if not isinstance(func_node, astroid.FunctionDef):
282280
return
283281

282+
# skip functions smaller than 'docstring-min-length'
283+
if self._is_shorter_than_min_length(node):
284+
return
285+
284286
# skip functions that match the 'no-docstring-rgx' config option
285287
no_docstring_rgx = self.linter.config.no_docstring_rgx
286288
if no_docstring_rgx and re.match(no_docstring_rgx, func_node.name):
@@ -338,6 +340,10 @@ def visit_return(self, node: nodes.Return) -> None:
338340
if self.linter.config.accept_no_return_doc:
339341
return
340342

343+
# skip functions smaller than 'docstring-min-length'
344+
if self._is_shorter_than_min_length(node):
345+
return
346+
341347
func_node: astroid.FunctionDef = node.frame()
342348

343349
# skip functions that match the 'no-docstring-rgx' config option
@@ -364,6 +370,10 @@ def visit_yield(self, node: nodes.Yield | nodes.YieldFrom) -> None:
364370
if self.linter.config.accept_no_yields_doc:
365371
return
366372

373+
# skip functions smaller than 'docstring-min-length'
374+
if self._is_shorter_than_min_length(node):
375+
return
376+
367377
func_node: astroid.FunctionDef = node.frame()
368378

369379
# skip functions that match the 'no-docstring-rgx' config option
@@ -671,6 +681,18 @@ def _add_raise_message(
671681
confidence=HIGH,
672682
)
673683

684+
def _is_shorter_than_min_length(self, node: nodes.FunctionDef) -> bool:
685+
"""Returns true on functions smaller than 'docstring-min-length'.
686+
687+
:param node: Node for a function or method definition in the AST
688+
:type node: :class:`astroid.scoped_nodes.Function`
689+
690+
:rtype: bool
691+
"""
692+
lines = checker_utils.get_node_last_lineno(node) - node.lineno
693+
min_lines = self.linter.config.docstring_min_length
694+
return bool(min_lines > -1) and bool(lines < min_lines)
695+
674696

675697
def register(linter: PyLinter) -> None:
676698
linter.register_checker(DocstringParameterChecker(linter))

0 commit comments

Comments
 (0)