Documentation/Source/eric6.Plugins.CheckerPlugins.Tabnanny.Tabnanny.html

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

eric ide

mercurial