|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' |
|
3 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> |
|
4 <html><head> |
|
5 <title>eric5.Plugins.CheckerPlugins.Tabnanny.Tabnanny</title> |
|
6 <style> |
|
7 b'body {\n background:white;\n margin: 0em 1em 10em 1em;\n color: black;\n}\n\nh1 { color: white; background: #4FA4FF; }\nh2 { color: white; background: #4FA4FF; }\nh3 { color: white; background: #00557F; }\nh4 { color: white; background: #00557F; }\n \na { color: #AA5500; }\n' |
|
8 </style> |
|
9 </head> |
|
10 <body><a NAME="top" ID="top"></a> |
|
11 <h1>eric5.Plugins.CheckerPlugins.Tabnanny.Tabnanny</h1> |
|
12 <p> |
|
13 The Tab Nanny despises ambiguous indentation. She knows no mercy. |
|
14 </p><p> |
|
15 tabnanny -- Detection of ambiguous indentation |
|
16 </p><p> |
|
17 For the time being this module is intended to be called as a script. |
|
18 However it is possible to import it into an IDE and use the function |
|
19 check() described below. |
|
20 </p><p> |
|
21 Warning: The API provided by this module is likely to change in future |
|
22 releases; such changes may not be backward compatible. |
|
23 </p><p> |
|
24 This is a modified version to make the original tabnanny better suitable |
|
25 for being called from within the eric5 IDE. |
|
26 </p><dl> |
|
27 <dt>Raises <b>ValueError</b>:</dt> |
|
28 <dd> |
|
29 The tokenize module is too old. |
|
30 </dd> |
|
31 </dl> |
|
32 <h3>Global Attributes</h3> |
|
33 <table> |
|
34 <tr><td>__all__</td></tr><tr><td>__version__</td></tr> |
|
35 </table> |
|
36 <h3>Classes</h3> |
|
37 <table> |
|
38 <tr> |
|
39 <td><a href="#NannyNag">NannyNag</a></td> |
|
40 <td>Raised by tokeneater() if detecting an ambiguous indent.</td> |
|
41 </tr><tr> |
|
42 <td><a href="#Whitespace">Whitespace</a></td> |
|
43 <td>Class implementing the whitespace checker.</td> |
|
44 </tr> |
|
45 </table> |
|
46 <h3>Functions</h3> |
|
47 <table> |
|
48 <tr> |
|
49 <td><a href="#check">check</a></td> |
|
50 <td>Private function to check one Python source file for whitespace related problems.</td> |
|
51 </tr><tr> |
|
52 <td><a href="#format_witnesses">format_witnesses</a></td> |
|
53 <td>Function to format the witnesses as a readable string.</td> |
|
54 </tr><tr> |
|
55 <td><a href="#process_tokens">process_tokens</a></td> |
|
56 <td>Function processing all tokens generated by a tokenizer run.</td> |
|
57 </tr> |
|
58 </table> |
|
59 <hr /><hr /> |
|
60 <a NAME="NannyNag" ID="NannyNag"></a> |
|
61 <h2>NannyNag</h2> |
|
62 <p> |
|
63 Raised by tokeneater() if detecting an ambiguous indent. |
|
64 Captured and handled in check(). |
|
65 </p> |
|
66 <h3>Derived from</h3> |
|
67 Exception |
|
68 <h3>Class Attributes</h3> |
|
69 <table> |
|
70 <tr><td>None</td></tr> |
|
71 </table> |
|
72 <h3>Methods</h3> |
|
73 <table> |
|
74 <tr> |
|
75 <td><a href="#NannyNag.__init__">NannyNag</a></td> |
|
76 <td>Constructor</td> |
|
77 </tr><tr> |
|
78 <td><a href="#NannyNag.get_line">get_line</a></td> |
|
79 <td>Method to retrieve the offending line.</td> |
|
80 </tr><tr> |
|
81 <td><a href="#NannyNag.get_lineno">get_lineno</a></td> |
|
82 <td>Method to retrieve the line number.</td> |
|
83 </tr><tr> |
|
84 <td><a href="#NannyNag.get_msg">get_msg</a></td> |
|
85 <td>Method to retrieve the message.</td> |
|
86 </tr> |
|
87 </table> |
|
88 <a NAME="NannyNag.__init__" ID="NannyNag.__init__"></a> |
|
89 <h4>NannyNag (Constructor)</h4> |
|
90 <b>NannyNag</b>(<i>lineno, msg, line</i>) |
|
91 <p> |
|
92 Constructor |
|
93 </p><dl> |
|
94 <dt><i>lineno</i></dt> |
|
95 <dd> |
|
96 Line number of the ambiguous indent. |
|
97 </dd><dt><i>msg</i></dt> |
|
98 <dd> |
|
99 Descriptive message assigned to this problem. |
|
100 </dd><dt><i>line</i></dt> |
|
101 <dd> |
|
102 The offending source line. |
|
103 </dd> |
|
104 </dl><a NAME="NannyNag.get_line" ID="NannyNag.get_line"></a> |
|
105 <h4>NannyNag.get_line</h4> |
|
106 <b>get_line</b>(<i></i>) |
|
107 <p> |
|
108 Method to retrieve the offending line. |
|
109 </p><dl> |
|
110 <dt>Returns:</dt> |
|
111 <dd> |
|
112 The line of code (string) |
|
113 </dd> |
|
114 </dl><a NAME="NannyNag.get_lineno" ID="NannyNag.get_lineno"></a> |
|
115 <h4>NannyNag.get_lineno</h4> |
|
116 <b>get_lineno</b>(<i></i>) |
|
117 <p> |
|
118 Method to retrieve the line number. |
|
119 </p><dl> |
|
120 <dt>Returns:</dt> |
|
121 <dd> |
|
122 The line number (integer) |
|
123 </dd> |
|
124 </dl><a NAME="NannyNag.get_msg" ID="NannyNag.get_msg"></a> |
|
125 <h4>NannyNag.get_msg</h4> |
|
126 <b>get_msg</b>(<i></i>) |
|
127 <p> |
|
128 Method to retrieve the message. |
|
129 </p><dl> |
|
130 <dt>Returns:</dt> |
|
131 <dd> |
|
132 The error message (string) |
|
133 </dd> |
|
134 </dl> |
|
135 <div align="right"><a href="#top">Up</a></div> |
|
136 <hr /><hr /> |
|
137 <a NAME="Whitespace" ID="Whitespace"></a> |
|
138 <h2>Whitespace</h2> |
|
139 <p> |
|
140 Class implementing the whitespace checker. |
|
141 </p> |
|
142 <h3>Derived from</h3> |
|
143 object |
|
144 <h3>Class Attributes</h3> |
|
145 <table> |
|
146 <tr><td>None</td></tr> |
|
147 </table> |
|
148 <h3>Methods</h3> |
|
149 <table> |
|
150 <tr> |
|
151 <td><a href="#Whitespace.__init__">Whitespace</a></td> |
|
152 <td>Constructor</td> |
|
153 </tr><tr> |
|
154 <td><a href="#Whitespace.equal">equal</a></td> |
|
155 <td>Method to compare the indentation levels of two Whitespace objects for equality.</td> |
|
156 </tr><tr> |
|
157 <td><a href="#Whitespace.indent_level">indent_level</a></td> |
|
158 <td>Method to determine the indentation level.</td> |
|
159 </tr><tr> |
|
160 <td><a href="#Whitespace.less">less</a></td> |
|
161 <td>Method to compare the indentation level against another Whitespace objects to be smaller.</td> |
|
162 </tr><tr> |
|
163 <td><a href="#Whitespace.longest_run_of_spaces">longest_run_of_spaces</a></td> |
|
164 <td>Method to calculate the length of longest contiguous run of spaces.</td> |
|
165 </tr><tr> |
|
166 <td><a href="#Whitespace.not_equal_witness">not_equal_witness</a></td> |
|
167 <td>Method to calculate a tuple of witnessing tab size.</td> |
|
168 </tr><tr> |
|
169 <td><a href="#Whitespace.not_less_witness">not_less_witness</a></td> |
|
170 <td>Method to calculate a tuple of witnessing tab size.</td> |
|
171 </tr> |
|
172 </table> |
|
173 <a NAME="Whitespace.__init__" ID="Whitespace.__init__"></a> |
|
174 <h4>Whitespace (Constructor)</h4> |
|
175 <b>Whitespace</b>(<i>ws</i>) |
|
176 <p> |
|
177 Constructor |
|
178 </p><dl> |
|
179 <dt><i>ws</i></dt> |
|
180 <dd> |
|
181 The string to be checked. |
|
182 </dd> |
|
183 </dl><a NAME="Whitespace.equal" ID="Whitespace.equal"></a> |
|
184 <h4>Whitespace.equal</h4> |
|
185 <b>equal</b>(<i>other</i>) |
|
186 <p> |
|
187 Method to compare the indentation levels of two Whitespace objects for equality. |
|
188 </p><dl> |
|
189 <dt><i>other</i></dt> |
|
190 <dd> |
|
191 Whitespace object to compare against. |
|
192 </dd> |
|
193 </dl><dl> |
|
194 <dt>Returns:</dt> |
|
195 <dd> |
|
196 True, if we compare equal against the other Whitespace object. |
|
197 </dd> |
|
198 </dl><a NAME="Whitespace.indent_level" ID="Whitespace.indent_level"></a> |
|
199 <h4>Whitespace.indent_level</h4> |
|
200 <b>indent_level</b>(<i>tabsize</i>) |
|
201 <p> |
|
202 Method to determine the indentation level. |
|
203 </p><dl> |
|
204 <dt><i>tabsize</i></dt> |
|
205 <dd> |
|
206 The length of a tab stop. (integer) |
|
207 </dd> |
|
208 </dl><dl> |
|
209 <dt>Returns:</dt> |
|
210 <dd> |
|
211 indentation level (integer) |
|
212 </dd> |
|
213 </dl><a NAME="Whitespace.less" ID="Whitespace.less"></a> |
|
214 <h4>Whitespace.less</h4> |
|
215 <b>less</b>(<i>other</i>) |
|
216 <p> |
|
217 Method to compare the indentation level against another Whitespace objects to |
|
218 be smaller. |
|
219 </p><dl> |
|
220 <dt><i>other</i></dt> |
|
221 <dd> |
|
222 Whitespace object to compare against. |
|
223 </dd> |
|
224 </dl><dl> |
|
225 <dt>Returns:</dt> |
|
226 <dd> |
|
227 True, if we compare less against the other Whitespace object. |
|
228 </dd> |
|
229 </dl><a NAME="Whitespace.longest_run_of_spaces" ID="Whitespace.longest_run_of_spaces"></a> |
|
230 <h4>Whitespace.longest_run_of_spaces</h4> |
|
231 <b>longest_run_of_spaces</b>(<i></i>) |
|
232 <p> |
|
233 Method to calculate the length of longest contiguous run of spaces. |
|
234 </p><dl> |
|
235 <dt>Returns:</dt> |
|
236 <dd> |
|
237 The length of longest contiguous run of spaces (whether or not |
|
238 preceding a tab) |
|
239 </dd> |
|
240 </dl><a NAME="Whitespace.not_equal_witness" ID="Whitespace.not_equal_witness"></a> |
|
241 <h4>Whitespace.not_equal_witness</h4> |
|
242 <b>not_equal_witness</b>(<i>other</i>) |
|
243 <p> |
|
244 Method to calculate a tuple of witnessing tab size. |
|
245 </p><p> |
|
246 Intended to be used after not self.equal(other) is known, in which |
|
247 case it will return at least one witnessing tab size. |
|
248 </p><dl> |
|
249 <dt><i>other</i></dt> |
|
250 <dd> |
|
251 Whitespace object to calculate against. |
|
252 </dd> |
|
253 </dl><dl> |
|
254 <dt>Returns:</dt> |
|
255 <dd> |
|
256 A list of tuples (ts, i1, i2) such that |
|
257 i1 == self.indent_level(ts) != other.indent_level(ts) == i2. |
|
258 </dd> |
|
259 </dl><a NAME="Whitespace.not_less_witness" ID="Whitespace.not_less_witness"></a> |
|
260 <h4>Whitespace.not_less_witness</h4> |
|
261 <b>not_less_witness</b>(<i>other</i>) |
|
262 <p> |
|
263 Method to calculate a tuple of witnessing tab size. |
|
264 </p><p> |
|
265 Intended to be used after not self.less(other is known, in which |
|
266 case it will return at least one witnessing tab size. |
|
267 </p><dl> |
|
268 <dt><i>other</i></dt> |
|
269 <dd> |
|
270 Whitespace object to calculate against. |
|
271 </dd> |
|
272 </dl><dl> |
|
273 <dt>Returns:</dt> |
|
274 <dd> |
|
275 A list of tuples (ts, i1, i2) such that |
|
276 i1 == self.indent_level(ts) >= other.indent_level(ts) == i2. |
|
277 </dd> |
|
278 </dl> |
|
279 <div align="right"><a href="#top">Up</a></div> |
|
280 <hr /><hr /> |
|
281 <a NAME="check" ID="check"></a> |
|
282 <h2>check</h2> |
|
283 <b>check</b>(<i>file</i>) |
|
284 <p> |
|
285 Private function to check one Python source file for whitespace related problems. |
|
286 </p><dl> |
|
287 <dt><i>file</i></dt> |
|
288 <dd> |
|
289 source filename (string) |
|
290 </dd> |
|
291 </dl><dl> |
|
292 <dt>Returns:</dt> |
|
293 <dd> |
|
294 A tuple indicating status (True = an error was found), the |
|
295 filename, the linenumber and the error message |
|
296 (boolean, string, string, string). The values are only |
|
297 valid, if the status is True. |
|
298 </dd> |
|
299 </dl> |
|
300 <div align="right"><a href="#top">Up</a></div> |
|
301 <hr /><hr /> |
|
302 <a NAME="format_witnesses" ID="format_witnesses"></a> |
|
303 <h2>format_witnesses</h2> |
|
304 <b>format_witnesses</b>(<i>w</i>) |
|
305 <p> |
|
306 Function to format the witnesses as a readable string. |
|
307 </p><dl> |
|
308 <dt><i>w</i></dt> |
|
309 <dd> |
|
310 A list of witnesses |
|
311 </dd> |
|
312 </dl><dl> |
|
313 <dt>Returns:</dt> |
|
314 <dd> |
|
315 A formated string of the witnesses. |
|
316 </dd> |
|
317 </dl> |
|
318 <div align="right"><a href="#top">Up</a></div> |
|
319 <hr /><hr /> |
|
320 <a NAME="process_tokens" ID="process_tokens"></a> |
|
321 <h2>process_tokens</h2> |
|
322 <b>process_tokens</b>(<i>tokens</i>) |
|
323 <p> |
|
324 Function processing all tokens generated by a tokenizer run. |
|
325 </p><dl> |
|
326 <dt><i>tokens</i></dt> |
|
327 <dd> |
|
328 list of tokens |
|
329 </dd> |
|
330 </dl> |
|
331 <div align="right"><a href="#top">Up</a></div> |
|
332 <hr /> |
|
333 </body></html> |