110 """ |
110 """ |
111 Codes = [ |
111 Codes = [ |
112 "D101", "D102", "D103", "D104", "D105", |
112 "D101", "D102", "D103", "D104", "D105", |
113 "D111", "D112", "D113", |
113 "D111", "D112", "D113", |
114 "D121", "D122", |
114 "D121", "D122", |
115 "D131", "D132", "D133", "D134", |
115 "D130", "D131", "D132", "D133", "D134", |
116 "D141", "D142", "D143", "D144", "D145", |
116 "D141", "D142", "D143", "D144", "D145", |
117 |
117 |
118 "D203", "D205", |
118 "D203", "D205", |
119 "D221", "D222", |
119 "D221", "D222", |
120 "D231", "D234", "D235", "D236", "D237", "D238", "D239", |
120 "D231", "D234", "D235", "D236", "D237", "D238", "D239", |
147 'docstring containing unicode character not surrounded by u"""'), |
147 'docstring containing unicode character not surrounded by u"""'), |
148 "D121": QT_TRANSLATE_NOOP( |
148 "D121": QT_TRANSLATE_NOOP( |
149 "DocStyleChecker", "one-liner docstring on multiple lines"), |
149 "DocStyleChecker", "one-liner docstring on multiple lines"), |
150 "D122": QT_TRANSLATE_NOOP( |
150 "D122": QT_TRANSLATE_NOOP( |
151 "DocStyleChecker", "docstring has wrong indentation"), |
151 "DocStyleChecker", "docstring has wrong indentation"), |
|
152 "D130": QT_TRANSLATE_NOOP( |
|
153 "DocStyleChecker", "docstring does not contain a summary"), |
152 "D131": QT_TRANSLATE_NOOP( |
154 "D131": QT_TRANSLATE_NOOP( |
153 "DocStyleChecker", "docstring summary does not end with a period"), |
155 "DocStyleChecker", "docstring summary does not end with a period"), |
154 "D132": QT_TRANSLATE_NOOP( |
156 "D132": QT_TRANSLATE_NOOP( |
155 "DocStyleChecker", |
157 "DocStyleChecker", |
156 "docstring summary is not in imperative mood" |
158 "docstring summary is not in imperative mood" |
312 (self.__checkTripleDoubleQuotes, ("D111",)), |
314 (self.__checkTripleDoubleQuotes, ("D111",)), |
313 (self.__checkBackslashes, ("D112",)), |
315 (self.__checkBackslashes, ("D112",)), |
314 (self.__checkUnicode, ("D113",)), |
316 (self.__checkUnicode, ("D113",)), |
315 (self.__checkOneLiner, ("D121",)), |
317 (self.__checkOneLiner, ("D121",)), |
316 (self.__checkIndent, ("D122",)), |
318 (self.__checkIndent, ("D122",)), |
|
319 (self.__checkSummary, ("D130")), |
317 (self.__checkEndsWithPeriod, ("D131",)), |
320 (self.__checkEndsWithPeriod, ("D131",)), |
318 (self.__checkBlankAfterSummary, ("D144",)), |
321 (self.__checkBlankAfterSummary, ("D144",)), |
319 (self.__checkBlankAfterLastParagraph, ("D145",)), |
322 (self.__checkBlankAfterLastParagraph, ("D145",)), |
320 ], |
323 ], |
321 } |
324 } |
347 "docstring": [ |
350 "docstring": [ |
348 (self.__checkTripleDoubleQuotes, ("D111",)), |
351 (self.__checkTripleDoubleQuotes, ("D111",)), |
349 (self.__checkBackslashes, ("D112",)), |
352 (self.__checkBackslashes, ("D112",)), |
350 (self.__checkUnicode, ("D113",)), |
353 (self.__checkUnicode, ("D113",)), |
351 (self.__checkIndent, ("D122",)), |
354 (self.__checkIndent, ("D122",)), |
|
355 (self.__checkSummary, ("D130")), |
352 (self.__checkEricEndsWithPeriod, ("D231",)), |
356 (self.__checkEricEndsWithPeriod, ("D231",)), |
353 (self.__checkEricBlankAfterSummary, ("D246",)), |
357 (self.__checkEricBlankAfterSummary, ("D246",)), |
354 (self.__checkEricNBlankAfterLastParagraph, ("D247",)), |
358 (self.__checkEricNBlankAfterLastParagraph, ("D247",)), |
355 (self.__checkEricQuotesOnSeparateLines, ("D222", "D223")) |
359 (self.__checkEricQuotesOnSeparateLines, ("D222", "D223")) |
356 ], |
360 ], |
938 else: |
942 else: |
939 expectedIndent = len(context.indent()) + 4 |
943 expectedIndent = len(context.indent()) + 4 |
940 if indent != expectedIndent: |
944 if indent != expectedIndent: |
941 self.__error(docstringContext.start(), 0, "D122") |
945 self.__error(docstringContext.start(), 0, "D122") |
942 |
946 |
|
947 def __checkSummary(self, docstringContext, context): |
|
948 """ |
|
949 Private method to check, that docstring summaries contain some text. |
|
950 |
|
951 @param docstringContext docstring context (DocStyleContext) |
|
952 @param context context of the docstring (DocStyleContext) |
|
953 """ |
|
954 if docstringContext is None: |
|
955 return |
|
956 |
|
957 summary, lineNumber = self.__getSummaryLine(docstringContext) |
|
958 if summary == "": |
|
959 self.__error(docstringContext.start() + lineNumber, 0, "D130") |
|
960 |
943 def __checkEndsWithPeriod(self, docstringContext, context): |
961 def __checkEndsWithPeriod(self, docstringContext, context): |
944 """ |
962 """ |
945 Private method to check, that docstring summaries end with a period. |
963 Private method to check, that docstring summaries end with a period. |
946 |
964 |
947 @param docstringContext docstring context (DocStyleContext) |
965 @param docstringContext docstring context (DocStyleContext) |
964 """ |
982 """ |
965 if docstringContext is None: |
983 if docstringContext is None: |
966 return |
984 return |
967 |
985 |
968 summary, lineNumber = self.__getSummaryLine(docstringContext) |
986 summary, lineNumber = self.__getSummaryLine(docstringContext) |
969 firstWord = summary.strip().split()[0] |
987 if summary: |
970 if firstWord.endswith("s") and not firstWord.endswith("ss"): |
988 firstWord = summary.strip().split()[0] |
971 self.__error(docstringContext.start() + lineNumber, 0, "D132") |
989 if firstWord.endswith("s") and not firstWord.endswith("ss"): |
|
990 self.__error(docstringContext.start() + lineNumber, 0, "D132") |
972 |
991 |
973 def __checkNoSignature(self, docstringContext, context): |
992 def __checkNoSignature(self, docstringContext, context): |
974 """ |
993 """ |
975 Private method to check, that docstring summaries don't repeat |
994 Private method to check, that docstring summaries don't repeat |
976 the function's signature. |
995 the function's signature. |
1139 """ |
1158 """ |
1140 if docstringContext is None: |
1159 if docstringContext is None: |
1141 return |
1160 return |
1142 |
1161 |
1143 summaryLines, lineNumber = self.__getSummaryLines(docstringContext) |
1162 summaryLines, lineNumber = self.__getSummaryLines(docstringContext) |
1144 if summaryLines[-1].lstrip().startswith("@"): |
1163 if summaryLines: |
1145 summaryLines.pop(-1) |
1164 if summaryLines[-1].lstrip().startswith("@"): |
1146 summary = " ".join([s.strip() for s in summaryLines if s]) |
1165 summaryLines.pop(-1) |
1147 if not summary.endswith(".") and \ |
1166 summary = " ".join([s.strip() for s in summaryLines if s]) |
1148 not summary.split(None, 1)[0].lower() == "constructor": |
1167 if summary and not summary.endswith(".") and \ |
1149 self.__error( |
1168 not summary.split(None, 1)[0].lower() == "constructor": |
1150 docstringContext.start() + lineNumber + len(summaryLines) - 1, |
1169 self.__error( |
1151 0, "D231") |
1170 docstringContext.start() + lineNumber + |
|
1171 len(summaryLines) - 1, |
|
1172 0, "D231") |
1152 |
1173 |
1153 def __checkEricReturn(self, docstringContext, context): |
1174 def __checkEricReturn(self, docstringContext, context): |
1154 """ |
1175 """ |
1155 Private method to check, that docstrings contain an @return line |
1176 Private method to check, that docstrings contain an @return line |
1156 if they return anything and don't otherwise. |
1177 if they return anything and don't otherwise. |