eric6/Plugins/CheckerPlugins/CodeStyleChecker/DocStyle/DocStyleChecker.py

Sun, 11 Apr 2021 18:45:10 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 11 Apr 2021 18:45:10 +0200
changeset 8222
5994b80b8760
parent 8207
d359172d11be
child 8243
cc717c2ae956
permissions
-rw-r--r--

Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 1).

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