Fri, 04 Oct 2013 17:21:14 +0200
Continued changing the names of the various code style checkers to make them more appropriate to the broadened scope.
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 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | # Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de> |
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 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a checker for PEP-257 documentation string conventions. |
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 | """ |
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
|
103 | Class implementing a checker for PEP-257 and eric 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", |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | "D131", "D132", "D133", "D134", |
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",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
190 | (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
|
191 | (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
|
192 | (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
|
193 | ], |
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 | 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
|
196 | checkersWithCodes = { |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
197 | "moduleDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
198 | (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
|
199 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
200 | "functionDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
201 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
202 | "classDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
203 | (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
|
204 | (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
|
205 | ("D242", "D243")), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
206 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
207 | "methodDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
208 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
209 | "defDocstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
210 | (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
|
211 | (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
|
212 | (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
|
213 | (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
|
214 | (self.__checkEricFunctionArguments, |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
215 | ("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
|
216 | (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
|
217 | ("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
|
218 | (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
|
219 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
220 | "docstring": [ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
221 | (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
|
222 | (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
|
223 | (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
|
224 | (self.__checkIndent, ("D122",)), |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
225 | (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
|
226 | (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
|
227 | (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
|
228 | (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
|
229 | ], |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
230 | } |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | 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
|
233 | 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
|
234 | for checker, codes in checkers: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | 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
|
236 | for code in codes): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | 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
|
238 | self.__checkers[key] = [] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | self.__checkers[key].append(checker) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | def __ignoreCode(self, code): |
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 | 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
|
244 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | @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
|
246 | @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
|
247 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | 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
|
249 | not code.startswith(self.__select)) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
250 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
251 | 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
|
252 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | 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
|
254 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | @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
|
256 | @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
|
257 | @param code message code (string) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | @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
|
259 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | if self.__ignoreCode(code): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | if code in self.counters: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
264 | self.counters[code] += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | else: |
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 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | # 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
|
269 | if code in self.__expected: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
272 | 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
|
273 | # 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
|
274 | self.errors.append( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | (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
|
276 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | def __resetReadline(self): |
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 | 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
|
280 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | self.__lineNumber = 0 |
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 | def __readline(self): |
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 | 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
|
286 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | @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
|
288 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | self.__lineNumber += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | 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
|
291 | return '' |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | 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
|
293 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | def run(self): |
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 | Public method to check the given source for violations of doc string |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | conventions according to PEP-257. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | 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
|
300 | # 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
|
301 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | |
2967
f9acd647f881
Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2961
diff
changeset
|
303 | if not self.__checkers: |
f9acd647f881
Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2961
diff
changeset
|
304 | # 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
|
305 | return |
f9acd647f881
Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2961
diff
changeset
|
306 | |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | for keyword in self.__keywords: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | if keyword in self.__checkers: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | 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
|
310 | 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
|
311 | docstring = self.__parseDocstring(context, keyword) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | check(docstring, context) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | def __getSummaryLine(self, docstringContext): |
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 | 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
|
317 | |
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
|
318 | @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
|
319 | @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
|
320 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | lines = docstringContext.source() |
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 | line = (lines[0] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | .replace('r"""', "", 1) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | .replace('u"""', "", 1) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | .replace('"""', "") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
327 | .replace("r'''", "", 1) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | .replace("u'''", "", 1) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
329 | .replace("'''", "") |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | .strip()) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | 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
|
333 | 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
|
334 | 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
|
335 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
336 | 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
|
337 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
338 | 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
|
339 | |
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
|
340 | @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
|
341 | @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
|
342 | (integer) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
343 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
344 | summaries = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
345 | 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
|
346 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
347 | 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
|
348 | .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
|
349 | .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
|
350 | .replace('"""', "") |
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("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
|
352 | .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
|
353 | .replace("'''", "") |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
354 | .strip()) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
355 | 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
|
356 | 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
|
357 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
358 | line1 = "" |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
359 | 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
|
360 | 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
|
361 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
362 | line2 = "" |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
363 | if line0: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
364 | lineno = 0 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
365 | 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
|
366 | 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
|
367 | # 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
|
368 | 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
|
369 | elif line1: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
370 | lineno = 1 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
371 | 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
|
372 | 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
|
373 | # 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
|
374 | 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
|
375 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
376 | lineno = 2 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
377 | 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
|
378 | 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
|
379 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
380 | 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
|
381 | 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
|
382 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
383 | 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
|
384 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
385 | @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
|
386 | @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
|
387 | 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
|
388 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
389 | 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
|
390 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
391 | 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
|
392 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
393 | @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
|
394 | @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
|
395 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
396 | ret = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
397 | 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
|
398 | 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
|
399 | 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
|
400 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
401 | 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
|
402 | return ret |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
403 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
404 | 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
|
405 | 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
|
406 | 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
|
407 | kwarguments = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
408 | 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
|
409 | 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
|
410 | 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
|
411 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
412 | 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
|
413 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
414 | 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
|
415 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
416 | @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
|
417 | @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
|
418 | 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
|
419 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
420 | arguments = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
421 | 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
|
422 | 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
|
423 | 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
|
424 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
425 | kwarguments = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
426 | 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
|
427 | 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
|
428 | 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
|
429 | return arguments, kwarguments |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
430 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
431 | ################################################################## |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
432 | ## Parsing functionality below |
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 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
435 | def __parseModuleDocstring(self, source): |
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 | 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
|
438 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | @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
|
440 | @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
|
441 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
442 | 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
|
443 | StringIO("".join(source)).readline): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
444 | 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
|
445 | continue |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
446 | 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
|
447 | 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
|
448 | else: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
449 | return None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
450 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | def __parseDocstring(self, context, what=''): |
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 | 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
|
454 | |
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
|
455 | @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
|
456 | @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
|
457 | @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
|
458 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
459 | moduleDocstring = self.__parseModuleDocstring(context.source()) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
460 | 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
|
461 | return moduleDocstring |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
462 | if moduleDocstring: |
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 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
465 | tokenGenerator = tokenize.generate_tokens( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
466 | StringIO(context.ssource()).readline) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
467 | try: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
468 | kind = None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
469 | while kind != tokenize.INDENT: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
470 | kind, _, _, _, _ = next(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
471 | 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
|
472 | 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
|
473 | return DocStyleContext( |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
474 | 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
|
475 | except StopIteration: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
476 | pass |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
477 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
478 | return None |
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 | def __parseTopLevel(self, keyword): |
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 | 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
|
483 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
484 | @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
|
485 | @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
|
486 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
487 | self.__resetReadline() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
488 | 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
|
489 | 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
|
490 | contexts = [] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
491 | try: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
492 | while True: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
493 | start, end = None, None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
494 | 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
|
495 | value == keyword and |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
496 | char == 0): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
497 | 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
|
498 | start = line - 1, char |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
499 | 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
|
500 | value == '' and |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
501 | char == 0): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
502 | 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
|
503 | 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
|
504 | contexts.append(DocStyleContext( |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
505 | 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
|
506 | except StopIteration: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
507 | return contexts |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
508 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
509 | def __parseFunctions(self): |
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 | 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
|
512 | |
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
|
513 | @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
|
514 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
515 | if not self.__functionsCache: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
516 | self.__functionsCache = self.__parseTopLevel('def') |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
517 | return self.__functionsCache |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
518 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
519 | def __parseClasses(self): |
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 | 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
|
522 | |
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
|
523 | @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
|
524 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
525 | if not self.__classesCache: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
526 | self.__classesCache = self.__parseTopLevel('class') |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
527 | return self.__classesCache |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
528 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
529 | def __skipIndentedBlock(self, tokenGenerator): |
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 | 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
|
532 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
533 | @param tokenGenerator token generator |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
534 | @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
|
535 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
536 | 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
|
537 | while kind != tokenize.INDENT: |
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 | indent = 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
540 | 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
|
541 | if kind == tokenize.INDENT: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
542 | indent += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
543 | elif kind == tokenize.DEDENT: |
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 | if indent == 0: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
546 | 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
|
547 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
548 | def __parseMethods(self): |
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 | 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
|
551 | |
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
|
552 | @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
|
553 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
554 | if not self.__methodsCache: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
555 | contexts = [] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
556 | for classContext in self.__parseClasses(): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
557 | tokenGenerator = tokenize.generate_tokens( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
558 | StringIO(classContext.ssource()).readline) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
559 | 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
|
560 | try: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
561 | while True: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
562 | start, end = None, None |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
563 | 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
|
564 | kind, value, (line, char), _, _ = \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
565 | next(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
566 | start = line - 1, char |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
567 | kind, value, (line, char), _, _ = \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
568 | self.__skipIndentedBlock(tokenGenerator) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
569 | end = line - 1, char |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
570 | startLine = classContext.start() + start[0] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
571 | endLine = classContext.start() + end[0] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
572 | 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
|
573 | DocStyleContext(self.__source[startLine:endLine], |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
574 | startLine, "def")) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
575 | except StopIteration: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
576 | pass |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
577 | self.__methodsCache = contexts |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
578 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
579 | return self.__methodsCache |
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 | def __parseContexts(self, kind): |
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 | 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
|
584 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
585 | @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
|
586 | @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
|
587 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
588 | 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
|
589 | 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
|
590 | if kind == 'functionDocstring': |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
591 | return self.__parseFunctions() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
592 | if kind == 'classDocstring': |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
593 | return self.__parseClasses() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
594 | if kind == 'methodDocstring': |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
595 | return self.__parseMethods() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
596 | if kind == 'defDocstring': |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
597 | return self.__parseFunctions() + self.__parseMethods() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
598 | 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
|
599 | 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
|
600 | self.__parseFunctions() + |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
601 | self.__parseClasses() + |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
602 | self.__parseMethods()) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
603 | return [] # fall back |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
604 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
605 | ################################################################## |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
606 | ## 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
|
607 | ################################################################## |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
608 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
609 | def __checkModulesDocstrings(self, docstringContext, context): |
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 | 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
|
612 | |
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
|
613 | @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
|
614 | @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
|
615 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
616 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
617 | 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
|
618 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
619 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
620 | docstring = docstringContext.ssource() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
621 | 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
|
622 | not docstring.strip('\'"')): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
623 | 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
|
624 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
625 | def __checkFunctionDocstring(self, docstringContext, context): |
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 | 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
|
628 | have a docstring. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
629 | |
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
|
630 | @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
|
631 | @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
|
632 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
633 | 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
|
634 | 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
|
635 | 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
|
636 | code = "D203" |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
637 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
638 | code = "D103" |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
639 | else: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
640 | code = "D102" |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
641 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
642 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
643 | 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
|
644 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
645 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
646 | docstring = docstringContext.ssource() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
647 | 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
|
648 | not docstring.strip('\'"')): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
649 | 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
|
650 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
651 | def __checkClassDocstring(self, docstringContext, context): |
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 | 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
|
654 | have a docstring. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
655 | |
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
|
656 | @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
|
657 | @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
|
658 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
659 | 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
|
660 | 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
|
661 | 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
|
662 | code = "D205" |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
663 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
664 | code = "D105" |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
665 | else: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
666 | code = "D104" |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
667 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
668 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
669 | 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
|
670 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
671 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
672 | docstring = docstringContext.ssource() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
673 | 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
|
674 | not docstring.strip('\'"')): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
675 | 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
|
676 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
677 | def __checkTripleDoubleQuotes(self, docstringContext, context): |
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 | 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
|
680 | by triple double quotes. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
681 | |
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
|
682 | @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
|
683 | @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
|
684 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
685 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
686 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
687 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
688 | docstring = docstringContext.ssource().strip() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
689 | 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
|
690 | 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
|
691 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
692 | def __checkBackslashes(self, docstringContext, context): |
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 | 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
|
695 | 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
|
696 | |
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
|
697 | @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
|
698 | @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
|
699 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
700 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
701 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
702 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
703 | docstring = docstringContext.ssource().strip() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
704 | 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
|
705 | 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
|
706 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
707 | def __checkUnicode(self, docstringContext, context): |
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 | 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
|
710 | 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
|
711 | |
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
|
712 | @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
|
713 | @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
|
714 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
715 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
716 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
717 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
718 | docstring = docstringContext.ssource().strip() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
719 | 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
|
720 | 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
|
721 | 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
|
722 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
723 | def __checkOneLiner(self, docstringContext, context): |
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 | 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
|
726 | one line with quotes. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
727 | |
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
|
728 | @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
|
729 | @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
|
730 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
731 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
732 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
733 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
734 | lines = docstringContext.source() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
735 | if len(lines) > 1: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
736 | 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
|
737 | if len(nonEmptyLines) == 1: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
738 | modLen = len(context.indent() + '"""' + |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
739 | nonEmptyLines[0].strip() + '"""') |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
740 | if context.contextType() != "module": |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
741 | 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
|
742 | 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
|
743 | # 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
|
744 | modLen += 1 |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
745 | if modLen <= self.__maxLineLength: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
746 | 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
|
747 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
748 | def __checkIndent(self, docstringContext, context): |
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 | 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
|
751 | |
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
|
752 | @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
|
753 | @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
|
754 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
755 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
756 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
757 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
758 | lines = docstringContext.source() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
759 | if len(lines) == 1: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
760 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
761 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
762 | 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
|
763 | if not nonEmptyLines: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
764 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
765 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
766 | 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
|
767 | if context.contextType() == "module": |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
768 | expectedIndent = 0 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
769 | else: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
770 | expectedIndent = len(context.indent()) + 4 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
771 | if indent != expectedIndent: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
772 | 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
|
773 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
774 | def __checkEndsWithPeriod(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
775 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
776 | 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
|
777 | |
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
|
778 | @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
|
779 | @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
|
780 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
781 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
782 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
783 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
784 | summary, lineNumber = self.__getSummaryLine(docstringContext) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
785 | if not summary.endswith("."): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
786 | 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
|
787 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
788 | def __checkImperativeMood(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
789 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
790 | 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
|
791 | imperative mood. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
792 | |
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
|
793 | @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
|
794 | @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
|
795 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
796 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
797 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
798 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
799 | summary, lineNumber = self.__getSummaryLine(docstringContext) |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
800 | firstWord = summary.strip().split()[0] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
801 | if firstWord.endswith("s") and not firstWord.endswith("ss"): |
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, "D132") |
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 __checkNoSignature(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 don't repeat |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
807 | the function's signature. |
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 | 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
|
816 | 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
|
817 | 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
|
818 | not functionName + "()" in summary.replace(" ", ""): |
ea04689ee599
Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2946
diff
changeset
|
819 | # 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
|
820 | 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
|
821 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
822 | def __checkReturnType(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
823 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
824 | 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
|
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 | """ |
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
|
829 | if docstringContext is None: |
2917
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 | 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
|
833 | tokens = list( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
834 | 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
|
835 | 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
|
836 | if token[1] == "return"] |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
837 | if (set(return_) - |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
838 | 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
|
839 | set([])): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
840 | 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
|
841 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
842 | def __checkNoBlankLineBefore(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
843 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
844 | 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
|
845 | preceded by a blank line. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
846 | |
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
|
847 | @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
|
848 | @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
|
849 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
850 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
851 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
852 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
853 | contextLines = context.source() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
854 | cti = 0 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
855 | while cti < len(contextLines) and \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
856 | not contextLines[cti].strip().startswith( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
857 | ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
858 | cti += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
859 | if cti == len(contextLines): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
860 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
861 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
862 | 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
|
863 | 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
|
864 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
865 | def __checkBlankBeforeAndAfterClass(self, docstringContext, context): |
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 | 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
|
868 | blank line around them. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
869 | |
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
|
870 | @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
|
871 | @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
|
872 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
873 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
874 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
875 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
876 | contextLines = context.source() |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
877 | cti = 0 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
878 | while cti < len(contextLines) and \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
879 | not contextLines[cti].strip().startswith( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
880 | ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
881 | cti += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
882 | if cti == len(contextLines): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
883 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
884 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
885 | start = cti |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
886 | if contextLines[cti].strip() in ( |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
887 | '"""', 'r"""', 'u"""', "'''", "r'''", "u'''"): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
888 | # 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
|
889 | cti += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
890 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
891 | while cti < len(contextLines) and \ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
892 | not contextLines[cti].strip().endswith(('"""', "'''")): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
893 | cti += 1 |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
894 | end = cti |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
895 | 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
|
896 | return |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
897 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
898 | if contextLines[start - 1].strip(): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
899 | 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
|
900 | if contextLines[end + 1].strip(): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
901 | 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
|
902 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
903 | def __checkBlankAfterSummary(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
904 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
905 | 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
|
906 | by a blank line. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
907 | |
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
|
908 | @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
|
909 | @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
|
910 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
911 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
912 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
913 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
914 | 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
|
915 | if len(docstrings) <= 3: |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
916 | # correct/invalid one-liner |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
917 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
918 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
919 | 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
|
920 | 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
|
921 | 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
|
922 | 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
|
923 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
924 | def __checkBlankAfterLastParagraph(self, docstringContext, context): |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
925 | """ |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
926 | 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
|
927 | 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
|
928 | |
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
|
929 | @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
|
930 | @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
|
931 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
932 | 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
|
933 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
934 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
935 | 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
|
936 | 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
|
937 | # 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
|
938 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
939 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
940 | 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
|
941 | 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
|
942 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
943 | ################################################################## |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
944 | ## 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
|
945 | ################################################################## |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
946 | |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
947 | 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
|
948 | """ |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
949 | 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
|
950 | 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
|
951 | |
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
|
952 | @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
|
953 | @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
|
954 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
955 | 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
|
956 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
957 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
958 | lines = docstringContext.source() |
2948
ea04689ee599
Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2946
diff
changeset
|
959 | 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
|
960 | 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
|
961 | 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
|
962 | 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
|
963 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
964 | 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
|
965 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
966 | 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
|
967 | |
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
|
968 | @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
|
969 | @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
|
970 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
971 | 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
|
972 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
973 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
974 | 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
|
975 | if summaryLines[-1].lstrip().startswith("@"): |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
976 | summaryLines.pop(-1) |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
977 | summary = " ".join([s.strip() for s in summaryLines if s]) |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
978 | if not summary.endswith(".") and \ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
979 | not summary.split(None, 1)[0].lower() == "constructor": |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
980 | self.__error( |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
981 | docstringContext.start() + lineNumber + len(summaryLines) - 1, |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
982 | 0, "D231") |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
983 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
984 | 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
|
985 | """ |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
986 | 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
|
987 | 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
|
988 | |
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
|
989 | @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
|
990 | @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
|
991 | """ |
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
|
992 | 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
|
993 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
994 | |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
995 | tokens = list( |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
996 | 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
|
997 | 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
|
998 | 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
|
999 | 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
|
1000 | 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
|
1001 | 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
|
1002 | set([])): |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1003 | 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
|
1004 | else: |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1005 | if (set(return_) - |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1006 | 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
|
1007 | set([])): |
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1008 | 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
|
1009 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1010 | 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
|
1011 | """ |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1012 | 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
|
1013 | @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
|
1014 | |
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
|
1015 | @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
|
1016 | @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
|
1017 | """ |
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
|
1018 | 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
|
1019 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1020 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1021 | try: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1022 | 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
|
1023 | 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
|
1024 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1025 | 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
|
1026 | 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
|
1027 | 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
|
1028 | 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
|
1029 | 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
|
1030 | 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
|
1031 | 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
|
1032 | 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
|
1033 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1034 | 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
|
1035 | 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
|
1036 | 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
|
1037 | 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
|
1038 | 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
|
1039 | 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
|
1040 | 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
|
1041 | else: |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1042 | # 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
|
1043 | args = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1044 | kwargs = [] |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1045 | 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
|
1046 | 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
|
1047 | 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
|
1048 | if at == "@keyparam": |
2952
94fc661a54a2
Fixed an issue parsing the eric style doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2949
diff
changeset
|
1049 | kwargs.append(name.lstrip("*")) |
94fc661a54a2
Fixed an issue parsing the eric style doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2949
diff
changeset
|
1050 | 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
|
1051 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1052 | # 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
|
1053 | 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
|
1054 | 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
|
1055 | 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
|
1056 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1057 | 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
|
1058 | 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
|
1059 | |
2949
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1060 | 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
|
1061 | """ |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1062 | 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
|
1063 | 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
|
1064 | |
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
|
1065 | @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
|
1066 | @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
|
1067 | """ |
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
|
1068 | 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
|
1069 | return |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1070 | |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1071 | 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
|
1072 | 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
|
1073 | 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
|
1074 | 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
|
1075 | 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
|
1076 | "@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
|
1077 | "@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
|
1078 | 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
|
1079 | 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
|
1080 | set([])): |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1081 | 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
|
1082 | else: |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1083 | 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
|
1084 | 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
|
1085 | set([])): |
e8f41288a688
Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2948
diff
changeset
|
1086 | 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
|
1087 | |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1088 | 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
|
1089 | """ |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1090 | 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
|
1091 | by a blank line. |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1092 | |
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
|
1093 | @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
|
1094 | @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
|
1095 | """ |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1096 | if docstringContext is None: |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1097 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1098 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1099 | 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
|
1100 | if len(docstrings) <= 3: |
2917
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1101 | # correct/invalid one-liner |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1102 | return |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1103 | |
2929
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1104 | 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
|
1105 | 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
|
1106 | 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
|
1107 | 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
|
1108 | |
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
|
1109 | 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
|
1110 | 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
|
1111 | """ |
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
|
1112 | 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
|
1113 | 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
|
1114 | |
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
|
1115 | @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
|
1116 | @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
|
1117 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1118 | 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
|
1119 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1120 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1121 | 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
|
1122 | 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
|
1123 | cti = 0 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1124 | 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
|
1125 | 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
|
1126 | ('"""', '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
|
1127 | cti += 1 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1128 | 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
|
1129 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1130 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1131 | start = cti |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1132 | 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
|
1133 | '"""', '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
|
1134 | # 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
|
1135 | cti += 1 |
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 | 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
|
1138 | 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
|
1139 | cti += 1 |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1140 | end = cti |
2946
987b6368dbae
Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2934
diff
changeset
|
1141 | 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
|
1142 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1143 | |
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
|
1144 | 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
|
1145 | 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
|
1146 | 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
|
1147 | 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
|
1148 | 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
|
1149 | 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
|
1150 | 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
|
1151 | 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
|
1152 | 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
|
1153 | 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
|
1154 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1155 | 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
|
1156 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1157 | 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
|
1158 | 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
|
1159 | |
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
|
1160 | @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
|
1161 | @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
|
1162 | """ |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1163 | 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
|
1164 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1165 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1166 | 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
|
1167 | 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
|
1168 | # 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
|
1169 | return |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1170 | |
28ab0bc63d69
Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2917
diff
changeset
|
1171 | 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
|
1172 | 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
|
1173 | |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1174 | # |
fe82710d02cb
Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1175 | # eflag: FileType = Python2 |