UtilitiesPython2/Pep257CheckerPy2.py

Sun, 29 Sep 2013 18:41:53 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 29 Sep 2013 18:41:53 +0200
changeset 2967
f9acd647f881
parent 2961
e4e2efb4846a
child 2968
b109ff4678bc
permissions
-rw-r--r--

Some little optimization in the doc style checker.

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
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 class Pep257Context(object):
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
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 class Pep257Checker(object):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 Class 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
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 self.__isScript = self.__source[0].startswith('#!')
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 # statistics counters
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 self.counters = {}
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 # collection of detected errors
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 self.errors = []
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 self.__lineNumber = 0
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 # caches
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 self.__functionsCache = None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 self.__classesCache = None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self.__methodsCache = None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.__keywords = [
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 'moduleDocstring', 'functionDocstring',
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 'classDocstring', 'methodDocstring',
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 'defDocstring', 'docstring'
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 ]
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
165 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
166 checkersWithCodes = {
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
167 "moduleDocstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
168 (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
169 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
170 "functionDocstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
171 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
172 "classDocstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
173 (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
174 (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
175 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
176 "methodDocstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
177 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
178 "defDocstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
179 (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
180 (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
181 (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
182 (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
183 (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
184 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
185 "docstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
186 (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
187 (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
188 (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
189 (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
190 (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
191 (self.__checkEndsWithPeriod, ("D131",)),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
192 (self.__checkBlankAfterSummary, ("D144",)),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
193 (self.__checkBlankAfterLastParagraph, ("D145",)),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
194 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
195 }
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
196 elif self.__docType == "eric":
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
197 checkersWithCodes = {
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
198 "moduleDocstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
199 (self.__checkModulesDocstrings, ("D101",)),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
200 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
201 "functionDocstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
202 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
203 "classDocstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
204 (self.__checkClassDocstring, ("D104", "D205")),
2934
82811ddafea2 Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2929
diff changeset
205 (self.__checkEricNoBlankBeforeAndAfterClassOrFunction,
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
206 ("D242", "D243")),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
207 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
208 "methodDocstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
209 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
210 "defDocstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
211 (self.__checkFunctionDocstring, ("D102", "D203")),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
212 (self.__checkImperativeMood, ("D132",)),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
213 (self.__checkNoSignature, ("D133",)),
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
214 (self.__checkEricReturn, ("D234", "D235")),
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
215 (self.__checkEricFunctionArguments,
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
216 ("D236", "D237", "D238", "D239")),
2934
82811ddafea2 Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2929
diff changeset
217 (self.__checkEricNoBlankBeforeAndAfterClassOrFunction,
82811ddafea2 Extended the eric doc string checks for functions not surrounded by blank lines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2929
diff changeset
218 ("D244", "D245")),
2949
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
219 (self.__checkEricException, ("D250", "D251")),
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
220 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
221 "docstring": [
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
222 (self.__checkTripleDoubleQuotes, ("D111",)),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
223 (self.__checkBackslashes, ("D112",)),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
224 (self.__checkUnicode, ("D113",)),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
225 (self.__checkIndent, ("D122",)),
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
226 (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
227 (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
228 (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
229 (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
230 ],
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
231 }
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 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
234 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
235 for checker, codes in checkers:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 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
237 for code in codes):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 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
239 self.__checkers[key] = []
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 self.__checkers[key].append(checker)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 def __ignoreCode(self, code):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 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
245
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 @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
247 @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
248 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 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
250 not code.startswith(self.__select))
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 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
253 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 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
255
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 @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
257 @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
258 @param code message code (string)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 @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
260 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 if self.__ignoreCode(code):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 if code in self.counters:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 self.counters[code] += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 else:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 self.counters[code] = 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 # 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
270 if code in self.__expected:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 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
274 # 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
275 self.errors.append(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 (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
277
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 def __resetReadline(self):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 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
281 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 self.__lineNumber = 0
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 def __readline(self):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 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
287
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 @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
289 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 self.__lineNumber += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 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
292 return ''
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 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
294
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 def run(self):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 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
298 conventions according to PEP-257.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 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
301 # 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
302 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303
2967
f9acd647f881 Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2961
diff changeset
304 if not self.__checkers:
f9acd647f881 Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2961
diff changeset
305 # 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
306 return
f9acd647f881 Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2961
diff changeset
307
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 for keyword in self.__keywords:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 if keyword in self.__checkers:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 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
311 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
312 docstring = self.__parseDocstring(context, keyword)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 check(docstring, context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 def __getSummaryLine(self, docstringContext):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 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
318
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 @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
321 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 lines = docstringContext.source()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 line = (lines[0]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 .replace('r"""', "", 1)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 .replace('u"""', "", 1)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 .replace('"""', "")
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 .replace("r'''", "", 1)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 .replace("u'''", "", 1)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 .replace("'''", "")
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 .strip())
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 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
334 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
335 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
336
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
337 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
338 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
339 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
340
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
341 @param docstringContext docstring context (Pep257Context)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
342 @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
343 (integer)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
344 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
345 summaries = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
346 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
347
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
348 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
349 .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
350 .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
351 .replace('"""', "")
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("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
353 .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
354 .replace("'''", "")
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
355 .strip())
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
356 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
357 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
358 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
359 line1 = ""
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
360 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
361 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
362 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
363 line2 = ""
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
364 if line0:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
365 lineno = 0
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
366 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
367 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
368 # 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
369 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
370 elif line1:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
371 lineno = 1
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
372 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
373 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
374 # 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
375 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
376 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
377 lineno = 2
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
378 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
379 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
380
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
381 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
382 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
383 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
384 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
385
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
386 @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
387 @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
388 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
389 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
390 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
391 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
392 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
393
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
394 @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
395 @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
396 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
397 ret = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
398 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
399 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
400 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
401 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
402 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
403 return ret
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
404
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
405 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
406 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
407 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
408 kwarguments = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
409 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
410 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
411 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
412 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
413 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
414 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
415 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
416
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
417 @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
418 @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
419 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
420 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
421 arguments = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
422 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
423 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
424 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
425
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
426 kwarguments = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
427 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
428 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
429 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
430 return arguments, kwarguments
2917
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 ##################################################################
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 ## Parsing functionality below
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
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 def __parseModuleDocstring(self, source):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 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
439
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 @param source source to parse (list of string)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 @return context of extracted docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 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
444 StringIO("".join(source)).readline):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 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
446 continue
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 elif kind == tokenize.STRING: # first STRING should be docstring
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 return Pep257Context(value, line - 1, "docstring")
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 else:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 return None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 def __parseDocstring(self, context, what=''):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
453 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454 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
455
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 @param context context data to get the docstring from (Pep257Context)
2949
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
457 @param what string denoting what is being parsed (string)
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
458 @return context of extracted docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 moduleDocstring = self.__parseModuleDocstring(context.source())
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 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
462 return moduleDocstring
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 if moduleDocstring:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 return moduleDocstring
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 tokenGenerator = tokenize.generate_tokens(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 StringIO(context.ssource()).readline)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 try:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 kind = None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
470 while kind != tokenize.INDENT:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 kind, _, _, _, _ = next(tokenGenerator)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 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
473 if kind == tokenize.STRING: # STRING after INDENT is a docstring
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474 return Pep257Context(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 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
476 except StopIteration:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 pass
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
479 return None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
480
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
481 def __parseTopLevel(self, keyword):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
482 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
483 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
484
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 @param keyword keyword signaling what to extract (string)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486 @return extracted function or class contexts (list of Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
488 self.__resetReadline()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
489 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
490 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
491 contexts = []
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 try:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 while True:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 start, end = None, None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
495 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
496 value == keyword and
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 char == 0):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 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
499 start = line - 1, char
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500 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
501 value == '' and
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502 char == 0):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
503 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
504 end = line - 1, char
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505 contexts.append(Pep257Context(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 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
507 except StopIteration:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 return contexts
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
509
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 def __parseFunctions(self):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
511 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
512 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
513
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 @return extracted function contexts (list of Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
515 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
516 if not self.__functionsCache:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517 self.__functionsCache = self.__parseTopLevel('def')
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
518 return self.__functionsCache
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
519
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 def __parseClasses(self):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
521 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
522 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
523
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
524 @return extracted class contexts (list of Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
525 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526 if not self.__classesCache:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527 self.__classesCache = self.__parseTopLevel('class')
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
528 return self.__classesCache
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
529
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530 def __skipIndentedBlock(self, tokenGenerator):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
531 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
532 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
533
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
534 @param tokenGenerator token generator
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 @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
536 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
537 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
538 while kind != tokenize.INDENT:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
539 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
540 indent = 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541 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
542 if kind == tokenize.INDENT:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
543 indent += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
544 elif kind == tokenize.DEDENT:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
545 indent -= 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
546 if indent == 0:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547 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
548
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
549 def __parseMethods(self):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
550 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
551 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
552
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
553 @return extracted method contexts (list of Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
554 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 if not self.__methodsCache:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556 contexts = []
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
557 for classContext in self.__parseClasses():
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 tokenGenerator = tokenize.generate_tokens(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
559 StringIO(classContext.ssource()).readline)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
560 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
561 try:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
562 while True:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
563 start, end = None, None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
564 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
565 kind, value, (line, char), _, _ = \
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
566 next(tokenGenerator)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567 start = line - 1, char
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
568 kind, value, (line, char), _, _ = \
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
569 self.__skipIndentedBlock(tokenGenerator)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
570 end = line - 1, char
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
571 startLine = classContext.start() + start[0]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
572 endLine = classContext.start() + end[0]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
573 contexts.append(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
574 Pep257Context(self.__source[startLine:endLine],
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
575 startLine, "def"))
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
576 except StopIteration:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
577 pass
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
578 self.__methodsCache = contexts
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
579
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
580 return self.__methodsCache
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
581
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
582 def __parseContexts(self, kind):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
583 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
584 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
585
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
586 @param kind kind of context to extract (string)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
587 @return requested contexts (list of Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
588 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
589 if kind == 'moduleDocstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
590 return [Pep257Context(self.__source, 0, "module")]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
591 if kind == 'functionDocstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
592 return self.__parseFunctions()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
593 if kind == 'classDocstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
594 return self.__parseClasses()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
595 if kind == 'methodDocstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
596 return self.__parseMethods()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
597 if kind == 'defDocstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
598 return self.__parseFunctions() + self.__parseMethods()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
599 if kind == 'docstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
600 return ([Pep257Context(self.__source, 0, "module")] +
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
601 self.__parseFunctions() +
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
602 self.__parseClasses() +
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
603 self.__parseMethods())
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
604 return [] # fall back
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
605
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
606 ##################################################################
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
607 ## 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
608 ##################################################################
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
609
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
610 def __checkModulesDocstrings(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
611 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
612 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
613
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
614 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
615 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
616 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
617 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
618 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
619 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
620
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
621 docstring = docstringContext.ssource()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
622 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
623 not docstring.strip('\'"')):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
624 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
625
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
626 def __checkFunctionDocstring(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
627 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
628 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
629 have a docstring.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
630
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
631 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
632 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
633 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
634 if self.__isScript:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
635 # assume nothing is exported
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
636 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
637
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
638 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
639 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
640 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
641 code = "D203"
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
642 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
643 code = "D103"
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
644 else:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
645 code = "D102"
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
646
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
647 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
648 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
649 return
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 docstring = docstringContext.ssource()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
652 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
653 not docstring.strip('\'"')):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
654 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
655
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
656 def __checkClassDocstring(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
657 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
658 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
659 have a docstring.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
660
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
661 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
662 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
663 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
664 if self.__isScript:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
665 # assume nothing is exported
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
666 return
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 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
669 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
670 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
671 code = "D205"
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
672 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
673 code = "D105"
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
674 else:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
675 code = "D104"
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 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
678 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
679 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
680
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
681 docstring = docstringContext.ssource()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
682 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
683 not docstring.strip('\'"')):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
684 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
685
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
686 def __checkTripleDoubleQuotes(self, docstringContext, context):
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 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
689 by triple double quotes.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
690
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
691 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
692 @param context context of the docstring (Pep257Context)
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 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
695 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
696
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
697 docstring = docstringContext.ssource().strip()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
698 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
699 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
700
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
701 def __checkBackslashes(self, docstringContext, context):
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 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
704 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
705
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
706 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
707 @param context context of the docstring (Pep257Context)
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 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
710 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
711
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
712 docstring = docstringContext.ssource().strip()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
713 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
714 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
715
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
716 def __checkUnicode(self, docstringContext, context):
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 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
719 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
720
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
721 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
722 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
723 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
724 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
725 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
726
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
727 docstring = docstringContext.ssource().strip()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
728 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
729 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
730 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
731
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
732 def __checkOneLiner(self, docstringContext, context):
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 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
735 one line with quotes.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
736
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
737 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
738 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
739 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
740 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
741 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
742
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
743 lines = docstringContext.source()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
744 if len(lines) > 1:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
745 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
746 if len(nonEmptyLines) == 1:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
747 modLen = len(context.indent() + '"""' +
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
748 nonEmptyLines[0].strip() + '"""')
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
749 if context.contextType() != "module":
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
750 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
751 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
752 # 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
753 modLen += 1
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
754 if modLen <= self.__maxLineLength:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
755 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
756
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
757 def __checkIndent(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
758 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
759 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
760
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
761 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
762 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
763 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
764 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
765 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
766
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
767 lines = docstringContext.source()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
768 if len(lines) == 1:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
769 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
770
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
771 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
772 if not nonEmptyLines:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
773 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
774
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
775 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
776 if context.contextType() == "module":
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
777 expectedIndent = 0
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
778 else:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
779 expectedIndent = len(context.indent()) + 4
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
780 if indent != expectedIndent:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
781 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
782
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
783 def __checkEndsWithPeriod(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
784 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
785 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
786
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
787 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
788 @param context context of the docstring (Pep257Context)
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 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
791 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
792
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
793 summary, lineNumber = self.__getSummaryLine(docstringContext)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
794 if not summary.endswith("."):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
795 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
796
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
797 def __checkImperativeMood(self, docstringContext, context):
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 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
800 imperative mood.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
801
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
802 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
803 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
804 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
805 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
806 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
807
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
808 summary, lineNumber = self.__getSummaryLine(docstringContext)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
809 firstWord = summary.strip().split()[0]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
810 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
811 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
812
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
813 def __checkNoSignature(self, docstringContext, context):
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 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
816 the function's signature.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
817
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
818 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
819 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
820 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
821 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
822 return
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 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
825 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
826 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
827 not functionName + "()" in summary.replace(" ", ""):
ea04689ee599 Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2946
diff changeset
828 # 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
829 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
830
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
831 def __checkReturnType(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
832 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
833 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
834
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
835 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
836 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
837 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
838 if docstringContext is None or self.__isScript:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
839 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
840
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
841 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
842 tokens = list(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
843 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
844 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
845 if token[1] == "return"]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
846 if (set(return_) -
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
847 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
848 set([])):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
849 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
850
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
851 def __checkNoBlankLineBefore(self, docstringContext, context):
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 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
854 preceded by a blank line.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
855
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
856 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
857 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
858 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
859 if docstringContext is None:
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 contextLines = context.source()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
863 cti = 0
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
864 while cti < len(contextLines) and \
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
865 not contextLines[cti].strip().startswith(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
866 ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
867 cti += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
868 if cti == len(contextLines):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
869 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
870
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
871 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
872 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
873
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
874 def __checkBlankBeforeAndAfterClass(self, docstringContext, context):
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 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
877 blank line around them.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
878
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
879 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
880 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
881 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
882 if docstringContext is None:
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 contextLines = context.source()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
886 cti = 0
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
887 while cti < len(contextLines) and \
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
888 not contextLines[cti].strip().startswith(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
889 ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
890 cti += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
891 if cti == len(contextLines):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
892 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
893
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
894 start = cti
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
895 if contextLines[cti].strip() in (
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
896 '"""', 'r"""', 'u"""', "'''", "r'''", "u'''"):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
897 # 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
898 cti += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
899
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
900 while cti < len(contextLines) and \
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
901 not contextLines[cti].strip().endswith(('"""', "'''")):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
902 cti += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
903 end = cti
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
904 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
905 return
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
906
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
907 if contextLines[start - 1].strip():
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
908 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
909 if contextLines[end + 1].strip():
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
910 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
911
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
912 def __checkBlankAfterSummary(self, docstringContext, context):
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 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
915 by a blank line.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
916
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
917 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
918 @param context context of the docstring (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
919 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
920 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
921 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
922
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
923 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
924 if len(docstrings) <= 3:
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
925 # correct/invalid one-liner
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
926 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
927
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
928 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
929 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
930 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
931 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
932
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
933 def __checkBlankAfterLastParagraph(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
934 """
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
935 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
936 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
937
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
938 @param docstringContext docstring context (Pep257Context)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
939 @param context context of the docstring (Pep257Context)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
940 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
941 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
942 return
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 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
945 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
946 # 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
947 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
948
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
949 if 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
950 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
951
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
952 ##################################################################
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
953 ## 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
954 ##################################################################
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
955
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
956 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
957 """
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
958 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
959 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
960
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
961 @param docstringContext docstring context (Pep257Context)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
962 @param context context of the docstring (Pep257Context)
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 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
965 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
966
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
967 lines = docstringContext.source()
2948
ea04689ee599 Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2946
diff changeset
968 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
969 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
970 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
971 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
972
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
973 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
974 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
975 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
976
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
977 @param docstringContext docstring context (Pep257Context)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
978 @param context context of the docstring (Pep257Context)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
979 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
980 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
981 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
982
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
983 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
984 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
985 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
986 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
987 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
988 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
989 self.__error(
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
990 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
991 0, "D231")
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
992
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
993 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
994 """
2949
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
995 Private method to check, that docstrings contain an &#64;return line
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
996 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
997
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
998 @param docstringContext docstring context (Pep257Context)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
999 @param context context of the docstring (Pep257Context)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1000 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1001 if docstringContext is None or self.__isScript:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1002 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1003
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
1004 tokens = list(
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
1005 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
1006 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
1007 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
1008 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
1009 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
1010 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
1011 set([])):
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1012 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
1013 else:
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
1014 if (set(return_) -
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
1015 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
1016 set([])):
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
1017 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
1018
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1019 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
1020 """
2949
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1021 Private method to check, that docstrings contain an &#64;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
1022 &#64;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
1023
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1024 @param docstringContext docstring context (Pep257Context)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1025 @param context context of the docstring (Pep257Context)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1026 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1027 if docstringContext is None or self.__isScript:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1028 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1029
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1030 try:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1031 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
1032 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
1033 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1034 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
1035 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
1036 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
1037 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
1038 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
1039 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
1040 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
1041 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
1042
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1043 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
1044 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
1045 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
1046 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
1047 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
1048 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
1049 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
1050 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1051 # 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
1052 args = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1053 kwargs = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1054 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
1055 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
1056 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
1057 if at == "@keyparam":
2952
94fc661a54a2 Fixed an issue parsing the eric style doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2949
diff changeset
1058 kwargs.append(name.lstrip("*"))
94fc661a54a2 Fixed an issue parsing the eric style doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2949
diff changeset
1059 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
1060
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1061 # 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
1062 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
1063 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
1064 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
1065 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1066 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
1067 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
1068
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 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
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 Private method to check, that docstrings contain an &#64;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
1072 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
1073
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1074 @param docstringContext docstring context (Pep257Context)
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1075 @param context context of the docstring (Pep257Context)
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1076 """
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1077 if docstringContext is None or self.__isScript:
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1078 return
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1079
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1080 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
1081 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
1082 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
1083 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
1084 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
1085 "@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
1086 "@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
1087 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
1088 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
1089 set([])):
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1090 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
1091 else:
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1092 if (set(exception) -