@@ -111,7 +111,7 @@ class ConventionChecker:
111111 # Begins with 0 or more whitespace characters
112112 r"^\s*"
113113 # Followed by 1 or more unicode chars, numbers or underscores
114- # The above is captured as the first group as this is the paramater name.
114+ # The below is captured as the first group as this is the parameter name.
115115 r"(\w+)"
116116 # Followed by 0 or more whitespace characters
117117 r"\s*"
@@ -129,6 +129,20 @@ class ConventionChecker:
129129 ".+"
130130 )
131131
132+ SPHINX_ARGS_REGEX = re (
133+ # Begins with 0 or more whitespace characters
134+ r"^\s*"
135+ # Followed by the parameter marker
136+ r":param "
137+ # Followed by 1 or more unicode chars, numbers or underscores and a colon
138+ # The parameter name is captured as the first group.
139+ r"(\w+):"
140+ # Followed by 0 or more whitespace characters
141+ r"\s*"
142+ # Next is the parameter description
143+ r".+$"
144+ )
145+
132146 def check_source (
133147 self ,
134148 source ,
@@ -905,6 +919,56 @@ def _check_args_section(docstring, definition, context):
905919 docstring_args , definition
906920 )
907921
922+ @staticmethod
923+ def _find_sphinx_params (lines ):
924+ """D417: Sphinx param section checks.
925+
926+ Check for a valid Sphinx-style parameter section.
927+ * The section documents all function arguments (D417)
928+ except `self` or `cls` if it is a method.
929+
930+ Documentation for each arg should start at the same indentation
931+ level::
932+
933+ :param x: Lorem ipsum dolor sit amet
934+ :param y: Ut enim ad minim veniam
935+ """
936+ params = []
937+ for line in lines :
938+ match = ConventionChecker .SPHINX_ARGS_REGEX .match (line )
939+ if match :
940+ params .append (match .group (1 ))
941+ return params
942+
943+ @staticmethod
944+ def _check_sphinx_params (lines , definition ):
945+ """D417: Sphinx param section checks.
946+
947+ Check for a valid Sphinx-style parameter section.
948+ * The section documents all function arguments (D417)
949+ except `self` or `cls` if it is a method.
950+
951+ Documentation for each arg should start at the same indentation
952+ level. For example, in this case x and y are distinguishable::
953+
954+ :param x: Lorem ipsum dolor sit amet
955+ :param y: Ut enim ad minim veniam
956+
957+ In the case below, we only recognize x as a documented parameter
958+ because the rest of the content is indented as if it belongs
959+ to the description for x::
960+
961+ :param x: Lorem ipsum dolor sit amet
962+ :param y: Ut enim ad minim veniam
963+ """
964+ docstring_args = set (ConventionChecker ._find_sphinx_params (lines ))
965+ if docstring_args :
966+ yield from ConventionChecker ._check_missing_args (
967+ docstring_args , definition
968+ )
969+ return True
970+ return False
971+
908972 @staticmethod
909973 def _check_missing_args (docstring_args , definition ):
910974 """D417: Yield error for missing arguments in docstring.
@@ -1093,10 +1157,14 @@ def check_docstring_sections(self, definition, docstring):
10931157 found_numpy = yield from self ._check_numpy_sections (
10941158 lines , definition , docstring
10951159 )
1096- if not found_numpy :
1097- yield from self ._check_google_sections (
1098- lines , definition , docstring
1099- )
1160+ if found_numpy :
1161+ return
1162+
1163+ found_sphinx = yield from self ._check_sphinx_params (lines , definition )
1164+ if found_sphinx :
1165+ return
1166+
1167+ yield from self ._check_google_sections (lines , definition , docstring )
11001168
11011169
11021170parse = Parser ()
0 commit comments