UtilitiesPython2/Pep257CheckerPy2.py

Sun, 29 Sep 2013 14:22:08 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 29 Sep 2013 14:22:08 +0200
changeset 2961
e4e2efb4846a
parent 2952
94fc661a54a2
child 2967
f9acd647f881
permissions
-rw-r--r--

Change to the doc style checker to treat yield like return for the eric doc style.

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
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 for keyword in self.__keywords:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 if keyword in self.__checkers:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 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
307 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
308 docstring = self.__parseDocstring(context, keyword)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 check(docstring, context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 def __getSummaryLine(self, docstringContext):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 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
314
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 @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
317 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 lines = docstringContext.source()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 line = (lines[0]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 .replace('r"""', "", 1)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 .replace('u"""', "", 1)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 .replace('"""', "")
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 .replace("r'''", "", 1)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 .replace("u'''", "", 1)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 .replace("'''", "")
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 .strip())
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 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
330 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
331 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
332
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
333 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
334 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
335 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
336
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
337 @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
338 @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
339 (integer)
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 summaries = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
342 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
343
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
344 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
345 .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
346 .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
347 .replace('"""', "")
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
348 .replace("r'''", "", 1)
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
349 .replace("u'''", "", 1)
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
350 .replace("'''", "")
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
351 .strip())
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
352 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
353 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
354 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
355 line1 = ""
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) > 2:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
357 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
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 line2 = ""
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
360 if line0:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
361 lineno = 0
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
362 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
363 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
364 # 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
365 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
366 elif line1:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
367 lineno = 1
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
368 summaries.append(line1)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
369 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
370 # 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
371 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
372 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
373 lineno = 2
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
374 summaries.append(line2)
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
375 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
376
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
377 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
378 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
379 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
380 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
381
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
382 @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
383 @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
384 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
385 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
386 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
387 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
388 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
389
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
390 @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
391 @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
392 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
393 ret = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
394 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
395 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
396 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
397 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
398 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
399 return ret
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
400
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
401 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
402 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
403 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
404 kwarguments = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
405 if node.args.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
406 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
407 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
408 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
409 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
410 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
411 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
412
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
413 @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
414 @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
415 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
416 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
417 arguments = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
418 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
419 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
420 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
421
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
422 kwarguments = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
423 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
424 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
425 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
426 return arguments, kwarguments
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 ##################################################################
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 ## Parsing functionality below
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 ##################################################################
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 def __parseModuleDocstring(self, source):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 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
435
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 @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
437 @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
438 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439 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
440 StringIO("".join(source)).readline):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 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
442 continue
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 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
444 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
445 else:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 return None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 def __parseDocstring(self, context, what=''):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 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
451
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 @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
453 @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
454 @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
455 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 moduleDocstring = self.__parseModuleDocstring(context.source())
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
457 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
458 return moduleDocstring
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 if moduleDocstring:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 return moduleDocstring
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
462 tokenGenerator = tokenize.generate_tokens(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
463 StringIO(context.ssource()).readline)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 try:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 kind = None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 while kind != tokenize.INDENT:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 kind, _, _, _, _ = next(tokenGenerator)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 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
469 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
470 return Pep257Context(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 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
472 except StopIteration:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
473 pass
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 return None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
476
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 def __parseTopLevel(self, keyword):
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 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
480
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
481 @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
482 @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
483 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
484 self.__resetReadline()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 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
486 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
487 contexts = []
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
488 try:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
489 while True:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
490 start, end = None, None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
491 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
492 value == keyword and
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 char == 0):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 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
495 start = line - 1, char
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496 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
497 value == '' and
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 char == 0):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499 kind, value, (line, char), _, _ = next(tokenGenerator)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500 end = line - 1, char
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
501 contexts.append(Pep257Context(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502 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
503 except StopIteration:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
504 return contexts
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 def __parseFunctions(self):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 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
509
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 @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
511 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
512 if not self.__functionsCache:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
513 self.__functionsCache = self.__parseTopLevel('def')
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 return self.__functionsCache
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 def __parseClasses(self):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
518 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
519
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 @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
521 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
522 if not self.__classesCache:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
523 self.__classesCache = self.__parseTopLevel('class')
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
524 return self.__classesCache
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 def __skipIndentedBlock(self, tokenGenerator):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
528 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
529
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530 @param tokenGenerator token generator
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
531 @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
532 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
533 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
534 while kind != tokenize.INDENT:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 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
536 indent = 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
537 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
538 if kind == tokenize.INDENT:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
539 indent += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
540 elif kind == tokenize.DEDENT:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541 indent -= 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
542 if indent == 0:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
543 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
544
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
545 def __parseMethods(self):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
546 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547 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
548
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
549 @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
550 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
551 if not self.__methodsCache:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
552 contexts = []
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
553 for classContext in self.__parseClasses():
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
554 tokenGenerator = tokenize.generate_tokens(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 StringIO(classContext.ssource()).readline)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556 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
557 try:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 while True:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
559 start, end = None, None
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
560 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
561 kind, value, (line, char), _, _ = \
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
562 next(tokenGenerator)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
563 start = line - 1, char
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
564 kind, value, (line, char), _, _ = \
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
565 self.__skipIndentedBlock(tokenGenerator)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
566 end = line - 1, char
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567 startLine = classContext.start() + start[0]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
568 endLine = classContext.start() + end[0]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
569 contexts.append(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
570 Pep257Context(self.__source[startLine:endLine],
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
571 startLine, "def"))
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
572 except StopIteration:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
573 pass
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
574 self.__methodsCache = contexts
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
575
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
576 return self.__methodsCache
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
577
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
578 def __parseContexts(self, kind):
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 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
581
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
582 @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
583 @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
584 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
585 if kind == 'moduleDocstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
586 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
587 if kind == 'functionDocstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
588 return self.__parseFunctions()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
589 if kind == 'classDocstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
590 return self.__parseClasses()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
591 if kind == 'methodDocstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
592 return self.__parseMethods()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
593 if kind == 'defDocstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
594 return self.__parseFunctions() + self.__parseMethods()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
595 if kind == 'docstring':
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
596 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
597 self.__parseFunctions() +
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
598 self.__parseClasses() +
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
599 self.__parseMethods())
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
600 return [] # fall back
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
601
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
602 ##################################################################
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
603 ## 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
604 ##################################################################
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 def __checkModulesDocstrings(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
607 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
608 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
609
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
610 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
611 @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
612 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
613 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
614 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
615 return
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 docstring = docstringContext.ssource()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
618 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
619 not docstring.strip('\'"')):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
620 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
621
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
622 def __checkFunctionDocstring(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
623 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
624 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
625 have a docstring.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
626
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
627 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
628 @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
629 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
630 if self.__isScript:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
631 # assume nothing is exported
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
632 return
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 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
635 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
636 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
637 code = "D203"
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
638 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
639 code = "D103"
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
640 else:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
641 code = "D102"
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
642
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
643 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
644 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
645 return
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 docstring = docstringContext.ssource()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
648 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
649 not docstring.strip('\'"')):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
650 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
651
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
652 def __checkClassDocstring(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
653 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
654 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
655 have a docstring.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
656
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
657 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
658 @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
659 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
660 if self.__isScript:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
661 # assume nothing is exported
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
662 return
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 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
665 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
666 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
667 code = "D205"
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
668 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
669 code = "D105"
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
670 else:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
671 code = "D104"
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
672
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
673 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
674 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
675 return
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 docstring = docstringContext.ssource()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
678 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
679 not docstring.strip('\'"')):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
680 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
681
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
682 def __checkTripleDoubleQuotes(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
683 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
684 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
685 by triple double quotes.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
686
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
687 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
688 @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
689 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
690 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
691 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
692
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
693 docstring = docstringContext.ssource().strip()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
694 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
695 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
696
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
697 def __checkBackslashes(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
698 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
699 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
700 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
701
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
702 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
703 @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
704 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
705 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
706 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
707
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
708 docstring = docstringContext.ssource().strip()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
709 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
710 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
711
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
712 def __checkUnicode(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
713 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
714 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
715 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
716
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
717 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
718 @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
719 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
720 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
721 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
722
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
723 docstring = docstringContext.ssource().strip()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
724 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
725 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
726 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
727
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
728 def __checkOneLiner(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
729 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
730 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
731 one line with quotes.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
732
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
733 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
734 @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
735 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
736 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
737 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
738
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
739 lines = docstringContext.source()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
740 if len(lines) > 1:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
741 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
742 if len(nonEmptyLines) == 1:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
743 modLen = len(context.indent() + '"""' +
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
744 nonEmptyLines[0].strip() + '"""')
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
745 if context.contextType() != "module":
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
746 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
747 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
748 # 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
749 modLen += 1
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
750 if modLen <= self.__maxLineLength:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
751 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
752
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
753 def __checkIndent(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
754 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
755 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
756
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
757 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
758 @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
759 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
760 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
761 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
762
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
763 lines = docstringContext.source()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
764 if len(lines) == 1:
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 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
768 if not nonEmptyLines:
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 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
772 if context.contextType() == "module":
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
773 expectedIndent = 0
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
774 else:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
775 expectedIndent = len(context.indent()) + 4
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
776 if indent != expectedIndent:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
777 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
778
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
779 def __checkEndsWithPeriod(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
780 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
781 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
782
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
783 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
784 @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
785 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
786 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
787 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
788
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
789 summary, lineNumber = self.__getSummaryLine(docstringContext)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
790 if not summary.endswith("."):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
791 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
792
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
793 def __checkImperativeMood(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
794 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
795 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
796 imperative mood.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
797
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
798 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
799 @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
800 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
801 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
802 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
803
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
804 summary, lineNumber = self.__getSummaryLine(docstringContext)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
805 firstWord = summary.strip().split()[0]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
806 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
807 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
808
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
809 def __checkNoSignature(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
810 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
811 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
812 the function's signature.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
813
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
814 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
815 @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
816 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
817 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
818 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
819
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
820 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
821 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
822 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
823 not functionName + "()" in summary.replace(" ", ""):
ea04689ee599 Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2946
diff changeset
824 # 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
825 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
826
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
827 def __checkReturnType(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
828 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
829 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
830
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
831 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
832 @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
833 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
834 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
835 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
836
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
837 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
838 tokens = list(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
839 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
840 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
841 if token[1] == "return"]
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
842 if (set(return_) -
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
843 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
844 set([])):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
845 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
846
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
847 def __checkNoBlankLineBefore(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
848 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
849 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
850 preceded by a blank line.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
851
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
852 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
853 @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
854 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
855 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
856 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
857
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
858 contextLines = context.source()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
859 cti = 0
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
860 while cti < len(contextLines) and \
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
861 not contextLines[cti].strip().startswith(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
862 ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
863 cti += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
864 if cti == len(contextLines):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
865 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
866
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
867 if not contextLines[cti - 1].strip():
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
868 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
869
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
870 def __checkBlankBeforeAndAfterClass(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
871 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
872 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
873 blank line around them.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
874
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
875 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
876 @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
877 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
878 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
879 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
880
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
881 contextLines = context.source()
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
882 cti = 0
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
883 while cti < len(contextLines) and \
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
884 not contextLines[cti].strip().startswith(
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
885 ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''")):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
886 cti += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
887 if cti == len(contextLines):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
888 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
889
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
890 start = cti
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
891 if contextLines[cti].strip() in (
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
892 '"""', 'r"""', 'u"""', "'''", "r'''", "u'''"):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
893 # 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
894 cti += 1
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
895
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
896 while cti < len(contextLines) and \
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
897 not contextLines[cti].strip().endswith(('"""', "'''")):
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 end = cti
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
900 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
901 return
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
902
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
903 if contextLines[start - 1].strip():
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
904 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
905 if contextLines[end + 1].strip():
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
906 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
907
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
908 def __checkBlankAfterSummary(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
909 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
910 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
911 by a blank line.
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
912
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
913 @param docstringContext docstring context (Pep257Context)
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
914 @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
915 """
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
916 if docstringContext is None:
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
917 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
918
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
919 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
920 if len(docstrings) <= 3:
2917
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
921 # correct/invalid one-liner
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
922 return
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
923
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
924 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
925 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
926 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
927 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
928
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
929 def __checkBlankAfterLastParagraph(self, docstringContext, context):
fe82710d02cb Did the Python2 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
930 """
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
931 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
932 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
933
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
934 @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
935 @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
936 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
937 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
938 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
939
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
940 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
941 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
942 # 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
943 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
944
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
945 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
946 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
947
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 ## 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
950 ##################################################################
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
951
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
952 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
953 """
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
954 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
955 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
956
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
957 @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
958 @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
959 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
960 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
961 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
962
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
963 lines = docstringContext.source()
2948
ea04689ee599 Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2946
diff changeset
964 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
965 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
966 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
967 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
968
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
969 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
970 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
971 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
972
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
973 @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
974 @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
975 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
976 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
977 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
978
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
979 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
980 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
981 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
982 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
983 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
984 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
985 self.__error(
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
986 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
987 0, "D231")
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
988
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
989 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
990 """
2949
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
991 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
992 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
993
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
994 @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
995 @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
996 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
997 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
998 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
999
2946
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
1000 tokens = list(
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
1001 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
1002 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
1003 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
1004 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
1005 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
1006 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
1007 set([])):
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1008 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
1009 else:
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
1010 if (set(return_) -
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
1011 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
1012 set([])):
987b6368dbae Ported the doc style checker enhancements to its Python2 variant.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2934
diff changeset
1013 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
1014
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1015 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
1016 """
2949
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1017 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
1018 &#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
1019
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1020 @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
1021 @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
1022 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1023 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
1024 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1025
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1026 try:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1027 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
1028 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
1029 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1030 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
1031 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
1032 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
1033 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
1034 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
1035 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
1036 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
1037 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
1038
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1039 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
1040 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
1041 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
1042 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
1043 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
1044 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
1045 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
1046 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1047 # 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
1048 args = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1049 kwargs = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1050 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
1051 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
1052 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
1053 if at == "@keyparam":
2952
94fc661a54a2 Fixed an issue parsing the eric style doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2949
diff changeset
1054 kwargs.append(name.lstrip("*"))
94fc661a54a2 Fixed an issue parsing the eric style doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2949
diff changeset
1055 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
1056
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1057 # 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
1058 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
1059 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
1060 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
1061 return
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2917
diff changeset
1062 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
1063 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
1064
2949
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1065 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
1066 """
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1067 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
1068 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
1069
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1070 @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
1071 @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
1072 """
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1073 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
1074 return
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1075
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1076 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
1077 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
1078 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
1079 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
1080 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
1081 "@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
1082 "@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
1083 if (set(exception) -
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1084 set([tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE]) !=
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1085 set([])):
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1086 self.__error(docstringContext.end(), 0, "D250")
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1087 else:
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1088 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
1089 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
1090 set([])):
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
1091 self.__error(docstringContext.end(), 0, "D251")
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: