eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyleChecker.py

Sat, 27 Jun 2020 12:08:12 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Jun 2020 12:08:12 +0200
changeset 7639
422fd05e9c91
parent 7637
c878e8255972
permissions
-rw-r--r--

Removed some more Python2 related code.

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