@@ -111,7 +111,7 @@ class ConventionChecker:
111
111
# Begins with 0 or more whitespace characters
112
112
r"^\s*"
113
113
# 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.
115
115
r"(\w+)"
116
116
# Followed by 0 or more whitespace characters
117
117
r"\s*"
@@ -129,6 +129,20 @@ class ConventionChecker:
129
129
".+"
130
130
)
131
131
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
+
132
146
def check_source (
133
147
self ,
134
148
source ,
@@ -905,6 +919,63 @@ def _check_args_section(docstring, definition, context):
905
919
docstring_args , definition
906
920
)
907
921
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. For example, in this case x and y are distinguishable::
932
+
933
+ :param x: Lorem ipsum dolor sit amet
934
+ :param y: Ut enim ad minim veniam
935
+
936
+ In the case below, we only recognize x as a documented parameter
937
+ because the rest of the content is indented as if it belongs
938
+ to the description for x::
939
+
940
+ :param x: Lorem ipsum dolor sit amet
941
+ :param y: Ut enim ad minim veniam
942
+ """
943
+ params = []
944
+ for line in lines :
945
+ match = ConventionChecker .SPHINX_ARGS_REGEX .match (line )
946
+ if match :
947
+ params .append (match .group (1 ))
948
+ return params
949
+
950
+ @staticmethod
951
+ def _check_sphinx_params (lines , definition ):
952
+ """D417: Sphinx param section checks.
953
+
954
+ Check for a valid Sphinx-style parameter section.
955
+ * The section documents all function arguments (D417)
956
+ except `self` or `cls` if it is a method.
957
+
958
+ Documentation for each arg should start at the same indentation
959
+ level. For example, in this case x and y are distinguishable::
960
+
961
+ :param x: Lorem ipsum dolor sit amet
962
+ :param y: Ut enim ad minim veniam
963
+
964
+ In the case below, we only recognize x as a documented parameter
965
+ because the rest of the content is indented as if it belongs
966
+ to the description for x::
967
+
968
+ :param x: Lorem ipsum dolor sit amet
969
+ :param y: Ut enim ad minim veniam
970
+ """
971
+ docstring_args = set (ConventionChecker ._find_sphinx_params (lines ))
972
+ if docstring_args :
973
+ yield from ConventionChecker ._check_missing_args (
974
+ docstring_args , definition
975
+ )
976
+ return True
977
+ return False
978
+
908
979
@staticmethod
909
980
def _check_missing_args (docstring_args , definition ):
910
981
"""D417: Yield error for missing arguments in docstring.
@@ -1093,10 +1164,14 @@ def check_docstring_sections(self, definition, docstring):
1093
1164
found_numpy = yield from self ._check_numpy_sections (
1094
1165
lines , definition , docstring
1095
1166
)
1096
- if not found_numpy :
1097
- yield from self ._check_google_sections (
1098
- lines , definition , docstring
1099
- )
1167
+ if found_numpy :
1168
+ return
1169
+
1170
+ found_sphinx = yield from self ._check_sphinx_params (lines , definition )
1171
+ if found_sphinx :
1172
+ return
1173
+
1174
+ yield from self ._check_google_sections (lines , definition , docstring )
1100
1175
1101
1176
1102
1177
parse = Parser ()
0 commit comments