Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py

Sat, 14 Dec 2013 23:44:25 +0100

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Sat, 14 Dec 2013 23:44:25 +0100
branch
Py2 comp.
changeset 3145
a9de05d4a22f
parent 3142
55030c09e142
child 3161
06f57a834adf
child 3209
c5432abceb25
permissions
-rw-r--r--

# __IGNORE_WARNING__ added/ removed.

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