@@ -209,9 +209,7 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
209
209
return
210
210
211
211
# 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 ):
215
213
return
216
214
217
215
self .check_functiondef_params (node , node_doc )
@@ -281,6 +279,10 @@ def visit_raise(self, node: nodes.Raise) -> None:
281
279
if not isinstance (func_node , astroid .FunctionDef ):
282
280
return
283
281
282
+ # skip functions smaller than 'docstring-min-length'
283
+ if self ._is_shorter_than_min_length (node ):
284
+ return
285
+
284
286
# skip functions that match the 'no-docstring-rgx' config option
285
287
no_docstring_rgx = self .linter .config .no_docstring_rgx
286
288
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:
338
340
if self .linter .config .accept_no_return_doc :
339
341
return
340
342
343
+ # skip functions smaller than 'docstring-min-length'
344
+ if self ._is_shorter_than_min_length (node ):
345
+ return
346
+
341
347
func_node : astroid .FunctionDef = node .frame ()
342
348
343
349
# skip functions that match the 'no-docstring-rgx' config option
@@ -364,6 +370,10 @@ def visit_yield(self, node: nodes.Yield | nodes.YieldFrom) -> None:
364
370
if self .linter .config .accept_no_yields_doc :
365
371
return
366
372
373
+ # skip functions smaller than 'docstring-min-length'
374
+ if self ._is_shorter_than_min_length (node ):
375
+ return
376
+
367
377
func_node : astroid .FunctionDef = node .frame ()
368
378
369
379
# skip functions that match the 'no-docstring-rgx' config option
@@ -671,6 +681,18 @@ def _add_raise_message(
671
681
confidence = HIGH ,
672
682
)
673
683
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
+
674
696
675
697
def register (linter : PyLinter ) -> None :
676
698
linter .register_checker (DocstringParameterChecker (linter ))
0 commit comments