Fri, 03 Jan 2014 13:52:58 +0100
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
3160
209a07d7e401
Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3031
diff
changeset
|
3 | # Copyright (c) 2013 - 2014 Detlev Offenbach <detlev@die-offenbachs.de> |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
2984
031cceaa8b01
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2983
diff
changeset
|
7 | Module implementing a checker for documentation string conventions. |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | # |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | # The routines of the checker class are modeled after the ones found in |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | # pep257.py (version 0.2.4). |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | # |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | try: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | # Python 2 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | from StringIO import StringIO # __IGNORE_EXCEPTION__ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | except ImportError: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | # Python 3 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | from io import StringIO # __IGNORE_WARNING__ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | import tokenize |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
22 | import ast |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
23 | import sys |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
26 | class DocStyleContext(object): |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | Class implementing the source context. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | def __init__(self, source, startLine, contextType): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | Constructor |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | @param source source code of the context (list of string or string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | @param startLine line number the context starts in the source (integer) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | @param contextType type of the context object (string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | if isinstance(source, str): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | self.__source = source.splitlines(True) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | else: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | self.__source = source[:] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | self.__start = startLine |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | self.__indent = "" |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | self.__type = contextType |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | # ensure first line is left justified |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | if self.__source: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | self.__indent = self.__source[0].replace( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | self.__source[0].lstrip(), "") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | self.__source[0] = self.__source[0].lstrip() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | def source(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | Public method to get the source. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | @return source (list of string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | return self.__source |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | def ssource(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | Public method to get the joined source lines. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | @return source (string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | return "".join(self.__source) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | def start(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | Public method to get the start line number. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | @return start line number (integer) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | return self.__start |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | def end(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
78 | Public method to get the end line number. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | @return end line number (integer) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | return self.__start + len(self.__source) - 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | def indent(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | Public method to get the indentation of the first line. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | @return indentation string (string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | return self.__indent |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | def contextType(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | Public method to get the context type. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | @return context type (string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | return self.__type |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
101 | class DocStyleChecker(object): |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | """ |
2984
031cceaa8b01
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2983
diff
changeset
|
103 | Class implementing a checker for documentation string conventions. |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | Codes = [ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | "D101", "D102", "D103", "D104", "D105", |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | "D111", "D112", "D113", |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | "D121", "D122", |
3165
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
109 | "D130", "D131", "D132", "D133", "D134", |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | "D141", "D142", "D143", "D144", "D145", |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
111 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
112 | "D203", "D205", |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
113 | "D221", |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
114 | "D231", "D234", "D235", "D236", "D237", "D238", "D239", |
2934
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
115 | "D242", "D243", "D244", "D245", "D246", "D247", |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
116 | "D250", "D251", |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | ] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | def __init__(self, source, filename, select, ignore, expected, repeat, |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
120 | maxLineLength=79, docType="pep257"): |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | """ |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
122 | Constructor |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | @param source source code to be checked (list of string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | @param filename name of the source file (string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | @param select list of selected codes (list of string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | @param ignore list of codes to be ignored (list of string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | @param expected list of expected codes (list of string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | @param repeat flag indicating to report each occurrence of a code |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | (boolean) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
131 | @keyparam maxLineLength allowed line length (integer) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
132 | @keyparam docType type of the documentation strings |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
133 | (string, one of 'eric' or 'pep257') |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | """ |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
135 | assert docType in ("eric", "pep257") |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
136 | |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | self.__select = tuple(select) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | self.__ignore = tuple(ignore) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | self.__expected = expected[:] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | self.__repeat = repeat |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | self.__maxLineLength = maxLineLength |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
142 | self.__docType = docType |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | self.__filename = filename |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | self.__source = source[:] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | # statistics counters |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | self.counters = {} |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | # collection of detected errors |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | self.errors = [] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | self.__lineNumber = 0 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | # caches |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | self.__functionsCache = None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | self.__classesCache = None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | self.__methodsCache = None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | self.__keywords = [ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | 'moduleDocstring', 'functionDocstring', |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | 'classDocstring', 'methodDocstring', |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | 'defDocstring', 'docstring' |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | ] |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
164 | if self.__docType == "pep257": |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
165 | checkersWithCodes = { |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
166 | "moduleDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
167 | (self.__checkModulesDocstrings, ("D101",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
168 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
169 | "functionDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
170 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
171 | "classDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
172 | (self.__checkClassDocstring, ("D104", "D105")), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
173 | (self.__checkBlankBeforeAndAfterClass, ("D142", "D143")), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
174 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
175 | "methodDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
176 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
177 | "defDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
178 | (self.__checkFunctionDocstring, ("D102", "D103")), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
179 | (self.__checkImperativeMood, ("D132",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
180 | (self.__checkNoSignature, ("D133",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
181 | (self.__checkReturnType, ("D134",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
182 | (self.__checkNoBlankLineBefore, ("D141",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
183 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
184 | "docstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
185 | (self.__checkTripleDoubleQuotes, ("D111",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
186 | (self.__checkBackslashes, ("D112",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
187 | (self.__checkUnicode, ("D113",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
188 | (self.__checkOneLiner, ("D121",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
189 | (self.__checkIndent, ("D122",)), |
3165
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
190 | (self.__checkSummary, ("D130")), |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
191 | (self.__checkEndsWithPeriod, ("D131",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
192 | (self.__checkBlankAfterSummary, ("D144",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
193 | (self.__checkBlankAfterLastParagraph, ("D145",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
194 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
195 | } |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
196 | elif self.__docType == "eric": |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
197 | checkersWithCodes = { |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
198 | "moduleDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
199 | (self.__checkModulesDocstrings, ("D101",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
200 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
201 | "functionDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
202 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
203 | "classDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
204 | (self.__checkClassDocstring, ("D104", "D205")), |
2934
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
205 | (self.__checkEricNoBlankBeforeAndAfterClassOrFunction, |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
206 | ("D242", "D243")), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
207 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
208 | "methodDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
209 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
210 | "defDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
211 | (self.__checkFunctionDocstring, ("D102", "D203")), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
212 | (self.__checkImperativeMood, ("D132",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
213 | (self.__checkNoSignature, ("D133",)), |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
214 | (self.__checkEricReturn, ("D234", "D235")), |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
215 | (self.__checkEricFunctionArguments, |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
216 | ("D236", "D237", "D238", "D239")), |
2934
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
217 | (self.__checkEricNoBlankBeforeAndAfterClassOrFunction, |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
218 | ("D244", "D245")), |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
219 | (self.__checkEricException, ("D250", "D251")), |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
220 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
221 | "docstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
222 | (self.__checkTripleDoubleQuotes, ("D111",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
223 | (self.__checkBackslashes, ("D112",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
224 | (self.__checkUnicode, ("D113",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
225 | (self.__checkIndent, ("D122",)), |
3165
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
226 | (self.__checkSummary, ("D130")), |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
227 | (self.__checkEricEndsWithPeriod, ("D231",)), |
2934
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
228 | (self.__checkEricBlankAfterSummary, ("D246",)), |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
229 | (self.__checkEricNBlankAfterLastParagraph, ("D247",)), |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
230 | (self.__checkEricQuotesOnSeparateLines, ("D222", "D223")) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
231 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
232 | } |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | self.__checkers = {} |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
235 | for key, checkers in checkersWithCodes.items(): |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | for checker, codes in checkers: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | if any(not (code and self.__ignoreCode(code)) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
238 | for code in codes): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | if key not in self.__checkers: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | self.__checkers[key] = [] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | self.__checkers[key].append(checker) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | def __ignoreCode(self, code): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | Private method to check if the error code should be ignored. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | @param code message code to check for (string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | @return flag indicating to ignore the given code (boolean) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
249 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
250 | return (code.startswith(self.__ignore) and |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
251 | not code.startswith(self.__select)) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | def __error(self, lineNumber, offset, code, *args): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | Private method to record an issue. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | @param lineNumber line number of the issue (integer) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | @param offset position within line of the issue (integer) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | @param code message code (string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | @param args arguments for the message (list) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | if self.__ignoreCode(code): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
264 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | if code in self.counters: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | self.counters[code] += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | else: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | self.counters[code] = 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | # Don't care about expected codes |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | if code in self.__expected: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
272 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | if code and (self.counters[code] == 1 or self.__repeat): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | # record the issue with one based line number |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | self.errors.append( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | (self.__filename, lineNumber + 1, offset, code, args)) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
278 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | def __resetReadline(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | Private method to reset the internal readline function. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | self.__lineNumber = 0 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | def __readline(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | Private method to get the next line from the source. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | @return next line of source (string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | self.__lineNumber += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | if self.__lineNumber > len(self.__source): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | return '' |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | return self.__source[self.__lineNumber - 1] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | def run(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | Public method to check the given source for violations of doc string |
2984
031cceaa8b01
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2983
diff
changeset
|
299 | conventions. |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
301 | if not self.__source or not self.__filename: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | # don't do anything, if essential data is missing |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
303 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
304 | |
2967
f9acd647f881
Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2961
diff
changeset
|
305 | if not self.__checkers: |
f9acd647f881
Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2961
diff
changeset
|
306 | # don't do anything, if no codes were selected |
f9acd647f881
Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2961
diff
changeset
|
307 | return |
f9acd647f881
Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2961
diff
changeset
|
308 | |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | for keyword in self.__keywords: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | if keyword in self.__checkers: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | for check in self.__checkers[keyword]: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | for context in self.__parseContexts(keyword): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | docstring = self.__parseDocstring(context, keyword) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | check(docstring, context) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
316 | def __getSummaryLine(self, docstringContext): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
317 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
318 | Private method to extract the summary line. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
319 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
320 | @param docstringContext docstring context (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | @return summary line (string) and the line it was found on (integer) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | lines = docstringContext.source() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | line = (lines[0] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | .replace('r"""', "", 1) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
327 | .replace('u"""', "", 1) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | .replace('"""', "") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
329 | .replace("r'''", "", 1) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | .replace("u'''", "", 1) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | .replace("'''", "") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | .strip()) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
333 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
334 | if len(lines) == 1 or len(line) > 0: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
335 | return line, 0 |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
336 | return lines[1].strip().replace('"""', "").replace("'''", ""), 1 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
337 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
338 | def __getSummaryLines(self, docstringContext): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
339 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
340 | Private method to extract the summary lines. |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
341 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
342 | @param docstringContext docstring context (DocStyleContext) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
343 | @return summary lines (list of string) and the line it was found on |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
344 | (integer) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
345 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
346 | summaries = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
347 | lines = docstringContext.source() |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
348 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
349 | line0 = (lines[0] |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
350 | .replace('r"""', "", 1) |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
351 | .replace('u"""', "", 1) |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
352 | .replace('"""', "") |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
353 | .replace("r'''", "", 1) |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
354 | .replace("u'''", "", 1) |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
355 | .replace("'''", "") |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
356 | .strip()) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
357 | if len(lines) > 1: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
358 | line1 = lines[1].strip().replace('"""', "").replace("'''", "") |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
359 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
360 | line1 = "" |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
361 | if len(lines) > 2: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
362 | line2 = lines[2].strip().replace('"""', "").replace("'''", "") |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
363 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
364 | line2 = "" |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
365 | if line0: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
366 | lineno = 0 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
367 | summaries.append(line0) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
368 | if not line0.endswith(".") and line1: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
369 | # two line summary |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
370 | summaries.append(line1) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
371 | elif line1: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
372 | lineno = 1 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
373 | summaries.append(line1) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
374 | if not line1.endswith(".") and line2: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
375 | # two line summary |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
376 | summaries.append(line2) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
377 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
378 | lineno = 2 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
379 | summaries.append(line2) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
380 | return summaries, lineno |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
381 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
382 | if sys.version_info[0] < 3: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
383 | def __getArgNames(self, node): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
384 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
385 | Private method to get the argument names of a function node. |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
386 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
387 | @param node AST node to extract arguments names from |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
388 | @return tuple of two list of argument names, one for arguments |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
389 | and one for keyword arguments (tuple of list of string) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
390 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
391 | def unpackArgs(args): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
392 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
393 | Local helper function to unpack function argument names. |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
394 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
395 | @param args list of AST node arguments |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
396 | @return list of argument names (list of string) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
397 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
398 | ret = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
399 | for arg in args: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
400 | if isinstance(arg, ast.Tuple): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
401 | ret.extend(unpackArgs(arg.elts)) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
402 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
403 | ret.append(arg.id) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
404 | return ret |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
405 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
406 | arguments = unpackArgs(node.args.args) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
407 | if node.args.vararg is not None: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
408 | arguments.append(node.args.vararg) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
409 | kwarguments = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
410 | if node.args.kwarg is not None: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
411 | kwarguments.append(node.args.kwarg) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
412 | return arguments, kwarguments |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
413 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
414 | def __getArgNames(self, node): # __IGNORE_WARNING__ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
415 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
416 | Private method to get the argument names of a function node. |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
417 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
418 | @param node AST node to extract arguments names from |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
419 | @return tuple of two list of argument names, one for arguments |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
420 | and one for keyword arguments (tuple of list of string) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
421 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
422 | arguments = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
423 | arguments.extend([arg.arg for arg in node.args.args]) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
424 | if node.args.vararg is not None: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
425 | arguments.append(node.args.vararg) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
426 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
427 | kwarguments = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
428 | kwarguments.extend([arg.arg for arg in node.args.kwonlyargs]) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
429 | if node.args.kwarg is not None: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
430 | kwarguments.append(node.args.kwarg) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
431 | return arguments, kwarguments |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
432 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
433 | ################################################################## |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
434 | ## Parsing functionality below |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
435 | ################################################################## |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
436 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
437 | def __parseModuleDocstring(self, source): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
438 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | Private method to extract a docstring given a module source. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
440 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
441 | @param source source to parse (list of string) |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
442 | @return context of extracted docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
443 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
444 | for kind, value, (line, char), _, _ in tokenize.generate_tokens( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
445 | StringIO("".join(source)).readline): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
446 | if kind in [tokenize.COMMENT, tokenize.NEWLINE, tokenize.NL]: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
447 | continue |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
448 | elif kind == tokenize.STRING: # first STRING should be docstring |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
449 | return DocStyleContext(value, line - 1, "docstring") |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
450 | else: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | return None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
452 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
453 | def __parseDocstring(self, context, what=''): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
454 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
455 | Private method to extract a docstring given `def` or `class` source. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
456 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
457 | @param context context data to get the docstring from (DocStyleContext) |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
458 | @param what string denoting what is being parsed (string) |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
459 | @return context of extracted docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
460 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
461 | moduleDocstring = self.__parseModuleDocstring(context.source()) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
462 | if what.startswith('module') or context.contextType() == "module": |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
463 | return moduleDocstring |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
464 | if moduleDocstring: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
465 | return moduleDocstring |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
466 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
467 | tokenGenerator = tokenize.generate_tokens( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
468 | StringIO(context.ssource()).readline) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
469 | try: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
470 | kind = None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
471 | while kind != tokenize.INDENT: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
472 | kind, _, _, _, _ = next(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
473 | kind, value, (line, char), _, _ = next(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
474 | if kind == tokenize.STRING: # STRING after INDENT is a docstring |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
475 | return DocStyleContext( |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
476 | value, context.start() + line - 1, "docstring") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
477 | except StopIteration: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
478 | pass |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
479 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
480 | return None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
481 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
482 | def __parseTopLevel(self, keyword): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
483 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
484 | Private method to extract top-level functions or classes. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
485 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
486 | @param keyword keyword signaling what to extract (string) |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
487 | @return extracted function or class contexts (list of DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
488 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
489 | self.__resetReadline() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
490 | tokenGenerator = tokenize.generate_tokens(self.__readline) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
491 | kind, value, char = None, None, None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
492 | contexts = [] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
493 | try: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
494 | while True: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
495 | start, end = None, None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
496 | while not (kind == tokenize.NAME and |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
497 | value == keyword and |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
498 | char == 0): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
499 | kind, value, (line, char), _, _ = next(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
500 | start = line - 1, char |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
501 | while not (kind == tokenize.DEDENT and |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
502 | value == '' and |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
503 | char == 0): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
504 | kind, value, (line, char), _, _ = next(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
505 | end = line - 1, char |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
506 | contexts.append(DocStyleContext( |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
507 | self.__source[start[0]:end[0]], start[0], keyword)) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
508 | except StopIteration: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
509 | return contexts |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
510 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
511 | def __parseFunctions(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
512 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
513 | Private method to extract top-level functions. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
514 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
515 | @return extracted function contexts (list of DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
516 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
517 | if not self.__functionsCache: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
518 | self.__functionsCache = self.__parseTopLevel('def') |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
519 | return self.__functionsCache |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
520 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
521 | def __parseClasses(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
522 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
523 | Private method to extract top-level classes. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
524 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
525 | @return extracted class contexts (list of DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
526 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
527 | if not self.__classesCache: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
528 | self.__classesCache = self.__parseTopLevel('class') |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
529 | return self.__classesCache |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
530 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
531 | def __skipIndentedBlock(self, tokenGenerator): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
532 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
533 | Private method to skip over an indented block of source code. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
534 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
535 | @param tokenGenerator token generator |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
536 | @return last token of the indented block |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
537 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
538 | kind, value, start, end, raw = next(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
539 | while kind != tokenize.INDENT: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
540 | kind, value, start, end, raw = next(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
541 | indent = 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
542 | for kind, value, start, end, raw in tokenGenerator: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
543 | if kind == tokenize.INDENT: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
544 | indent += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
545 | elif kind == tokenize.DEDENT: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
546 | indent -= 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
547 | if indent == 0: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
548 | return kind, value, start, end, raw |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
549 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
550 | def __parseMethods(self): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
551 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
552 | Private method to extract methods of all classes. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
553 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
554 | @return extracted method contexts (list of DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
555 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
556 | if not self.__methodsCache: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
557 | contexts = [] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
558 | for classContext in self.__parseClasses(): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
559 | tokenGenerator = tokenize.generate_tokens( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
560 | StringIO(classContext.ssource()).readline) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
561 | kind, value, char = None, None, None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
562 | try: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
563 | while True: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
564 | start, end = None, None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
565 | while not (kind == tokenize.NAME and value == 'def'): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
566 | kind, value, (line, char), _, _ = \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
567 | next(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
568 | start = line - 1, char |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
569 | kind, value, (line, char), _, _ = \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
570 | self.__skipIndentedBlock(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
571 | end = line - 1, char |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
572 | startLine = classContext.start() + start[0] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
573 | endLine = classContext.start() + end[0] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
574 | contexts.append( |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
575 | DocStyleContext(self.__source[startLine:endLine], |
3031
ed2eaa573ca5
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2984
diff
changeset
|
576 | startLine, "def")) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
577 | except StopIteration: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
578 | pass |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
579 | self.__methodsCache = contexts |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
580 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
581 | return self.__methodsCache |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
582 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
583 | def __parseContexts(self, kind): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
584 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
585 | Private method to extract a context from the source. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
586 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
587 | @param kind kind of context to extract (string) |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
588 | @return requested contexts (list of DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
589 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
590 | if kind == 'moduleDocstring': |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
591 | return [DocStyleContext(self.__source, 0, "module")] |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
592 | if kind == 'functionDocstring': |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
593 | return self.__parseFunctions() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
594 | if kind == 'classDocstring': |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
595 | return self.__parseClasses() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
596 | if kind == 'methodDocstring': |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
597 | return self.__parseMethods() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
598 | if kind == 'defDocstring': |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
599 | return self.__parseFunctions() + self.__parseMethods() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
600 | if kind == 'docstring': |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
601 | return ([DocStyleContext(self.__source, 0, "module")] + |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
602 | self.__parseFunctions() + |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
603 | self.__parseClasses() + |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
604 | self.__parseMethods()) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
605 | return [] # fall back |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
606 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
607 | ################################################################## |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
608 | ## Checking functionality below (PEP-257) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
609 | ################################################################## |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
610 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
611 | def __checkModulesDocstrings(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
612 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
613 | Private method to check, if the module has a docstring. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
614 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
615 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
616 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
617 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
618 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
619 | self.__error(context.start(), 0, "D101") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
620 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
621 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
622 | docstring = docstringContext.ssource() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
623 | if (not docstring or not docstring.strip() or |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
624 | not docstring.strip('\'"')): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
625 | self.__error(context.start(), 0, "D101") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
626 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
627 | def __checkFunctionDocstring(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
628 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
629 | Private method to check, that all public functions and methods |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
630 | have a docstring. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
631 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
632 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
633 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
634 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
635 | functionName = context.source()[0].lstrip().split()[1].split("(")[0] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
636 | if functionName.startswith('_') and not functionName.endswith('__'): |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
637 | if self.__docType == "eric": |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
638 | code = "D203" |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
639 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
640 | code = "D103" |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
641 | else: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
642 | code = "D102" |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
643 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
644 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
645 | self.__error(context.start(), 0, code) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
646 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
647 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
648 | docstring = docstringContext.ssource() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
649 | if (not docstring or not docstring.strip() or |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
650 | not docstring.strip('\'"')): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
651 | self.__error(context.start(), 0, code) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
652 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
653 | def __checkClassDocstring(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
654 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
655 | Private method to check, that all public functions and methods |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
656 | have a docstring. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
657 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
658 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
659 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
660 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
661 | className = context.source()[0].lstrip().split()[1].split("(")[0] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
662 | if className.startswith('_'): |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
663 | if self.__docType == "eric": |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
664 | code = "D205" |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
665 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
666 | code = "D105" |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
667 | else: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
668 | code = "D104" |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
669 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
670 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
671 | self.__error(context.start(), 0, code) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
672 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
673 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
674 | docstring = docstringContext.ssource() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
675 | if (not docstring or not docstring.strip() or |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
676 | not docstring.strip('\'"')): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
677 | self.__error(context.start(), 0, code) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
678 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
679 | def __checkTripleDoubleQuotes(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
680 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
681 | Private method to check, that all docstrings are surrounded |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
682 | by triple double quotes. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
683 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
684 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
685 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
686 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
687 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
688 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
689 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
690 | docstring = docstringContext.ssource().strip() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
691 | if not docstring.startswith(('"""', 'r"""', 'u"""')): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
692 | self.__error(docstringContext.start(), 0, "D111") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
693 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
694 | def __checkBackslashes(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
695 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
696 | Private method to check, that all docstrings containing |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
697 | backslashes are surrounded by raw triple double quotes. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
698 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
699 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
700 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
701 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
702 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
703 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
704 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
705 | docstring = docstringContext.ssource().strip() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
706 | if "\\" in docstring and not docstring.startswith('r"""'): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
707 | self.__error(docstringContext.start(), 0, "D112") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
708 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
709 | def __checkUnicode(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
710 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
711 | Private method to check, that all docstrings containing unicode |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
712 | characters are surrounded by unicode triple double quotes. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
713 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
714 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
715 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
716 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
717 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
718 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
719 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
720 | docstring = docstringContext.ssource().strip() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
721 | if not docstring.startswith('u"""') and \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
722 | any(ord(char) > 127 for char in docstring): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
723 | self.__error(docstringContext.start(), 0, "D113") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
724 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
725 | def __checkOneLiner(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
726 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
727 | Private method to check, that one-liner docstrings fit on |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
728 | one line with quotes. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
729 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
730 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
731 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
732 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
733 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
734 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
735 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
736 | lines = docstringContext.source() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
737 | if len(lines) > 1: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
738 | nonEmptyLines = [l for l in lines if l.strip().strip('\'"')] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
739 | if len(nonEmptyLines) == 1: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
740 | modLen = len(context.indent() + '"""' + |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
741 | nonEmptyLines[0].strip() + '"""') |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
742 | if context.contextType() != "module": |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
743 | modLen += 4 |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
744 | if not nonEmptyLines[0].strip().endswith("."): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
745 | # account for a trailing dot |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
746 | modLen += 1 |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
747 | if modLen <= self.__maxLineLength: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
748 | self.__error(docstringContext.start(), 0, "D121") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
749 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
750 | def __checkIndent(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
751 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
752 | Private method to check, that docstrings are properly indented. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
753 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
754 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
755 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
756 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
757 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
758 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
759 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
760 | lines = docstringContext.source() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
761 | if len(lines) == 1: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
762 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
763 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
764 | nonEmptyLines = [l.rstrip() for l in lines[1:] if l.strip()] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
765 | if not nonEmptyLines: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
766 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
767 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
768 | indent = min([len(l) - len(l.strip()) for l in nonEmptyLines]) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
769 | if context.contextType() == "module": |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
770 | expectedIndent = 0 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
771 | else: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
772 | expectedIndent = len(context.indent()) + 4 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
773 | if indent != expectedIndent: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
774 | self.__error(docstringContext.start(), 0, "D122") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
775 | |
3165
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
776 | def __checkSummary(self, docstringContext, context): |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
777 | """ |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
778 | Private method to check, that docstring summaries contain some text. |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
779 | |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
780 | @param docstringContext docstring context (DocStyleContext) |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
781 | @param context context of the docstring (DocStyleContext) |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
782 | """ |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
783 | if docstringContext is None: |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
784 | return |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
785 | |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
786 | summary, lineNumber = self.__getSummaryLine(docstringContext) |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
787 | if summary == "": |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
788 | self.__error(docstringContext.start() + lineNumber, 0, "D130") |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
789 | |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
790 | def __checkEndsWithPeriod(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
791 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
792 | Private method to check, that docstring summaries end with a period. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
793 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
794 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
795 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
796 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
797 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
798 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
799 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
800 | summary, lineNumber = self.__getSummaryLine(docstringContext) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
801 | if not summary.endswith("."): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
802 | self.__error(docstringContext.start() + lineNumber, 0, "D131") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
803 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
804 | def __checkImperativeMood(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
805 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
806 | Private method to check, that docstring summaries are in |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
807 | imperative mood. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
808 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
809 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
810 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
811 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
812 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
813 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
814 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
815 | summary, lineNumber = self.__getSummaryLine(docstringContext) |
3165
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
816 | if summary: |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
817 | firstWord = summary.strip().split()[0] |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
818 | if firstWord.endswith("s") and not firstWord.endswith("ss"): |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
819 | self.__error(docstringContext.start() + lineNumber, 0, "D132") |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
820 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
821 | def __checkNoSignature(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
822 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
823 | Private method to check, that docstring summaries don't repeat |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
824 | the function's signature. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
825 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
826 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
827 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
828 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
829 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
830 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
831 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
832 | functionName = context.source()[0].lstrip().split()[1].split("(")[0] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
833 | summary, lineNumber = self.__getSummaryLine(docstringContext) |
2948
ea04689ee599
Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2946
diff
changeset
|
834 | if functionName + "(" in summary.replace(" ", "") and \ |
ea04689ee599
Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2946
diff
changeset
|
835 | not functionName + "()" in summary.replace(" ", ""): |
ea04689ee599
Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2946
diff
changeset
|
836 | # report only, if it is not an abbreviated form (i.e. function() ) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
837 | self.__error(docstringContext.start() + lineNumber, 0, "D133") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
838 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
839 | def __checkReturnType(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
840 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
841 | Private method to check, that docstrings mention the return value type. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
842 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
843 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
844 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
845 | """ |
2968
b109ff4678bc
Removed the check for a module being a script because scripts should be well documented as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2967
diff
changeset
|
846 | if docstringContext is None: |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
847 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
848 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
849 | if "return" not in docstringContext.ssource().lower(): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
850 | tokens = list( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
851 | tokenize.generate_tokens(StringIO(context.ssource()).readline)) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
852 | return_ = [tokens[i + 1][0] for i, token in enumerate(tokens) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
853 | if token[1] == "return"] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
854 | if (set(return_) - |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
855 | set([tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE]) != |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
856 | set([])): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
857 | self.__error(docstringContext.end(), 0, "D134") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
858 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
859 | def __checkNoBlankLineBefore(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
860 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
861 | Private method to check, that function/method docstrings are not |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
862 | preceded by a blank line. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
863 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
864 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
865 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
866 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
867 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
868 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
869 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
870 | contextLines = context.source() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
871 | cti = 0 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
872 | while cti < len(contextLines) and \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
873 | not contextLines[cti].strip().startswith( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
874 | ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
875 | cti += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
876 | if cti == len(contextLines): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
877 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
878 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
879 | if not contextLines[cti - 1].strip(): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
880 | self.__error(docstringContext.start(), 0, "D141") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
881 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
882 | def __checkBlankBeforeAndAfterClass(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
883 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
884 | Private method to check, that class docstrings have one |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
885 | blank line around them. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
886 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
887 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
888 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
889 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
890 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
891 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
892 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
893 | contextLines = context.source() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
894 | cti = 0 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
895 | while cti < len(contextLines) and \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
896 | not contextLines[cti].strip().startswith( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
897 | ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
898 | cti += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
899 | if cti == len(contextLines): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
900 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
901 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
902 | start = cti |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
903 | if contextLines[cti].strip() in ( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
904 | '"""', 'r"""', 'u"""', "'''", "r'''", "u'''"): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
905 | # it is a multi line docstring |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
906 | cti += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
907 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
908 | while cti < len(contextLines) and \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
909 | not contextLines[cti].strip().endswith(('"""', "'''")): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
910 | cti += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
911 | end = cti |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
912 | if cti >= len(contextLines) - 1: |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
913 | return |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
914 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
915 | if contextLines[start - 1].strip(): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
916 | self.__error(docstringContext.start(), 0, "D142") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
917 | if contextLines[end + 1].strip(): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
918 | self.__error(docstringContext.end(), 0, "D143") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
919 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
920 | def __checkBlankAfterSummary(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
921 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
922 | Private method to check, that docstring summaries are followed |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
923 | by a blank line. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
924 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
925 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
926 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
927 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
928 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
929 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
930 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
931 | docstrings = docstringContext.source() |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
932 | if len(docstrings) <= 3: |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
933 | # correct/invalid one-liner |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
934 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
935 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
936 | summary, lineNumber = self.__getSummaryLine(docstringContext) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
937 | if len(docstrings) > 2: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
938 | if docstrings[lineNumber + 1].strip(): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
939 | self.__error(docstringContext.start() + lineNumber, 0, "D144") |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
940 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
941 | def __checkBlankAfterLastParagraph(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
942 | """ |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
943 | Private method to check, that the last paragraph of docstrings is |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
944 | followed by a blank line. |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
945 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
946 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
947 | @param context context of the docstring (DocStyleContext) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
948 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
949 | if docstringContext is None: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
950 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
951 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
952 | docstrings = docstringContext.source() |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
953 | if len(docstrings) <= 3: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
954 | # correct/invalid one-liner |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
955 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
956 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
957 | if docstrings[-2].strip(): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
958 | self.__error(docstringContext.end(), 0, "D145") |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
959 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
960 | ################################################################## |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
961 | ## Checking functionality below (eric specific ones) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
962 | ################################################################## |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
963 | |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
964 | def __checkEricQuotesOnSeparateLines(self, docstringContext, context): |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
965 | """ |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
966 | Private method to check, that leading and trailing quotes are on |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
967 | a line by themselves. |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
968 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
969 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
970 | @param context context of the docstring (DocStyleContext) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
971 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
972 | if docstringContext is None: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
973 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
974 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
975 | lines = docstringContext.source() |
2948
ea04689ee599
Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2946
diff
changeset
|
976 | if lines[0].strip().strip('ru"\''): |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
977 | self.__error(docstringContext.start(), 0, "D221") |
2948
ea04689ee599
Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2946
diff
changeset
|
978 | if lines[-1].strip().strip('"\''): |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
979 | self.__error(docstringContext.end(), 0, "D222") |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
980 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
981 | def __checkEricEndsWithPeriod(self, docstringContext, context): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
982 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
983 | Private method to check, that docstring summaries end with a period. |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
984 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
985 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
986 | @param context context of the docstring (DocStyleContext) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
987 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
988 | if docstringContext is None: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
989 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
990 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
991 | summaryLines, lineNumber = self.__getSummaryLines(docstringContext) |
3165
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
992 | if summaryLines: |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
993 | if summaryLines[-1].lstrip().startswith("@"): |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
994 | summaryLines.pop(-1) |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
995 | summary = " ".join([s.strip() for s in summaryLines if s]) |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
996 | if summary and not summary.endswith(".") and \ |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
997 | not summary.split(None, 1)[0].lower() == "constructor": |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
998 | self.__error( |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
999 | docstringContext.start() + lineNumber + |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
1000 | len(summaryLines) - 1, |
400234200cd6
Fixed a serious bug in the doc style checker and made the style checker for Python2 more robust against exceptions in the external process.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3160
diff
changeset
|
1001 | 0, "D231") |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1002 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1003 | def __checkEricReturn(self, docstringContext, context): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1004 | """ |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1005 | Private method to check, that docstrings contain an @return line |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1006 | if they return anything and don't otherwise. |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1007 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1008 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1009 | @param context context of the docstring (DocStyleContext) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1010 | """ |
2968
b109ff4678bc
Removed the check for a module being a script because scripts should be well documented as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2967
diff
changeset
|
1011 | if docstringContext is None: |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1012 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1013 | |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1014 | tokens = list( |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1015 | tokenize.generate_tokens(StringIO(context.ssource()).readline)) |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1016 | return_ = [tokens[i + 1][0] for i, token in enumerate(tokens) |
2961
e4e2efb4846a
Change to the doc style checker to treat yield like return for the eric doc style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2952
diff
changeset
|
1017 | if token[1] in ("return", "yield")] |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1018 | if "@return" not in docstringContext.ssource(): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1019 | if (set(return_) - |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1020 | set([tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE]) != |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1021 | set([])): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1022 | self.__error(docstringContext.end(), 0, "D234") |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1023 | else: |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1024 | if (set(return_) - |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1025 | set([tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE]) == |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1026 | set([])): |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1027 | self.__error(docstringContext.end(), 0, "D235") |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1028 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1029 | def __checkEricFunctionArguments(self, docstringContext, context): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1030 | """ |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1031 | Private method to check, that docstrings contain an @param and/or |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1032 | @keyparam line for each argument. |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1033 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1034 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1035 | @param context context of the docstring (DocStyleContext) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1036 | """ |
2968
b109ff4678bc
Removed the check for a module being a script because scripts should be well documented as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2967
diff
changeset
|
1037 | if docstringContext is None: |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1038 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1039 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1040 | try: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1041 | tree = ast.parse(context.ssource()) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1042 | except (SyntaxError, TypeError): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1043 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1044 | if (isinstance(tree, ast.Module) and len(tree.body) == 1 and |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1045 | isinstance(tree.body[0], ast.FunctionDef)): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1046 | functionDef = tree.body[0] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1047 | argNames, kwNames = self.__getArgNames(functionDef) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1048 | if "self" in argNames: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1049 | argNames.remove("self") |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1050 | if "cls" in argNames: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1051 | argNames.remove("cls") |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1052 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1053 | docstring = docstringContext.ssource() |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1054 | if (docstring.count("@param") + docstring.count("@keyparam") < |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1055 | len(argNames + kwNames)): |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1056 | self.__error(docstringContext.end(), 0, "D236") |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1057 | elif (docstring.count("@param") + docstring.count("@keyparam") > |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1058 | len(argNames + kwNames)): |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1059 | self.__error(docstringContext.end(), 0, "D237") |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1060 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1061 | # extract @param and @keyparam from docstring |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1062 | args = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1063 | kwargs = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1064 | for line in docstringContext.source(): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1065 | if line.strip().startswith(("@param", "@keyparam")): |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1066 | at, name = line.strip().split(None, 2)[:2] |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1067 | if at == "@keyparam": |
2952
94fc661a54a2
Fixed an issue parsing the eric style doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2949
diff
changeset
|
1068 | kwargs.append(name.lstrip("*")) |
94fc661a54a2
Fixed an issue parsing the eric style doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2949
diff
changeset
|
1069 | args.append(name.lstrip("*")) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1070 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1071 | # do the checks |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1072 | for name in kwNames: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1073 | if name not in kwargs: |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1074 | self.__error(docstringContext.end(), 0, "D238") |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1075 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1076 | if argNames + kwNames != args: |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1077 | self.__error(docstringContext.end(), 0, "D239") |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1078 | |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1079 | def __checkEricException(self, docstringContext, context): |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1080 | """ |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1081 | Private method to check, that docstrings contain an @exception line |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1082 | if they raise an exception and don't otherwise. |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1083 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1084 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1085 | @param context context of the docstring (DocStyleContext) |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1086 | """ |
2968
b109ff4678bc
Removed the check for a module being a script because scripts should be well documented as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2967
diff
changeset
|
1087 | if docstringContext is None: |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1088 | return |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1089 | |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1090 | tokens = list( |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1091 | tokenize.generate_tokens(StringIO(context.ssource()).readline)) |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1092 | exception = [tokens[i + 1][0] for i, token in enumerate(tokens) |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1093 | if token[1] == "raise"] |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1094 | if "@exception" not in docstringContext.ssource() and \ |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1095 | "@throws" not in docstringContext.ssource() and \ |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1096 | "@raise" not in docstringContext.ssource(): |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1097 | if (set(exception) - |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1098 | set([tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE]) != |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1099 | set([])): |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1100 | self.__error(docstringContext.end(), 0, "D250") |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1101 | else: |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1102 | if (set(exception) - |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1103 | set([tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE]) == |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1104 | set([])): |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1105 | self.__error(docstringContext.end(), 0, "D251") |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1106 | |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1107 | def __checkEricBlankAfterSummary(self, docstringContext, context): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1108 | """ |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1109 | Private method to check, that docstring summaries are followed |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1110 | by a blank line. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1111 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1112 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1113 | @param context context of the docstring (DocStyleContext) |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1114 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1115 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1116 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1117 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1118 | docstrings = docstringContext.source() |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1119 | if len(docstrings) <= 3: |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1120 | # correct/invalid one-liner |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1121 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1122 | |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1123 | summaryLines, lineNumber = self.__getSummaryLines(docstringContext) |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1124 | if len(docstrings) - 2 > lineNumber + len(summaryLines) - 1: |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1125 | if docstrings[lineNumber + len(summaryLines)].strip(): |
2934
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1126 | self.__error(docstringContext.start() + lineNumber, 0, "D246") |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1127 | |
2934
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1128 | def __checkEricNoBlankBeforeAndAfterClassOrFunction( |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1129 | self, docstringContext, context): |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1130 | """ |
2934
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1131 | Private method to check, that class and function/method docstrings |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1132 | have no blank line around them. |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1133 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1134 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1135 | @param context context of the docstring (DocStyleContext) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1136 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1137 | if docstringContext is None: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1138 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1139 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1140 | contextLines = context.source() |
2934
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1141 | isClassContext = contextLines[0].lstrip().startswith("class ") |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1142 | cti = 0 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1143 | while cti < len(contextLines) and \ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1144 | not contextLines[cti].strip().startswith( |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1145 | ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1146 | cti += 1 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1147 | if cti == len(contextLines): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1148 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1149 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1150 | start = cti |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1151 | if contextLines[cti].strip() in ( |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1152 | '"""', 'r"""', 'u"""', "'''", "r'''", "u'''"): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1153 | # it is a multi line docstring |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1154 | cti += 1 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1155 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1156 | while cti < len(contextLines) and \ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1157 | not contextLines[cti].strip().endswith(('"""', "'''")): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1158 | cti += 1 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1159 | end = cti |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1160 | if cti >= len(contextLines) - 1: |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1161 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1162 | |
2934
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1163 | if isClassContext: |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1164 | if not contextLines[start - 1].strip(): |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1165 | self.__error(docstringContext.start(), 0, "D242") |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1166 | if not contextLines[end + 1].strip(): |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1167 | self.__error(docstringContext.end(), 0, "D243") |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1168 | else: |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1169 | if not contextLines[start - 1].strip(): |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1170 | self.__error(docstringContext.start(), 0, "D244") |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1171 | if not contextLines[end + 1].strip(): |
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1172 | self.__error(docstringContext.end(), 0, "D245") |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1173 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1174 | def __checkEricNBlankAfterLastParagraph(self, docstringContext, context): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1175 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1176 | Private method to check, that the last paragraph of docstrings is |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1177 | not followed by a blank line. |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1178 | |
2983
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1179 | @param docstringContext docstring context (DocStyleContext) |
f2f33024b001
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2968
diff
changeset
|
1180 | @param context context of the docstring (DocStyleContext) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1181 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1182 | if docstringContext is None: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1183 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1184 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1185 | docstrings = docstringContext.source() |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1186 | if len(docstrings) <= 3: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1187 | # correct/invalid one-liner |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1188 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1189 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1190 | if not docstrings[-2].strip(): |
2934
82811ddafea2
Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2929
diff
changeset
|
1191 | self.__error(docstringContext.end(), 0, "D247") |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1192 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1193 | # |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1194 | # eflag: FileType = Python2 |