Plugins/CheckerPlugins/Pep8/Pep257Checker.py

changeset 2937
de26bc76d6ee
parent 2935
e4c0b6e46ea3
child 2944
dcca9f5c701d
equal deleted inserted replaced
2936:2ff273068a10 2937:de26bc76d6ee
110 "D121", "D122", 110 "D121", "D122",
111 "D131", "D132", "D133", "D134", 111 "D131", "D132", "D133", "D134",
112 "D141", "D142", "D143", "D144", "D145", 112 "D141", "D142", "D143", "D144", "D145",
113 113
114 "D203", "D205", 114 "D203", "D205",
115 "D221", 115 "D221", "D222",
116 "D231", "D234", "D235", "D236", "D237", "D238", 116 "D231", "D234", "D235", "D236", "D237", "D238",
117 "D242", "D243", "D244", "D245", "D246", "D247", 117 "D242", "D243", "D244", "D245", "D246", "D247",
118 ] 118 ]
119 119
120 Messages = { 120 Messages = {
171 "D203": QT_TRANSLATE_NOOP( 171 "D203": QT_TRANSLATE_NOOP(
172 "Pep257Checker", "private function/method is missing a docstring"), 172 "Pep257Checker", "private function/method is missing a docstring"),
173 "D205": QT_TRANSLATE_NOOP( 173 "D205": QT_TRANSLATE_NOOP(
174 "Pep257Checker", "private class is missing a docstring"), 174 "Pep257Checker", "private class is missing a docstring"),
175 "D221": QT_TRANSLATE_NOOP( 175 "D221": QT_TRANSLATE_NOOP(
176 "Pep257Checker", "one-liner docstring not on three lines"), 176 "Pep257Checker",
177 "leading quotes of docstring not on separate line"),
178 "D222": QT_TRANSLATE_NOOP(
179 "Pep257Checker",
180 "trailing quotes of docstring not on separate line"),
177 "D231": QT_TRANSLATE_NOOP( 181 "D231": QT_TRANSLATE_NOOP(
178 "Pep257Checker", "docstring summary does not end with a period"), 182 "Pep257Checker", "docstring summary does not end with a period"),
179 "D234": QT_TRANSLATE_NOOP( 183 "D234": QT_TRANSLATE_NOOP(
180 "Pep257Checker", "docstring does not contain a @return line"), 184 "Pep257Checker", "docstring does not contain a @return line"),
181 "D235": QT_TRANSLATE_NOOP( 185 "D235": QT_TRANSLATE_NOOP(
311 ], 315 ],
312 "docstring": [ 316 "docstring": [
313 (self.__checkTripleDoubleQuotes, ("D111",)), 317 (self.__checkTripleDoubleQuotes, ("D111",)),
314 (self.__checkBackslashes, ("D112",)), 318 (self.__checkBackslashes, ("D112",)),
315 (self.__checkUnicode, ("D113",)), 319 (self.__checkUnicode, ("D113",)),
316 (self.__checkEricOneLiner, ("D221",)),
317 (self.__checkIndent, ("D122",)), 320 (self.__checkIndent, ("D122",)),
318 (self.__checkEricEndsWithPeriod, ("D231",)), 321 (self.__checkEricEndsWithPeriod, ("D231",)),
319 (self.__checkEricBlankAfterSummary, ("D246",)), 322 (self.__checkEricBlankAfterSummary, ("D246",)),
320 (self.__checkEricNBlankAfterLastParagraph, ("D247",)), 323 (self.__checkEricNBlankAfterLastParagraph, ("D247",)),
324 (self.__checkEricQuotesOnSeparateLines, ("D222", "D223"))
321 ], 325 ],
322 } 326 }
323 327
324 self.__checkers = {} 328 self.__checkers = {}
325 for key, checkers in checkersWithCodes.items(): 329 for key, checkers in checkersWithCodes.items():
1056 1060
1057 ################################################################## 1061 ##################################################################
1058 ## Checking functionality below (eric specific ones) 1062 ## Checking functionality below (eric specific ones)
1059 ################################################################## 1063 ##################################################################
1060 1064
1061 def __checkEricOneLiner(self, docstringContext, context): 1065 def __checkEricQuotesOnSeparateLines(self, docstringContext, context):
1062 """ 1066 """
1063 Private method to check, that one-liner docstrings are on 1067 Private method to check, that leading and trailing quotes are on
1064 three lines (quotes, docstring, quotes). 1068 a line by themselves.
1065 1069
1066 @param docstringContext docstring context (Pep257Context) 1070 @param docstringContext docstring context (Pep257Context)
1067 @param context context of the docstring (Pep257Context) 1071 @param context context of the docstring (Pep257Context)
1068 """ 1072 """
1069 if docstringContext is None: 1073 if docstringContext is None:
1070 return 1074 return
1071 1075
1072 lines = docstringContext.source() 1076 lines = docstringContext.source()
1073 if len(lines) != 3: 1077 if lines[0].strip().strip('ru"'):
1074 nonEmptyLines = [l for l in lines if l.strip().strip('\'"')] 1078 self.__error(docstringContext.start(), 0, "D221")
1075 if len(nonEmptyLines) == 1: 1079 if lines[-1].strip().strip('"'):
1076 self.__error(docstringContext.start(), 0, "D221") 1080 self.__error(docstringContext.end(), 0, "D222")
1077 1081
1078 def __checkEricEndsWithPeriod(self, docstringContext, context): 1082 def __checkEricEndsWithPeriod(self, docstringContext, context):
1079 """ 1083 """
1080 Private method to check, that docstring summaries end with a period. 1084 Private method to check, that docstring summaries end with a period.
1081 1085
1084 """ 1088 """
1085 if docstringContext is None: 1089 if docstringContext is None:
1086 return 1090 return
1087 1091
1088 summaryLines, lineNumber = self.__getSummaryLines(docstringContext) 1092 summaryLines, lineNumber = self.__getSummaryLines(docstringContext)
1093 if summaryLines[-1].lstrip().startswith("@"):
1094 summaryLines.pop(-1)
1089 summary = " ".join([s.strip() for s in summaryLines if s]) 1095 summary = " ".join([s.strip() for s in summaryLines if s])
1090 if not summary.endswith(".") and \ 1096 if not summary.endswith(".") and \
1091 not summary.split(None, 1)[0].lower() == "constructor": 1097 not summary.split(None, 1)[0].lower() == "constructor":
1092 self.__error( 1098 self.__error(
1093 docstringContext.start() + lineNumber + len(summaryLines) - 1, 1099 docstringContext.start() + lineNumber + len(summaryLines) - 1,

eric ide

mercurial