Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py

Sat, 17 May 2014 18:53:04 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 17 May 2014 18:53:04 +0200
changeset 3589
48aded8560dc
parent 3588
ce1f00c0d96d
child 3590
5280e37405b8
permissions
-rw-r--r--

Corrected an issue in the eric doc style checker.

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

eric ide

mercurial