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