eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py

Wed, 17 Jun 2020 20:18:54 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 17 Jun 2020 20:18:54 +0200
changeset 7628
f904d0eef264
parent 7610
df7025fe26a3
child 7637
c878e8255972
permissions
-rw-r--r--

Checked the reported security related issue reports generated by the new security 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
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7256
diff changeset
3 # Copyright (c) 2013 - 2020 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
4465
2fbb5bdb8ddf Prepared eric for Python 3.5 to support the new 'async def' function definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
25 try:
2fbb5bdb8ddf Prepared eric for Python 3.5 to support the new 'async def' function definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
26 ast.AsyncFunctionDef # __IGNORE_EXCEPTION__
2fbb5bdb8ddf Prepared eric for Python 3.5 to support the new 'async def' function definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
27 except AttributeError:
2fbb5bdb8ddf Prepared eric for Python 3.5 to support the new 'async def' function definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
28 ast.AsyncFunctionDef = ast.FunctionDef
2fbb5bdb8ddf Prepared eric for Python 3.5 to support the new 'async def' function definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
29
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30
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
31 class DocStyleContext(object):
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 Class implementing the source context.
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 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
36 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 Constructor
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @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
40 @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
41 @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
42 """
4547
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
43 if sys.version_info[0] == 2:
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
44 stringTypes = (str, unicode) # __IGNORE_WARNING__
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
45 else:
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
46 stringTypes = str
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
47 if isinstance(source, stringTypes):
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__source = source.splitlines(True)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 else:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.__source = source[:]
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.__start = startLine
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.__indent = ""
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.__type = contextType
5812
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
54 self.__special = ""
2915
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 # 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
57 if self.__source:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 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
59 self.__source[0].lstrip(), "")
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 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
61
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 def source(self):
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 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
65
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 @return source (list of string)
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 return self.__source
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 def ssource(self):
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 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
73
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 @return source (string)
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 return "".join(self.__source)
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 def start(self):
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 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
81
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @return start line number (integer)
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 return self.__start
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 def end(self):
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 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
89
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 @return end line number (integer)
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 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
93
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 def indent(self):
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 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
97
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 @return indentation string (string)
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 return self.__indent
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 def contextType(self):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 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
105
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 @return context type (string)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 return self.__type
5812
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
109
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
110 def setSpecial(self, special):
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
111 """
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
112 Public method to set a special attribute for the context.
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
113
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
114 @param special attribute string
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
115 @type str
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
116 """
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
117 self.__special = special
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
118
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
119 def special(self):
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
120 """
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
121 Public method to get the special context attribute string.
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
122
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
123 @return attribute string
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
124 @rtype str
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
125 """
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
126 return self.__special
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
2971
efd4a4343019 Started to change the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2968
diff changeset
129 class DocStyleChecker(object):
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
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
131 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
132 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 Codes = [
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 "D101", "D102", "D103", "D104", "D105",
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 "D111", "D112", "D113",
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 "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
137 "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
138 "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
139
6051
6e09a9a73cb7 Added a documentation style check for a template class documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
140 "D203", "D205", "D206",
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2935
diff changeset
141 "D221", "D222",
3582
49f9c3695ef5 Extended the doc style checker by another eric style check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3539
diff changeset
142 "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
143 "D242", "D243", "D244", "D245", "D246", "D247",
5732
34041e56ec42 Extended the source documentation checker to check for raised/documented exceptions and defined/documented signals.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5588
diff changeset
144 "D250", "D251", "D252", "D253",
34041e56ec42 Extended the source documentation checker to check for raised/documented exceptions and defined/documented signals.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5588
diff changeset
145 "D260", "D261", "D262", "D263",
3083
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
146
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
147 "D901",
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 ]
3083
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
149
2916
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
150 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
151 maxLineLength=79, docType="pep257"):
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 """
2928
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
153 Constructor
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 @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
156 @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
157 @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
158 @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
159 @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
160 @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
161 (boolean)
2928
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
162 @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
163 @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
164 (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
165 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.__select = tuple(select)
3622
7a9a8fb4b8c6 If messages explicitly selected ignore all other messages.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3590
diff changeset
167 self.__ignore = ('',) if select else tuple(ignore)
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 self.__expected = expected[:]
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 self.__repeat = repeat
2916
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
170 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
171 self.__docType = docType
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 self.__filename = filename
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 self.__source = source[:]
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 # statistics counters
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 self.counters = {}
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 # collection of detected errors
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 self.errors = []
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 self.__lineNumber = 0
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 # caches
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 self.__functionsCache = None
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 self.__classesCache = None
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 self.__methodsCache = None
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 self.__keywords = [
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 'moduleDocstring', 'functionDocstring',
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 'classDocstring', 'methodDocstring',
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 'defDocstring', 'docstring'
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 ]
2928
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
193 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
194 checkersWithCodes = {
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
195 "moduleDocstring": [
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
196 (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
197 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
198 "functionDocstring": [
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
199 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
200 "classDocstring": [
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
201 (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
202 (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
203 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
204 "methodDocstring": [
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
205 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
206 "defDocstring": [
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
207 (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
208 (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
209 (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
210 (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
211 (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
212 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
213 "docstring": [
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
214 (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
215 (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
216 (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
217 (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
218 (self.__checkIndent, ("D122",)),
4505
3b437ae320bd Fixed an issue in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
219 (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
220 (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
221 (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
222 (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
223 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
224 }
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
225 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
226 checkersWithCodes = {
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
227 "moduleDocstring": [
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
228 (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
229 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
230 "functionDocstring": [
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
231 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
232 "classDocstring": [
6051
6e09a9a73cb7 Added a documentation style check for a template class documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
233 (self.__checkClassDocstring, ("D104", "D205", "D206")),
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
234 (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
235 ("D242", "D243")),
5732
34041e56ec42 Extended the source documentation checker to check for raised/documented exceptions and defined/documented signals.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5588
diff changeset
236 (self.__checkEricSignal, ("D260", "D261", "D262", "D263")),
2928
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
237 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
238 "methodDocstring": [
3582
49f9c3695ef5 Extended the doc style checker by another eric style check.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3539
diff changeset
239 (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
240 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
241 "defDocstring": [
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
242 (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
243 (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
244 (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
245 (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
246 (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
247 ("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
248 (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
249 ("D244", "D245")),
5732
34041e56ec42 Extended the source documentation checker to check for raised/documented exceptions and defined/documented signals.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5588
diff changeset
250 (self.__checkEricException,
34041e56ec42 Extended the source documentation checker to check for raised/documented exceptions and defined/documented signals.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5588
diff changeset
251 ("D250", "D251", "D252", "D253")),
2928
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
252 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
253 "docstring": [
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
254 (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
255 (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
256 (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
257 (self.__checkIndent, ("D122",)),
4505
3b437ae320bd Fixed an issue in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4465
diff changeset
258 (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
259 (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
260 (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
261 (self.__checkEricNBlankAfterLastParagraph, ("D247",)),
2937
de26bc76d6ee Finished implementing fixer method for eric style docstring issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2935
diff changeset
262 (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
263 ],
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
264 }
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 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
267 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
268 for checker, codes in checkers:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 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
270 for code in codes):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 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
272 self.__checkers[key] = []
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 self.__checkers[key].append(checker)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 def __ignoreCode(self, code):
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 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
278
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 @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
280 @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
281 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 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
283 not code.startswith(self.__select))
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 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
286 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 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
288
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 @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
290 @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
291 @param code message code (string)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 @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
293 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 if self.__ignoreCode(code):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 if code in self.counters:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 self.counters[code] += 1
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 else:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 self.counters[code] = 1
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 # 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
303 if code in self.__expected:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 return
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 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
307 # 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
308 self.errors.append(
7610
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
309 {
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
310 "file": self.__filename,
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
311 "line": lineNumber + 1,
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
312 "offset": offset,
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
313 "code": code,
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
314 "args": args,
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
315 }
df7025fe26a3 Code Style Checker: reworked the API between frontend and backend to get some more flexibility for the future.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
316 )
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317
3083
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
318 def __reportInvalidSyntax(self):
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
319 """
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
320 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
321 """
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
322 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
323 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
324 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
325 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
326 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
327 else:
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
328 offset = (1, 0)
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
329 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
330 '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
331
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 def __resetReadline(self):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 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
335 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 self.__lineNumber = 0
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 def __readline(self):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 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
341
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 @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
343 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 self.__lineNumber += 1
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 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
346 return ''
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 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
348
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 def run(self):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 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
352 conventions.
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 """
3822
1faf52d8f2bd Changed doc style checker to perform checks on empty files as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3622
diff changeset
354 if not self.__filename:
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 # 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
356 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357
2967
f9acd647f881 Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2961
diff changeset
358 if not self.__checkers:
f9acd647f881 Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2961
diff changeset
359 # 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
360 return
f9acd647f881 Some little optimization in the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2961
diff changeset
361
4547
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
362 source = "".join(self.__source)
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
363 # Check type for py2: if not str it's unicode
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
364 if sys.version_info[0] == 2:
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
365 try:
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
366 source = source.encode('utf-8')
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
367 except UnicodeError:
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
368 pass
3083
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
369 try:
4547
7e0cb381dcbc Fixed an issue in the documentation style checker related to Python2 source files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4543
diff changeset
370 compile(source, self.__filename, '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
371 except (SyntaxError, TypeError):
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
372 self.__reportInvalidSyntax()
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
373 return
6382a74d9599 Guarded the doc style checker against files with invalid syntax.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3036
diff changeset
374
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 for keyword in self.__keywords:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 if keyword in self.__checkers:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 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
378 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
379 docstring = self.__parseDocstring(context, keyword)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 check(docstring, context)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 def __getSummaryLine(self, docstringContext):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 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
385
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
386 @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
387 @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
388 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 lines = docstringContext.source()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 line = (lines[0]
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 .replace('r"""', "", 1)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 .replace('u"""', "", 1)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 .replace('"""', "")
2916
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
395 .replace("r'''", "", 1)
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
396 .replace("u'''", "", 1)
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
397 .replace("'''", "")
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 .strip())
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 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
401 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
402 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
403
2928
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
404 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
405 """
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
406 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
407
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
408 @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
409 @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
410 (integer)
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
411 """
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
412 summaries = []
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
413 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
414
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
415 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
416 .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
417 .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
418 .replace('"""', "")
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
419 .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
420 .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
421 .replace("'''", "")
e8f41288a688 Added a check for the @exception line of the eric doc strings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2948
diff changeset
422 .strip())
2928
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
423 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
424 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
425 else:
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
426 line1 = ""
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
427 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
428 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
429 else:
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
430 line2 = ""
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
431 if line0:
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
432 lineno = 0
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
433 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
434 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
435 # 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
436 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
437 elif line1:
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
438 lineno = 1
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
439 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
440 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
441 # 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
442 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
443 else:
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
444 lineno = 2
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
445 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
446 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
447
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
448 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
449 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
450 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
451 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
452
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
453 @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
454 @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
455 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
456 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
457 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
458 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
459 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
460
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
461 @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
462 @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
463 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
464 ret = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
465 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
466 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
467 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
468 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
469 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
470 return ret
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
471
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
472 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
473 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
474 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
475 kwarguments = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
476 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
477 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
478 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
479 else:
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
480 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
481 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
482 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
483
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
484 @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
485 @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
486 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
487 """
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
488 arguments = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
489 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
490 if node.args.vararg is not None:
7243
cfeea029d8e1 DocStyleChecker: fixed some bad use of sys.version_info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
491 if sys.version_info < (3, 4, 0):
3938
d2b103d42907 Fixed an issue in the doc style checker related to a slightly changed AST in Python 3.4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3822
diff changeset
492 arguments.append(node.args.vararg)
d2b103d42907 Fixed an issue in the doc style checker related to a slightly changed AST in Python 3.4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3822
diff changeset
493 else:
d2b103d42907 Fixed an issue in the doc style checker related to a slightly changed AST in Python 3.4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3822
diff changeset
494 arguments.append(node.args.vararg.arg)
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
495
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
496 kwarguments = []
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
497 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
498 if node.args.kwarg is not None:
7243
cfeea029d8e1 DocStyleChecker: fixed some bad use of sys.version_info.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
499 if sys.version_info < (3, 4, 0):
3938
d2b103d42907 Fixed an issue in the doc style checker related to a slightly changed AST in Python 3.4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3822
diff changeset
500 kwarguments.append(node.args.kwarg)
d2b103d42907 Fixed an issue in the doc style checker related to a slightly changed AST in Python 3.4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3822
diff changeset
501 else:
d2b103d42907 Fixed an issue in the doc style checker related to a slightly changed AST in Python 3.4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3822
diff changeset
502 kwarguments.append(node.args.kwarg.arg)
2929
28ab0bc63d69 Finished enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2928
diff changeset
503 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
504
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505 ##################################################################
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 ## Parsing functionality below
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507 ##################################################################
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 def __parseModuleDocstring(self, source):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
511 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
512
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
513 @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
514 @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
515 """
6188
5a6ae3be31e6 Fixed some loop related coding issues detected by the extended code style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6170
diff changeset
516 for kind, value, (line, _char), _, _ in tokenize.generate_tokens(
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
517 StringIO("".join(source)).readline):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
518 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
519 continue
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 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
521 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
522 else:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
523 return None
6891
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
524
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
525 return None
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527 def __parseDocstring(self, context, what=''):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
528 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
529 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
530
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
531 @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
532 @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
533 @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
534 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 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
536 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
537 return moduleDocstring
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
538 if moduleDocstring:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
539 return moduleDocstring
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
540
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541 tokenGenerator = tokenize.generate_tokens(
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
542 StringIO(context.ssource()).readline)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
543 try:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
544 kind = None
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
545 while kind != tokenize.INDENT:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
546 kind, _, _, _, _ = next(tokenGenerator)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547 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
548 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
549 return DocStyleContext(
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
550 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
551 except StopIteration:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
552 pass
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 return None
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 def __parseTopLevel(self, keyword):
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 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
559
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
560 @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
561 @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
562 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
563 self.__resetReadline()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
564 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
565 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
566 contexts = []
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567 try:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
568 while True:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
569 start, end = None, None
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
570 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
571 value == keyword and
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
572 char == 0):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
573 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
574 start = line - 1, char
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
575 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
576 value == '' and
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
577 char == 0):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
578 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
579 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
580 contexts.append(DocStyleContext(
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
581 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
582 except StopIteration:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
583 return contexts
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
584
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
585 def __parseFunctions(self):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
586 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
587 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
588
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
589 @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
590 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
591 if not self.__functionsCache:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
592 self.__functionsCache = self.__parseTopLevel('def')
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
593 return self.__functionsCache
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
594
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
595 def __parseClasses(self):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
596 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
597 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
598
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
599 @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
600 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
601 if not self.__classesCache:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
602 self.__classesCache = self.__parseTopLevel('class')
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
603 return self.__classesCache
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
604
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
605 def __skipIndentedBlock(self, tokenGenerator):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
606 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
607 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
608
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
609 @param tokenGenerator token generator
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
610 @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
611 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
612 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
613 while kind != tokenize.INDENT:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
614 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
615 indent = 1
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
616 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
617 if kind == tokenize.INDENT:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
618 indent += 1
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
619 elif kind == tokenize.DEDENT:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
620 indent -= 1
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
621 if indent == 0:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
622 return kind, value, start, end, raw
6891
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
623
93f82da09f22 Fixed some code style issues detected by the new 'return' checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
624 return None
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
625
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
626 def __parseMethods(self):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
627 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
628 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
629
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
630 @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
631 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
632 if not self.__methodsCache:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
633 contexts = []
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
634 for classContext in self.__parseClasses():
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
635 tokenGenerator = tokenize.generate_tokens(
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
636 StringIO(classContext.ssource()).readline)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
637 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
638 try:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
639 while True:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
640 start, end = None, None
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
641 while not (kind == tokenize.NAME and value == 'def'):
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
642 kind, value, (line, char), _, _ = (
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
643 next(tokenGenerator)
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
644 )
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
645 start = line - 1, char
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
646 kind, value, (line, char), _, _ = (
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
647 self.__skipIndentedBlock(tokenGenerator)
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
648 )
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
649 end = line - 1, char
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
650 startLine = classContext.start() + start[0]
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
651 endLine = classContext.start() + end[0]
5812
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
652 context = DocStyleContext(
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3004
diff changeset
653 self.__source[startLine:endLine],
5812
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
654 startLine, "def")
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
655 if startLine > 0:
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
656 if (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
657 self.__source[startLine - 1].strip() ==
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
658 "@staticmethod"
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
659 ):
5812
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
660 context.setSpecial("staticmethod")
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
661 elif (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
662 self.__source[startLine - 1].strip() ==
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
663 "@classmethod"
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
664 ):
5812
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
665 context.setSpecial("classmethod")
ffc31e1cff4e Extended the documentation style checker to check for @classmethod and @staticmethod.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5732
diff changeset
666 contexts.append(context)
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
667 except StopIteration:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
668 pass
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
669 self.__methodsCache = contexts
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 return self.__methodsCache
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
672
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
673 def __parseContexts(self, kind):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
674 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
675 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
676
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
677 @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
678 @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
679 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
680 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
681 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
682 if kind == 'functionDocstring':
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
683 return self.__parseFunctions()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
684 if kind == 'classDocstring':
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
685 return self.__parseClasses()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
686 if kind == 'methodDocstring':
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
687 return self.__parseMethods()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
688 if kind == 'defDocstring':
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
689 return self.__parseFunctions() + self.__parseMethods()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
690 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
691 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
692 self.__parseFunctions() +
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
693 self.__parseClasses() +
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
694 self.__parseMethods())
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
695 return [] # fall back
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 ##################################################################
2928
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
698 ## 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
699 ##################################################################
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
700
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
701 def __checkModulesDocstrings(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
702 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
703 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
704
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
705 @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
706 @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
707 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
708 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
709 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
710 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
711
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
712 docstring = docstringContext.ssource()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
713 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
714 not docstring.strip('\'"')):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
715 self.__error(context.start(), 0, "D101")
6170
2bcf6e5637e7 Code Style Checker: added checks for default docstring in functions and modules
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6051
diff changeset
716
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
717 if (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
718 self.__docType == "eric" and
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
719 docstring.strip('\'"').strip() ==
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
720 "Module documentation goes here."
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
721 ):
6170
2bcf6e5637e7 Code Style Checker: added checks for default docstring in functions and modules
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6051
diff changeset
722 self.__error(docstringContext.end(), 0, "D201")
2bcf6e5637e7 Code Style Checker: added checks for default docstring in functions and modules
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6051
diff changeset
723 return
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 def __checkFunctionDocstring(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
726 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
727 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
728 have a docstring.
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
729
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
730 @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
731 @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
732 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
733 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
734 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
735 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
736 code = "D203"
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
737 else:
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
738 code = "D103"
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
739 else:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
740 code = "D102"
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
741
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
742 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
743 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
744 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
745
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
746 docstring = docstringContext.ssource()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
747 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
748 not docstring.strip('\'"')):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
749 self.__error(context.start(), 0, code)
6170
2bcf6e5637e7 Code Style Checker: added checks for default docstring in functions and modules
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6051
diff changeset
750
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
751 if (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
752 self.__docType == "eric" and
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
753 docstring.strip('\'"').strip() ==
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
754 "Function documentation goes here."
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
755 ):
6170
2bcf6e5637e7 Code Style Checker: added checks for default docstring in functions and modules
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6051
diff changeset
756 self.__error(docstringContext.end(), 0, "D202")
2bcf6e5637e7 Code Style Checker: added checks for default docstring in functions and modules
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6051
diff changeset
757 return
2915
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 def __checkClassDocstring(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
760 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
761 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
762 have a docstring.
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
763
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
764 @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
765 @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
766 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
767 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
768 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
769 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
770 code = "D205"
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
771 else:
4f74d3f595ce Started enhancing the docstring checker to include the eric docstring style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2925
diff changeset
772 code = "D105"
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
773 else:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
774 code = "D104"
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
775
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
776 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
777 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
778 return
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 docstring = docstringContext.ssource()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
781 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
782 not docstring.strip('\'"')):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
783 self.__error(context.start(), 0, code)
6051
6e09a9a73cb7 Added a documentation style check for a template class documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
784 return
6e09a9a73cb7 Added a documentation style check for a template class documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
785
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
786 if (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
787 self.__docType == "eric" and
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
788 docstring.strip('\'"').strip() == "Class documentation goes here."
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
789 ):
6170
2bcf6e5637e7 Code Style Checker: added checks for default docstring in functions and modules
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6051
diff changeset
790 self.__error(docstringContext.end(), 0, "D206")
6051
6e09a9a73cb7 Added a documentation style check for a template class documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
791 return
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
792
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
793 def __checkTripleDoubleQuotes(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
794 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
795 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
796 by triple double quotes.
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
797
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
798 @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
799 @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
800 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
801 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
802 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
803
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
804 docstring = docstringContext.ssource().strip()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
805 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
806 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
807
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
808 def __checkBackslashes(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
809 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
810 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
811 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
812
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
813 @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
814 @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
815 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
816 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
817 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
818
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
819 docstring = docstringContext.ssource().strip()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
820 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
821 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
822
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
823 def __checkUnicode(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
824 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
825 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
826 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
827
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
828 @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
829 @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
830 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
831 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
832 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
833
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
834 docstring = docstringContext.ssource().strip()
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
835 if (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
836 not docstring.startswith('u"""') and
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
837 any(ord(char) > 127 for char in docstring)
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
838 ):
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
839 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
840
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
841 def __checkOneLiner(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
842 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
843 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
844 one line with quotes.
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
845
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
846 @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
847 @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
848 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
849 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
850 return
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 lines = docstringContext.source()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
853 if len(lines) > 1:
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7610
diff changeset
854 nonEmptyLines = [line for line in lines
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7610
diff changeset
855 if line.strip().strip('\'"')]
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
856 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
857 modLen = len(context.indent() + '"""' +
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
858 nonEmptyLines[0].strip() + '"""')
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
859 if context.contextType() != "module":
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
860 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
861 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
862 # 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
863 modLen += 1
2916
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
864 if modLen <= self.__maxLineLength:
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
865 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
866
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
867 def __checkIndent(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
868 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
869 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
870
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
871 @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
872 @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
873 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
874 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
875 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
876
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
877 lines = docstringContext.source()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
878 if len(lines) == 1:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
879 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
880
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7610
diff changeset
881 nonEmptyLines = [line.rstrip() for line in lines[1:] if line.strip()]
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
882 if not nonEmptyLines:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
883 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
884
7628
f904d0eef264 Checked the reported security related issue reports generated by the new security checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7610
diff changeset
885 indent = min(len(line) - len(line.strip()) for line in nonEmptyLines)
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
886 if context.contextType() == "module":
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
887 expectedIndent = 0
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
888 else:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
889 expectedIndent = len(context.indent()) + 4
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
890 if indent != expectedIndent:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
891 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
892
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
893 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
894 """
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
895 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
896
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
897 @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
898 @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
899 """
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
900 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
901 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
902
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
903 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
904 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
905 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
906
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
907 def __checkEndsWithPeriod(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
908 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
909 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
910
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
911 @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
912 @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
913 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
914 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
915 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
916
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
917 summary, lineNumber = self.__getSummaryLine(docstringContext)
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
918 if not summary.endswith("."):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
919 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
920
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
921 def __checkImperativeMood(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
922 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
923 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
924 imperative mood.
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
925
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
926 @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
927 @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
928 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
929 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
930 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
931
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
932 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
933 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
934 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
935 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
936 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
937
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
938 def __checkNoSignature(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
939 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
940 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
941 the function's signature.
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
942
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
943 @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
944 @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
945 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
946 if docstringContext is None:
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
947 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
948
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
949 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
950 summary, lineNumber = self.__getSummaryLine(docstringContext)
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
951 if (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
952 functionName + "(" in summary.replace(" ", "") and
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
953 not functionName + "()" in summary.replace(" ", "")
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
954 ):
2948
ea04689ee599 Some more tweaks to the doc style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2945
diff changeset
955 # 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
956 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
957
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
958 def __checkReturnType(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
959 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
960 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
961
2971
efd4a4343019 Started to change the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2968
diff changeset
962 @param docstringContext docstring context (DocStyleContext)
efd4a4343019 Started to change the names of the various code style checkers to make them more appropriate to the broadened scope.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2968
diff changeset
963 @param context context of the docstring (DocStyleContext)
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
964 """
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
965 if docstringContext is None:
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
966 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
967
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
968 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
969 tokens = list(
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
970 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
971 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
972 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
973 if (set(return_) -
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
974 {tokenize.COMMENT, tokenize.NL, tokenize.NEWLINE} !=
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
975 set()):
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
976 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
977
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
978 def __checkNoBlankLineBefore(self, docstringContext, context):
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
979 """
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
980 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
981 preceded by a blank line.
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
982
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
983 @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
984 @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
985 """
2916
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
986 if docstringContext is None:
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
987 return
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
988
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
989 contextLines = context.source()
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
990 cti = 0
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
991 while (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
992 cti < len(contextLines) and
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
993 not contextLines[cti].strip().startswith(
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
994 ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''"))
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
995 ):
2916
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
996 cti += 1
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
997 if cti == len(contextLines):
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
998 return
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
999
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
1000 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
1001 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
1002
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
1003 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
1004 """
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
1005 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
1006 blank line around them.
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
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)
2916
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
1010 """
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
1011 if docstringContext is None:
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1012 return
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1013
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1014 contextLines = context.source()
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1015 cti = 0
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
1016 while (
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
1017 cti < len(contextLines) and
2916
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
1018 not contextLines[cti].strip().startswith(
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
1019 ('"""', 'r"""', 'u"""', "'''", "r'''", "u'''"))
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7243
diff changeset
1020 ):
2915
9da653363d07 Started implementing a checker for PEP-257 docstring conventions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1021 cti += 1
2916
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
1022 if cti == len(contextLines):
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
1023 return
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
1024
a8628dfdfe04 Finished the Python3 variant of the PEP-257 checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2915
diff changeset
1025 start = cti