Merge lp:~sinzui/ubuntu/oneiric/pocket-lint/0.5.21 into lp:ubuntu/oneiric/pocket-lint
- Oneiric (11.10)
- 0.5.21
- Merge into oneiric
Proposed by
Curtis Hovey
Status: | Superseded | ||||||||
---|---|---|---|---|---|---|---|---|---|
Proposed branch: | lp:~sinzui/ubuntu/oneiric/pocket-lint/0.5.21 | ||||||||
Merge into: | lp:ubuntu/oneiric/pocket-lint | ||||||||
Diff against target: |
2449 lines (+1499/-241) 10 files modified
ChangeLog (+121/-0) PKG-INFO (+1/-1) debian/changelog (+6/-0) debian/control (+1/-2) debian/copyright (+6/-1) pocketlint/contrib/cssccc.py (+495/-0) pocketlint/contrib/pep8.py (+683/-188) pocketlint/formatcheck.py (+94/-34) pocketlint/jsreporter.js (+71/-14) setup.py (+21/-1) |
||||||||
To merge this branch: | bzr merge lp:~sinzui/ubuntu/oneiric/pocket-lint/0.5.21 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Scott Moser | Needs Fixing | ||
Ubuntu branches | Pending | ||
Review via email: mp+74924@code.launchpad.net |
This proposal has been superseded by a proposal from 2011-10-18.
Commit message
Description of the change
Merge upstream release that improves CSS and JS support
debian/control was updated to require gjs
To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote : | # |
oh, and just to be clear, you're not expecting this for SRU to oneiric, right?
Revision history for this message
Curtis Hovey (sinzui) wrote : | # |
Thank you for spotting the license change. I updated the license file. No I do not think this deserves an SRU given that the branch is more than a month old.
- 6. By Curtis Hovey
-
Updated license information.
Unmerged revisions
- 6. By Curtis Hovey
-
Updated license information.
- 5. By Curtis Hovey
-
New upstream release improves CSS and JS support.
Fixes Gtk3 bugs.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ChangeLog' | |||
2 | --- ChangeLog 2011-04-16 15:32:48 +0000 | |||
3 | +++ ChangeLog 2011-10-14 21:24:26 +0000 | |||
4 | @@ -1,5 +1,126 @@ | |||
5 | 1 | <Generated by bzr log --log-format=gnu> | 1 | <Generated by bzr log --log-format=gnu> |
6 | 2 | 2 | ||
7 | 3 | 2011-06-06 Curtis Hovey <sinzui.is@verizon.net> | ||
8 | 4 | |||
9 | 5 | [396] Use seed as the js interpreter. | ||
10 | 6 | |||
11 | 7 | 2011-06-06 Curtis Hovey <sinzui.is@verizon.net> | ||
12 | 8 | |||
13 | 9 | [395] Clear refernece. | ||
14 | 10 | |||
15 | 11 | 2011-06-06 Curtis Hovey <sinzui.is@verizon.net> | ||
16 | 12 | |||
17 | 13 | [394] Documented how to use jsreporter.js | ||
18 | 14 | |||
19 | 15 | 2011-06-06 Curtis Hovey <sinzui.is@verizon.net> | ||
20 | 16 | |||
21 | 17 | [393] Removed unused code. | ||
22 | 18 | |||
23 | 19 | 2011-06-06 Curtis Hovey <sinzui.is@verizon.net> | ||
24 | 20 | |||
25 | 21 | [392] Use seed as the default js command. | ||
26 | 22 | |||
27 | 23 | 2011-06-06 Curtis Hovey <sinzui.is@verizon.net> | ||
28 | 24 | |||
29 | 25 | [391] Updated attr name. | ||
30 | 26 | |||
31 | 27 | 2011-06-06 Curtis Hovey <sinzui.is@verizon.net> | ||
32 | 28 | |||
33 | 29 | [390] Removed js subprocess, but HTML5Browser is slow. | ||
34 | 30 | |||
35 | 31 | 2011-06-05 Curtis Hovey <sinzui.is@verizon.net> | ||
36 | 32 | |||
37 | 33 | [389] Updated documentation. | ||
38 | 34 | |||
39 | 35 | 2011-06-05 Curtis Hovey <sinzui.is@verizon.net> | ||
40 | 36 | |||
41 | 37 | [388] Minor speed changes. | ||
42 | 38 | |||
43 | 39 | 2011-06-05 Curtis Hovey <sinzui.is@verizon.net> | ||
44 | 40 | |||
45 | 41 | [387] Added rudimentary JS checker based on Webkit. | ||
46 | 42 | |||
47 | 43 | 2011-05-10 Curtis Hovey <sinzui.is@verizon.net> | ||
48 | 44 | |||
49 | 45 | [386] Incremented version. | ||
50 | 46 | |||
51 | 47 | 2011-05-10 Curtis Hovey <sinzui.is@verizon.net> | ||
52 | 48 | |||
53 | 49 | [385] merged Adi's fix. | ||
54 | 50 | |||
55 | 51 | 2011-05-04 Curtis Hovey <sinzui.is@verizon.net> | ||
56 | 52 | |||
57 | 53 | [384] Inremented version. | ||
58 | 54 | |||
59 | 55 | 2011-05-04 Curtis Hovey <sinzui.is@verizon.net> | ||
60 | 56 | |||
61 | 57 | [383] Corrected the js line number. | ||
62 | 58 | |||
63 | 59 | 2011-05-04 Curtis Hovey <sinzui.is@verizon.net> | ||
64 | 60 | |||
65 | 61 | [382] Catch and report IndentationExceptions. | ||
66 | 62 | |||
67 | 63 | 2011-05-04 Curtis Hovey <sinzui.is@verizon.net> | ||
68 | 64 | |||
69 | 65 | [381] Removed unneeded checks. | ||
70 | 66 | |||
71 | 67 | 2011-05-04 Curtis Hovey <sinzui.is@verizon.net> | ||
72 | 68 | |||
73 | 69 | [380] Remove trailing whitespace. | ||
74 | 70 | |||
75 | 71 | 2011-05-04 Curtis Hovey <sinzui.is@verizon.net> | ||
76 | 72 | |||
77 | 73 | [379] Merged python encoding fix. | ||
78 | 74 | |||
79 | 75 | 2011-04-19 Curtis Hovey <sinzui.is@verizon.net> | ||
80 | 76 | |||
81 | 77 | [378] Increment version. | ||
82 | 78 | |||
83 | 79 | 2011-04-19 Curtis Hovey <sinzui.is@verizon.net> | ||
84 | 80 | |||
85 | 81 | [377] Hush WindowError. | ||
86 | 82 | |||
87 | 83 | 2011-04-19 Curtis Hovey <sinzui.is@verizon.net> | ||
88 | 84 | |||
89 | 85 | [376] Move signed archives rules into setup.py. | ||
90 | 86 | |||
91 | 87 | 2011-04-17 Curtis Hovey <sinzui.is@verizon.net> | ||
92 | 88 | |||
93 | 89 | [375] Incremented version for cssccc | ||
94 | 90 | |||
95 | 91 | 2011-04-17 Curtis Hovey <sinzui.is@verizon.net> | ||
96 | 92 | |||
97 | 93 | [374] Merged cssccc lib. | ||
98 | 94 | |||
99 | 95 | 2011-04-17 Curtis Hovey <sinzui.is@verizon.net> | ||
100 | 96 | |||
101 | 97 | [373] Added a rule to sign the release after it is made. | ||
102 | 98 | |||
103 | 99 | 2011-04-17 Curtis Hovey <sinzui.is@verizon.net> | ||
104 | 100 | |||
105 | 101 | [372] Incremenet version for release. | ||
106 | 102 | |||
107 | 103 | 2011-04-17 Curtis Hovey <sinzui.is@verizon.net> | ||
108 | 104 | |||
109 | 105 | [371] Merged Adi's feature that returns the count od reported issues. | ||
110 | 106 | |||
111 | 107 | 2011-04-17 Curtis Hovey <sinzui.is@verizon.net> | ||
112 | 108 | |||
113 | 109 | [370] Added simple SQL checker. | ||
114 | 110 | |||
115 | 111 | 2011-04-17 Curtis Hovey <sinzui.is@verizon.net> | ||
116 | 112 | |||
117 | 113 | [369] Elaborated comment test. | ||
118 | 114 | |||
119 | 115 | 2011-04-17 Curtis Hovey <sinzui.is@verizon.net> | ||
120 | 116 | |||
121 | 117 | [368] Added a basic test to verify comments do not mess up blank line | ||
122 | 118 | counts. | ||
123 | 119 | |||
124 | 120 | 2011-04-17 Curtis Hovey <sinzui.is@verizon.net> | ||
125 | 121 | |||
126 | 122 | [367] Update pep8 to version 0.6.1 | ||
127 | 123 | |||
128 | 3 | 2011-04-15 Curtis Hovey <sinzui.is@verizon.net> | 124 | 2011-04-15 Curtis Hovey <sinzui.is@verizon.net> |
129 | 4 | 125 | ||
130 | 5 | [366] Increment version. | 126 | [366] Increment version. |
131 | 6 | 127 | ||
132 | === modified file 'PKG-INFO' | |||
133 | --- PKG-INFO 2011-04-16 15:32:48 +0000 | |||
134 | +++ PKG-INFO 2011-10-14 21:24:26 +0000 | |||
135 | @@ -1,6 +1,6 @@ | |||
136 | 1 | Metadata-Version: 1.0 | 1 | Metadata-Version: 1.0 |
137 | 2 | Name: pocketlint | 2 | Name: pocketlint |
139 | 3 | Version: 0.5.13 | 3 | Version: 0.5.21 |
140 | 4 | Summary: Pocket-lint a composite linter and style checker. | 4 | Summary: Pocket-lint a composite linter and style checker. |
141 | 5 | Home-page: https://launchpad.net/pocket-lint | 5 | Home-page: https://launchpad.net/pocket-lint |
142 | 6 | Author: Curtis C. Hovey | 6 | Author: Curtis C. Hovey |
143 | 7 | 7 | ||
144 | === modified file 'debian/changelog' | |||
145 | --- debian/changelog 2011-04-16 15:32:48 +0000 | |||
146 | +++ debian/changelog 2011-10-14 21:24:26 +0000 | |||
147 | @@ -1,3 +1,9 @@ | |||
148 | 1 | pocket-lint (0.5.21-0ubuntu1) UNRELEASED; urgency=low | ||
149 | 2 | |||
150 | 3 | * New upstream release. | ||
151 | 4 | |||
152 | 5 | -- Curtis C. Hovey <sinzui.is@verizon.net> Sun, 11 Sep 2011 17:22:02 -0400 | ||
153 | 6 | |||
154 | 1 | pocket-lint (0.5.13-0ubuntu1) natty; urgency=low | 7 | pocket-lint (0.5.13-0ubuntu1) natty; urgency=low |
155 | 2 | 8 | ||
156 | 3 | * New upstream bug fix release | 9 | * New upstream bug fix release |
157 | 4 | 10 | ||
158 | === modified file 'debian/control' | |||
159 | --- debian/control 2011-04-15 13:37:44 +0000 | |||
160 | +++ debian/control 2011-10-14 21:24:26 +0000 | |||
161 | @@ -11,8 +11,7 @@ | |||
162 | 11 | Package: python-pocket-lint | 11 | Package: python-pocket-lint |
163 | 12 | Architecture: all | 12 | Architecture: all |
164 | 13 | Depends: ${misc:Depends}, ${shlibs:Depends}, ${python:Depends} | 13 | Depends: ${misc:Depends}, ${shlibs:Depends}, ${python:Depends} |
167 | 14 | Recommends: python-cssutils | 14 | Recommends: python-cssutils, gjs |
166 | 15 | Suggests: spidermonkey-bin | ||
168 | 16 | Description: a composite linter and style checker | 15 | Description: a composite linter and style checker |
169 | 17 | Pocket-lint has several notable features: | 16 | Pocket-lint has several notable features: |
170 | 18 | . | 17 | . |
171 | 19 | 18 | ||
172 | === modified file 'debian/copyright' | |||
173 | --- debian/copyright 2010-11-17 15:46:54 +0000 | |||
174 | +++ debian/copyright 2011-10-14 21:24:26 +0000 | |||
175 | @@ -4,7 +4,7 @@ | |||
176 | 4 | Copyright: | 4 | Copyright: |
177 | 5 | Upstream Author: Curtis C. Hovey | 5 | Upstream Author: Curtis C. Hovey |
178 | 6 | 6 | ||
180 | 7 | License: | 7 | Primary license: |
181 | 8 | The MIT License: | 8 | The MIT License: |
182 | 9 | 9 | ||
183 | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy | 10 | Permission is hereby granted, free of charge, to any person obtaining a copy |
184 | @@ -25,6 +25,11 @@ | |||
185 | 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
186 | 26 | THE SOFTWARE. | 26 | THE SOFTWARE. |
187 | 27 | 27 | ||
188 | 28 | |||
189 | 29 | contrib/cssccc.py license: | ||
190 | 30 | Public Domain | ||
191 | 31 | |||
192 | 32 | |||
193 | 28 | The Debian packaging is: | 33 | The Debian packaging is: |
194 | 29 | Copyright 2010 Curtis C. Hovey | 34 | Copyright 2010 Curtis C. Hovey |
195 | 30 | and is under the MIT licence. | 35 | and is under the MIT licence. |
196 | 31 | 36 | ||
197 | === added file 'pocketlint/contrib/cssccc.py' | |||
198 | --- pocketlint/contrib/cssccc.py 1970-01-01 00:00:00 +0000 | |||
199 | +++ pocketlint/contrib/cssccc.py 2011-10-14 21:24:26 +0000 | |||
200 | @@ -0,0 +1,495 @@ | |||
201 | 1 | ''' | ||
202 | 2 | This code is in the public domain. | ||
203 | 3 | |||
204 | 4 | Check CSS code for some common coding conventions. | ||
205 | 5 | The code must be in a valid CSS format. | ||
206 | 6 | It is recommend to first parse it using cssutils. | ||
207 | 7 | It is also recommend to check it with pocket-lint for things like trailing | ||
208 | 8 | spaces or tab characters. | ||
209 | 9 | |||
210 | 10 | If a comment is on the whole line, it will consume the whole line like it | ||
211 | 11 | was not there. | ||
212 | 12 | If a comment is inside a line it will only consume its own content. | ||
213 | 13 | |||
214 | 14 | Bases on Stoyan Stefanov's http://www.phpied.com/css-coding-conventions/ | ||
215 | 15 | |||
216 | 16 | '@media' rule is not supported. | ||
217 | 17 | @media print { | ||
218 | 18 | html { | ||
219 | 19 | background: #fff; | ||
220 | 20 | color: #000; | ||
221 | 21 | } | ||
222 | 22 | body { | ||
223 | 23 | padding: 1in; | ||
224 | 24 | border: 0.5pt solid #666; | ||
225 | 25 | } | ||
226 | 26 | } | ||
227 | 27 | |||
228 | 28 | The following at-rules are supported: | ||
229 | 29 | * keyword / text at-rules | ||
230 | 30 | * @charset "ISO-8859-15"; | ||
231 | 31 | * @import url(/css/screen.css) screen, projection; | ||
232 | 32 | * @namespace foo "http://example.com/ns/foo"; | ||
233 | 33 | * keybord / block rules | ||
234 | 34 | * @page { block; } | ||
235 | 35 | * @font-face { block; } | ||
236 | 36 | |||
237 | 37 | |||
238 | 38 | TODO: | ||
239 | 39 | * add warning for using px for fonts. | ||
240 | 40 | * add Unicode support. | ||
241 | 41 | * add AtRule checks | ||
242 | 42 | * add support for TAB as a separator / identation. | ||
243 | 43 | * add support for @media | ||
244 | 44 | ''' | ||
245 | 45 | from __future__ import with_statement | ||
246 | 46 | |||
247 | 47 | __version__ = '0.1.1' | ||
248 | 48 | |||
249 | 49 | import sys | ||
250 | 50 | |||
251 | 51 | SELECTOR_SEPARATOR = ',' | ||
252 | 52 | DECLARATION_SEPARATOR = ';' | ||
253 | 53 | PROPERTY_SEPARATOR = ':' | ||
254 | 54 | COMMENT_START = r'/*' | ||
255 | 55 | COMMENT_END = r'*/' | ||
256 | 56 | AT_TEXT_RULES = ['import', 'charset', 'namespace'] | ||
257 | 57 | AT_BLOCK_RULES = ['page', 'font-face'] | ||
258 | 58 | # If you want | ||
259 | 59 | # selector, | ||
260 | 60 | # selector2 | ||
261 | 61 | # { | ||
262 | 62 | # property: | ||
263 | 63 | # } | ||
264 | 64 | #IGNORED_MESSAGES = ['I013', 'I014'] | ||
265 | 65 | |||
266 | 66 | # If you want | ||
267 | 67 | # selector, | ||
268 | 68 | # selector { | ||
269 | 69 | # property: | ||
270 | 70 | # } | ||
271 | 71 | #IGNORED_MESSAGES = ['I005', 'I014'] | ||
272 | 72 | |||
273 | 73 | # If you want | ||
274 | 74 | # selector, | ||
275 | 75 | # selector2 { | ||
276 | 76 | # property: | ||
277 | 77 | # } | ||
278 | 78 | IGNORED_MESSAGES = ['I005', 'I006'] | ||
279 | 79 | |||
280 | 80 | |||
281 | 81 | class CSSRule(object): | ||
282 | 82 | '''A CSS rule.''' | ||
283 | 83 | |||
284 | 84 | def check(self): | ||
285 | 85 | '''Check the rule.''' | ||
286 | 86 | raise AssertionError('Method not implemtned.') | ||
287 | 87 | |||
288 | 88 | |||
289 | 89 | class CSSAtRule(object): | ||
290 | 90 | '''A CSS @rule.''' | ||
291 | 91 | |||
292 | 92 | type = object() | ||
293 | 93 | |||
294 | 94 | def __init__(self, identifier, keyword, log, text=None, block=None): | ||
295 | 95 | self.identifier = identifier | ||
296 | 96 | self.keyword = keyword | ||
297 | 97 | self.text = text | ||
298 | 98 | self.block = block | ||
299 | 99 | self.log = log | ||
300 | 100 | |||
301 | 101 | def check(self): | ||
302 | 102 | '''Check the rule.''' | ||
303 | 103 | |||
304 | 104 | |||
305 | 105 | class CSSRuleSet(object): | ||
306 | 106 | '''A CSS rule_set.''' | ||
307 | 107 | |||
308 | 108 | type = object() | ||
309 | 109 | |||
310 | 110 | def __init__(self, selector, declarations, log): | ||
311 | 111 | self.selector = selector | ||
312 | 112 | self.declarations = declarations | ||
313 | 113 | self.log = log | ||
314 | 114 | |||
315 | 115 | def __str__(self): | ||
316 | 116 | return '%s{%s}' % (str(self.selector), str(self.declarations)) | ||
317 | 117 | |||
318 | 118 | def __repr__(self): | ||
319 | 119 | return '%d:%s{%s}' % ( | ||
320 | 120 | self.selector.start_line, | ||
321 | 121 | str(self.selector), | ||
322 | 122 | str(self.declarations), | ||
323 | 123 | ) | ||
324 | 124 | |||
325 | 125 | def check(self): | ||
326 | 126 | '''Check the rule set.''' | ||
327 | 127 | self.checkSelector() | ||
328 | 128 | self.checkDeclarations() | ||
329 | 129 | |||
330 | 130 | def checkSelector(self): | ||
331 | 131 | '''Check rule-set selector.''' | ||
332 | 132 | start_line = self.selector.getStartLine() | ||
333 | 133 | selectors = self.selector.text.split(SELECTOR_SEPARATOR) | ||
334 | 134 | offset = 0 | ||
335 | 135 | last_selector = selectors[-1] | ||
336 | 136 | first_selector = selectors[0] | ||
337 | 137 | rest_selectors = selectors[1:] | ||
338 | 138 | |||
339 | 139 | if first_selector.startswith('\n\n\n'): | ||
340 | 140 | self.log(start_line, 'I002', 'To many newlines before selectors.') | ||
341 | 141 | elif first_selector.startswith('\n\n'): | ||
342 | 142 | pass | ||
343 | 143 | elif start_line > 2: | ||
344 | 144 | self.log(start_line, 'I003', 'To few newlines before selectors.') | ||
345 | 145 | else: | ||
346 | 146 | pass | ||
347 | 147 | |||
348 | 148 | for selector in rest_selectors: | ||
349 | 149 | if not selector.startswith('\n'): | ||
350 | 150 | self.log( | ||
351 | 151 | start_line + offset, | ||
352 | 152 | 'I004', | ||
353 | 153 | 'Selector must be on a new line.') | ||
354 | 154 | offset += selector.count('\n') | ||
355 | 155 | |||
356 | 156 | if not last_selector.endswith('\n'): | ||
357 | 157 | self.log( | ||
358 | 158 | start_line + offset, | ||
359 | 159 | 'I005', | ||
360 | 160 | 'No newline after last selector.') | ||
361 | 161 | |||
362 | 162 | if not (last_selector[-2] != ' ' and last_selector[-1] == (' ')): | ||
363 | 163 | self.log( | ||
364 | 164 | start_line + offset, | ||
365 | 165 | 'I013', | ||
366 | 166 | 'Last selector must be followed by " {".') | ||
367 | 167 | |||
368 | 168 | def checkDeclarations(self): | ||
369 | 169 | '''Check rule-set declarations.''' | ||
370 | 170 | start_line = self.declarations.getStartLine() | ||
371 | 171 | declarations = self.declarations.text.split(DECLARATION_SEPARATOR) | ||
372 | 172 | offset = 0 | ||
373 | 173 | |||
374 | 174 | # Check all declarations except last as this is the new line. | ||
375 | 175 | first_declaration = True | ||
376 | 176 | for declaration in declarations[:-1]: | ||
377 | 177 | if not declaration.startswith('\n'): | ||
378 | 178 | self.log( | ||
379 | 179 | start_line + offset, | ||
380 | 180 | 'I007', | ||
381 | 181 | 'Each declarations should start on a new line.', | ||
382 | 182 | ) | ||
383 | 183 | elif (not declaration.startswith('\n ') or | ||
384 | 184 | declaration[5] == ' '): | ||
385 | 185 | self.log( | ||
386 | 186 | start_line + offset, | ||
387 | 187 | 'I008', | ||
388 | 188 | 'Each declaration must be indented with 4 spaces.', | ||
389 | 189 | ) | ||
390 | 190 | |||
391 | 191 | parts = declaration.split(PROPERTY_SEPARATOR) | ||
392 | 192 | if len(parts) != 2: | ||
393 | 193 | self.log( | ||
394 | 194 | start_line + offset, | ||
395 | 195 | 'I009', | ||
396 | 196 | 'Wrong separator on property: value pair.', | ||
397 | 197 | ) | ||
398 | 198 | else: | ||
399 | 199 | prop, value = parts | ||
400 | 200 | if prop.endswith(' '): | ||
401 | 201 | self.log( | ||
402 | 202 | start_line + offset, | ||
403 | 203 | 'I010', | ||
404 | 204 | 'Whitespace before ":".', | ||
405 | 205 | ) | ||
406 | 206 | if not (value.startswith(' ') or value.startswith('\n')): | ||
407 | 207 | self.log( | ||
408 | 208 | start_line + offset, | ||
409 | 209 | 'I011', | ||
410 | 210 | 'Missing whitespace after ":".', | ||
411 | 211 | ) | ||
412 | 212 | elif value.startswith(' '): | ||
413 | 213 | self.log( | ||
414 | 214 | start_line + offset, | ||
415 | 215 | 'I012', | ||
416 | 216 | 'Multiple whitespaces after ":".', | ||
417 | 217 | ) | ||
418 | 218 | if first_declaration: | ||
419 | 219 | first_declaration = False | ||
420 | 220 | else: | ||
421 | 221 | offset += declaration.count('\n') | ||
422 | 222 | |||
423 | 223 | last_declaration = declarations[-1] | ||
424 | 224 | offset += last_declaration.count('\n') | ||
425 | 225 | if last_declaration != '\n': | ||
426 | 226 | self.log( | ||
427 | 227 | start_line + offset, | ||
428 | 228 | 'I006', | ||
429 | 229 | 'Rule declarations should end with a single new line.', | ||
430 | 230 | ) | ||
431 | 231 | if last_declaration != '\n ': | ||
432 | 232 | self.log( | ||
433 | 233 | start_line + offset, | ||
434 | 234 | 'I014', | ||
435 | 235 | 'Rule declarations should end indented on a single new line.', | ||
436 | 236 | ) | ||
437 | 237 | |||
438 | 238 | |||
439 | 239 | class CSSStatementMember(object): | ||
440 | 240 | '''A member of CSS statement.''' | ||
441 | 241 | |||
442 | 242 | def __init__(self, start_line, start_character, text): | ||
443 | 243 | self.start_line = start_line | ||
444 | 244 | self.start_character = start_character | ||
445 | 245 | self.text = text | ||
446 | 246 | |||
447 | 247 | def getStartLine(self): | ||
448 | 248 | '''Return the line number for first character in the statement and | ||
449 | 249 | the number of new lines untilg the first character.''' | ||
450 | 250 | index = 0 | ||
451 | 251 | text = self.text | ||
452 | 252 | character = text[index] | ||
453 | 253 | while character == '\n': | ||
454 | 254 | index += 1 | ||
455 | 255 | character = text[index] | ||
456 | 256 | |||
457 | 257 | return self.start_line + index + 1 | ||
458 | 258 | |||
459 | 259 | def __str__(self): | ||
460 | 260 | return self.text | ||
461 | 261 | |||
462 | 262 | def __repr__(self): | ||
463 | 263 | return '%d:%d:{%s}' % ( | ||
464 | 264 | self.start_line, self.start_character, self.text) | ||
465 | 265 | |||
466 | 266 | |||
467 | 267 | class CSSCodingConventionChecker(object): | ||
468 | 268 | '''CSS coding convention checker.''' | ||
469 | 269 | |||
470 | 270 | icons = { | ||
471 | 271 | 'E': 'error', | ||
472 | 272 | 'I': 'info', | ||
473 | 273 | } | ||
474 | 274 | |||
475 | 275 | def __init__(self, text, logger=None): | ||
476 | 276 | self._text = text.splitlines(True) | ||
477 | 277 | self.line_number = 0 | ||
478 | 278 | self.character_number = 0 | ||
479 | 279 | if logger: | ||
480 | 280 | self._logger = logger | ||
481 | 281 | else: | ||
482 | 282 | self._logger = self._defaultLog | ||
483 | 283 | |||
484 | 284 | def log(self, line_number, code, message): | ||
485 | 285 | '''Log the message with `code`.''' | ||
486 | 286 | if code in IGNORED_MESSAGES: | ||
487 | 287 | return | ||
488 | 288 | icon = self.icons[code[0]] | ||
489 | 289 | self._logger(line_number, code + ': ' + message, icon=icon) | ||
490 | 290 | |||
491 | 291 | def check(self): | ||
492 | 292 | '''Check all rules.''' | ||
493 | 293 | for rule in self.getRules(): | ||
494 | 294 | rule.check() | ||
495 | 295 | |||
496 | 296 | def getRules(self): | ||
497 | 297 | '''Generates the next CSS rule ignoring comments.''' | ||
498 | 298 | while True: | ||
499 | 299 | yield self.getNextRule() | ||
500 | 300 | |||
501 | 301 | def getNextRule(self): | ||
502 | 302 | '''Return the next parsed rule. | ||
503 | 303 | |||
504 | 304 | Raise `StopIteration` if we are at the last rule. | ||
505 | 305 | ''' | ||
506 | 306 | if self._nextStatementIsAtRule(): | ||
507 | 307 | text = None | ||
508 | 308 | block = None | ||
509 | 309 | keyword = self._parse('@') | ||
510 | 310 | # TODO: user regex [ \t {] | ||
511 | 311 | keyword_text = self._parse(' ') | ||
512 | 312 | keyword_name = keyword_text.text | ||
513 | 313 | keyword.text += '@' + keyword_name + ' ' | ||
514 | 314 | |||
515 | 315 | if keyword_name.lower() in AT_TEXT_RULES: | ||
516 | 316 | text = self._parse(';') | ||
517 | 317 | elif keyword_name.lower() in AT_BLOCK_RULES: | ||
518 | 318 | start = self._parse('{') | ||
519 | 319 | keyword.text += start.text | ||
520 | 320 | block = self._parse('}') | ||
521 | 321 | else: | ||
522 | 322 | self._parse(';') | ||
523 | 323 | raise StopIteration | ||
524 | 324 | |||
525 | 325 | return CSSAtRule( | ||
526 | 326 | identifier=keyword_name, | ||
527 | 327 | keyword=keyword, | ||
528 | 328 | text=text, | ||
529 | 329 | block=block, | ||
530 | 330 | log=self.log) | ||
531 | 331 | else: | ||
532 | 332 | selector = self._parse('{') | ||
533 | 333 | declarations = self._parse('}') | ||
534 | 334 | return CSSRuleSet( | ||
535 | 335 | selector=selector, | ||
536 | 336 | declarations=declarations, | ||
537 | 337 | log=self.log) | ||
538 | 338 | |||
539 | 339 | def _defaultLog(self, line_number, message, icon='info'): | ||
540 | 340 | '''Log the message to STDOUT.''' | ||
541 | 341 | print ' %4s:%s' % (line_number, message) | ||
542 | 342 | |||
543 | 343 | def _nextStatementIsAtRule(self): | ||
544 | 344 | '''Return True if next statement in the buffer is an at-rule. | ||
545 | 345 | |||
546 | 346 | Just look for open brackets and see if there is an @ before that | ||
547 | 347 | braket. | ||
548 | 348 | ''' | ||
549 | 349 | search_buffer = [] | ||
550 | 350 | line_counter = self.line_number | ||
551 | 351 | current_line = self._text[line_counter][self.character_number:] | ||
552 | 352 | while current_line.find('@') == -1: | ||
553 | 353 | search_buffer.append(current_line) | ||
554 | 354 | line_counter += 1 | ||
555 | 355 | try: | ||
556 | 356 | current_line = self._text[line_counter] | ||
557 | 357 | except IndexError: | ||
558 | 358 | return False | ||
559 | 359 | |||
560 | 360 | text_buffer = ''.join(search_buffer) | ||
561 | 361 | if text_buffer.find('{') == -1: | ||
562 | 362 | return True | ||
563 | 363 | else: | ||
564 | 364 | return False | ||
565 | 365 | |||
566 | 366 | def _parse(self, stop_character): | ||
567 | 367 | '''Return the parsed text until stop_character.''' | ||
568 | 368 | try: | ||
569 | 369 | self._text[self.line_number][self.character_number] | ||
570 | 370 | except IndexError: | ||
571 | 371 | raise StopIteration | ||
572 | 372 | result = [] | ||
573 | 373 | start_line = self.line_number | ||
574 | 374 | start_character = self.character_number | ||
575 | 375 | comment_started = False | ||
576 | 376 | while True: | ||
577 | 377 | try: | ||
578 | 378 | data = self._text[self.line_number][self.character_number:] | ||
579 | 379 | except IndexError: | ||
580 | 380 | break | ||
581 | 381 | |||
582 | 382 | # Look for comment start/end. | ||
583 | 383 | (comment_update, | ||
584 | 384 | before_comment, | ||
585 | 385 | after_comment, | ||
586 | 386 | newline_consumed) = _check_comment(data) | ||
587 | 387 | if comment_update is not None: | ||
588 | 388 | comment_started = comment_update | ||
589 | 389 | |||
590 | 390 | if comment_started: | ||
591 | 391 | # We are inside a comment. | ||
592 | 392 | # Add the data before the comment and go to next line. | ||
593 | 393 | if before_comment is not None: | ||
594 | 394 | result.append(before_comment) | ||
595 | 395 | self.character_number = 0 | ||
596 | 396 | self.line_number += 1 | ||
597 | 397 | continue | ||
598 | 398 | |||
599 | 399 | # If we have a comment, strip it from the data. | ||
600 | 400 | # Remember the initial cursor position to know where to | ||
601 | 401 | # continue. | ||
602 | 402 | initial_position = data.find(stop_character) | ||
603 | 403 | if before_comment is not None or after_comment is not None: | ||
604 | 404 | if before_comment is None: | ||
605 | 405 | before_comment = '' | ||
606 | 406 | if after_comment is None: | ||
607 | 407 | after_comment = '' | ||
608 | 408 | data = before_comment + after_comment | ||
609 | 409 | |||
610 | 410 | if initial_position == -1 or newline_consumed: | ||
611 | 411 | # We are not at the end. | ||
612 | 412 | # Go to next line and append the data. | ||
613 | 413 | result.append(data) | ||
614 | 414 | self.character_number = 0 | ||
615 | 415 | self.line_number += 1 | ||
616 | 416 | continue | ||
617 | 417 | else: | ||
618 | 418 | # Delimiter found. | ||
619 | 419 | # Find it again in the text that now has no comments. | ||
620 | 420 | # Append data until the delimiter. | ||
621 | 421 | # Move cursor to next character and stop searching for it. | ||
622 | 422 | new_position = data.find(stop_character) | ||
623 | 423 | result.append(data[:new_position]) | ||
624 | 424 | self.character_number += initial_position + 1 | ||
625 | 425 | break | ||
626 | 426 | |||
627 | 427 | return CSSStatementMember( | ||
628 | 428 | start_line=start_line, | ||
629 | 429 | start_character=start_character, | ||
630 | 430 | text=''.join(result)) | ||
631 | 431 | |||
632 | 432 | |||
633 | 433 | def _check_comment(data): | ||
634 | 434 | '''Check the data for comment markers.''' | ||
635 | 435 | |||
636 | 436 | comment_started = None | ||
637 | 437 | before_comment = None | ||
638 | 438 | after_comment = None | ||
639 | 439 | newline_consumed = False | ||
640 | 440 | |||
641 | 441 | comment_start = data.find(COMMENT_START) | ||
642 | 442 | if comment_start != -1: | ||
643 | 443 | comment_started = True | ||
644 | 444 | before_comment = data[:comment_start] | ||
645 | 445 | # Only use `None` to signal that there is no text before the comment. | ||
646 | 446 | if before_comment == '': | ||
647 | 447 | before_comment = None | ||
648 | 448 | |||
649 | 449 | comment_end = data.find(COMMENT_END) | ||
650 | 450 | if comment_end != -1: | ||
651 | 451 | comment_started = False | ||
652 | 452 | # Set comment end after the lenght of the actual comment end | ||
653 | 453 | # marker. | ||
654 | 454 | comment_end += len(COMMENT_END) | ||
655 | 455 | if before_comment is None and data[comment_end] == '\n': | ||
656 | 456 | # Consume the new line if it next to the comment end and | ||
657 | 457 | # the comment in on the whole line. | ||
658 | 458 | comment_end += 1 | ||
659 | 459 | newline_consumed = True | ||
660 | 460 | after_comment = data[comment_end:] | ||
661 | 461 | return (comment_started, before_comment, after_comment, newline_consumed) | ||
662 | 462 | |||
663 | 463 | |||
664 | 464 | def show_usage(): | ||
665 | 465 | '''Print the command usage.''' | ||
666 | 466 | print 'Usage: cssccc OPTIONS' | ||
667 | 467 | print ' -h, --help\t\tShow this help.' | ||
668 | 468 | print ' -v, --version\t\tShow version.' | ||
669 | 469 | print ' -f FILE, --file=FILE\tCheck FILE' | ||
670 | 470 | |||
671 | 471 | |||
672 | 472 | def read_file(filename): | ||
673 | 473 | '''Return the content of filename.''' | ||
674 | 474 | text = '' | ||
675 | 475 | with open(filename, 'r') as f: | ||
676 | 476 | text = f.read() | ||
677 | 477 | return text | ||
678 | 478 | |||
679 | 479 | |||
680 | 480 | if __name__ == '__main__': | ||
681 | 481 | if len(sys.argv) < 2: | ||
682 | 482 | show_usage() | ||
683 | 483 | elif sys.argv[1] in ['-v', '--version']: | ||
684 | 484 | print 'CSS Code Convention Checker %s' % (__version__) | ||
685 | 485 | sys.exit(0) | ||
686 | 486 | elif sys.argv[1] == '-f': | ||
687 | 487 | text = read_file(sys.argv[2]) | ||
688 | 488 | checker = CSSCodingConventionChecker(text) | ||
689 | 489 | sys.exit(checker.check()) | ||
690 | 490 | elif sys.argv[1] == '--file=': | ||
691 | 491 | text = read_file(sys.argv[1][len('--file='):]) | ||
692 | 492 | checker = CSSCodingConventionChecker(text) | ||
693 | 493 | sys.exit(checker.check()) | ||
694 | 494 | else: | ||
695 | 495 | show_usage() | ||
696 | 0 | 496 | ||
697 | === modified file 'pocketlint/contrib/pep8.py' | |||
698 | --- pocketlint/contrib/pep8.py 2010-11-17 15:46:54 +0000 | |||
699 | +++ pocketlint/contrib/pep8.py 2011-10-14 21:24:26 +0000 | |||
700 | @@ -1,6 +1,6 @@ | |||
701 | 1 | #!/usr/bin/python | 1 | #!/usr/bin/python |
702 | 2 | # pep8.py - Check Python source code formatting, according to PEP 8 | 2 | # pep8.py - Check Python source code formatting, according to PEP 8 |
704 | 3 | # Copyright (C) 2006 Johann C. Rocholl <johann@browsershots.org> | 3 | # Copyright (C) 2006 Johann C. Rocholl <johann@rocholl.net> |
705 | 4 | # | 4 | # |
706 | 5 | # Permission is hereby granted, free of charge, to any person | 5 | # Permission is hereby granted, free of charge, to any person |
707 | 6 | # obtaining a copy of this software and associated documentation files | 6 | # obtaining a copy of this software and associated documentation files |
708 | @@ -30,8 +30,7 @@ | |||
709 | 30 | $ python pep8.py -h | 30 | $ python pep8.py -h |
710 | 31 | 31 | ||
711 | 32 | This program and its regression test suite live here: | 32 | This program and its regression test suite live here: |
714 | 33 | http://svn.browsershots.org/trunk/devtools/pep8/ | 33 | http://github.com/jcrocholl/pep8 |
713 | 34 | http://trac.browsershots.org/browser/trunk/devtools/pep8/ | ||
715 | 35 | 34 | ||
716 | 36 | Groups of errors and warnings: | 35 | Groups of errors and warnings: |
717 | 37 | E errors | 36 | E errors |
718 | @@ -79,33 +78,65 @@ | |||
719 | 79 | 78 | ||
720 | 80 | The docstring of each check function shall be the relevant part of | 79 | The docstring of each check function shall be the relevant part of |
721 | 81 | text from PEP 8. It is printed if the user enables --show-pep8. | 80 | text from PEP 8. It is printed if the user enables --show-pep8. |
722 | 81 | Several docstrings contain examples directly from the PEP 8 document. | ||
723 | 82 | |||
724 | 83 | Okay: spam(ham[1], {eggs: 2}) | ||
725 | 84 | E201: spam( ham[1], {eggs: 2}) | ||
726 | 85 | |||
727 | 86 | These examples are verified automatically when pep8.py is run with the | ||
728 | 87 | --doctest option. You can add examples for your own check functions. | ||
729 | 88 | The format is simple: "Okay" or error/warning code followed by colon | ||
730 | 89 | and space, the rest of the line is example source code. If you put 'r' | ||
731 | 90 | before the docstring, you can use \n for newline, \t for tab and \s | ||
732 | 91 | for space. | ||
733 | 82 | 92 | ||
734 | 83 | """ | 93 | """ |
735 | 84 | 94 | ||
736 | 95 | __version__ = '0.5.1dev' | ||
737 | 96 | |||
738 | 85 | import os | 97 | import os |
739 | 86 | import sys | 98 | import sys |
740 | 87 | import re | 99 | import re |
741 | 88 | import time | 100 | import time |
742 | 89 | import inspect | 101 | import inspect |
743 | 102 | import keyword | ||
744 | 90 | import tokenize | 103 | import tokenize |
745 | 91 | from optparse import OptionParser | 104 | from optparse import OptionParser |
746 | 92 | from keyword import iskeyword | ||
747 | 93 | from fnmatch import fnmatch | 105 | from fnmatch import fnmatch |
763 | 94 | 106 | try: | |
764 | 95 | __version__ = '0.2.0' | 107 | frozenset |
765 | 96 | __revision__ = '$Rev: 2208 $' | 108 | except NameError: |
766 | 97 | 109 | from sets import ImmutableSet as frozenset | |
767 | 98 | default_exclude = '.svn,CVS,*.pyc,*.pyo' | 110 | |
768 | 99 | 111 | ||
769 | 100 | indent_match = re.compile(r'([ \t]*)').match | 112 | DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git' |
770 | 101 | raise_comma_match = re.compile(r'raise\s+\w+\s*(,)').match | 113 | DEFAULT_IGNORE = 'E24' |
771 | 102 | 114 | MAX_LINE_LENGTH = 79 | |
772 | 103 | operators = """ | 115 | |
773 | 104 | + - * / % ^ & | = < > >> << | 116 | INDENT_REGEX = re.compile(r'([ \t]*)') |
774 | 105 | += -= *= /= %= ^= &= |= == <= >= >>= <<= | 117 | RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*(,)') |
775 | 106 | != <> : | 118 | SELFTEST_REGEX = re.compile(r'(Okay|[EW]\d{3}):\s(.*)') |
776 | 107 | in is or not and | 119 | ERRORCODE_REGEX = re.compile(r'[EW]\d{3}') |
777 | 108 | """.split() | 120 | DOCSTRING_REGEX = re.compile(r'u?r?["\']') |
778 | 121 | WHITESPACE_AROUND_OPERATOR_REGEX = \ | ||
779 | 122 | re.compile('([^\w\s]*)\s*(\t| )\s*([^\w\s]*)') | ||
780 | 123 | EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]') | ||
781 | 124 | WHITESPACE_AROUND_NAMED_PARAMETER_REGEX = \ | ||
782 | 125 | re.compile(r'[()]|\s=[^=]|[^=!<>]=\s') | ||
783 | 126 | |||
784 | 127 | |||
785 | 128 | WHITESPACE = ' \t' | ||
786 | 129 | |||
787 | 130 | BINARY_OPERATORS = frozenset(['**=', '*=', '+=', '-=', '!=', '<>', | ||
788 | 131 | '%=', '^=', '&=', '|=', '==', '/=', '//=', '<=', '>=', '<<=', '>>=', | ||
789 | 132 | '%', '^', '&', '|', '=', '/', '//', '<', '>', '<<']) | ||
790 | 133 | UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-']) | ||
791 | 134 | OPERATORS = BINARY_OPERATORS | UNARY_OPERATORS | ||
792 | 135 | SKIP_TOKENS = frozenset([tokenize.COMMENT, tokenize.NL, tokenize.INDENT, | ||
793 | 136 | tokenize.DEDENT, tokenize.NEWLINE]) | ||
794 | 137 | E225NOT_KEYWORDS = (frozenset(keyword.kwlist + ['print']) - | ||
795 | 138 | frozenset(['False', 'None', 'True'])) | ||
796 | 139 | BENCHMARK_KEYS = ('directories', 'files', 'logical lines', 'physical lines') | ||
797 | 109 | 140 | ||
798 | 110 | options = None | 141 | options = None |
799 | 111 | args = None | 142 | args = None |
800 | @@ -117,7 +148,7 @@ | |||
801 | 117 | 148 | ||
802 | 118 | 149 | ||
803 | 119 | def tabs_or_spaces(physical_line, indent_char): | 150 | def tabs_or_spaces(physical_line, indent_char): |
805 | 120 | """ | 151 | r""" |
806 | 121 | Never mix tabs and spaces. | 152 | Never mix tabs and spaces. |
807 | 122 | 153 | ||
808 | 123 | The most popular way of indenting Python is with spaces only. The | 154 | The most popular way of indenting Python is with spaces only. The |
809 | @@ -126,38 +157,65 @@ | |||
810 | 126 | invoking the Python command line interpreter with the -t option, it issues | 157 | invoking the Python command line interpreter with the -t option, it issues |
811 | 127 | warnings about code that illegally mixes tabs and spaces. When using -tt | 158 | warnings about code that illegally mixes tabs and spaces. When using -tt |
812 | 128 | these warnings become errors. These options are highly recommended! | 159 | these warnings become errors. These options are highly recommended! |
813 | 160 | |||
814 | 161 | Okay: if a == 0:\n a = 1\n b = 1 | ||
815 | 162 | E101: if a == 0:\n a = 1\n\tb = 1 | ||
816 | 129 | """ | 163 | """ |
818 | 130 | indent = indent_match(physical_line).group(1) | 164 | indent = INDENT_REGEX.match(physical_line).group(1) |
819 | 131 | for offset, char in enumerate(indent): | 165 | for offset, char in enumerate(indent): |
820 | 132 | if char != indent_char: | 166 | if char != indent_char: |
821 | 133 | return offset, "E101 indentation contains mixed spaces and tabs" | 167 | return offset, "E101 indentation contains mixed spaces and tabs" |
822 | 134 | 168 | ||
823 | 135 | 169 | ||
824 | 136 | def tabs_obsolete(physical_line): | 170 | def tabs_obsolete(physical_line): |
826 | 137 | """ | 171 | r""" |
827 | 138 | For new projects, spaces-only are strongly recommended over tabs. Most | 172 | For new projects, spaces-only are strongly recommended over tabs. Most |
828 | 139 | editors have features that make this easy to do. | 173 | editors have features that make this easy to do. |
829 | 174 | |||
830 | 175 | Okay: if True:\n return | ||
831 | 176 | W191: if True:\n\treturn | ||
832 | 140 | """ | 177 | """ |
834 | 141 | indent = indent_match(physical_line).group(1) | 178 | indent = INDENT_REGEX.match(physical_line).group(1) |
835 | 142 | if indent.count('\t'): | 179 | if indent.count('\t'): |
836 | 143 | return indent.index('\t'), "W191 indentation contains tabs" | 180 | return indent.index('\t'), "W191 indentation contains tabs" |
837 | 144 | 181 | ||
838 | 145 | 182 | ||
839 | 146 | def trailing_whitespace(physical_line): | 183 | def trailing_whitespace(physical_line): |
841 | 147 | """ | 184 | r""" |
842 | 148 | JCR: Trailing whitespace is superfluous. | 185 | JCR: Trailing whitespace is superfluous. |
843 | 186 | FBM: Except when it occurs as part of a blank line (i.e. the line is | ||
844 | 187 | nothing but whitespace). According to Python docs[1] a line with only | ||
845 | 188 | whitespace is considered a blank line, and is to be ignored. However, | ||
846 | 189 | matching a blank line to its indentation level avoids mistakenly | ||
847 | 190 | terminating a multi-line statement (e.g. class declaration) when | ||
848 | 191 | pasting code into the standard Python interpreter. | ||
849 | 192 | |||
850 | 193 | [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines | ||
851 | 194 | |||
852 | 195 | The warning returned varies on whether the line itself is blank, for easier | ||
853 | 196 | filtering for those who want to indent their blank lines. | ||
854 | 197 | |||
855 | 198 | Okay: spam(1) | ||
856 | 199 | W291: spam(1)\s | ||
857 | 200 | W293: class Foo(object):\n \n bang = 12 | ||
858 | 149 | """ | 201 | """ |
862 | 150 | physical_line = physical_line.rstrip('\n') # chr(10), newline | 202 | physical_line = physical_line.rstrip('\n') # chr(10), newline |
863 | 151 | physical_line = physical_line.rstrip('\r') # chr(13), carriage return | 203 | physical_line = physical_line.rstrip('\r') # chr(13), carriage return |
864 | 152 | physical_line = physical_line.rstrip('\x0c') # chr(12), form feed, ^L | 204 | physical_line = physical_line.rstrip('\x0c') # chr(12), form feed, ^L |
865 | 153 | stripped = physical_line.rstrip() | 205 | stripped = physical_line.rstrip() |
866 | 154 | if physical_line != stripped: | 206 | if physical_line != stripped: |
868 | 155 | return len(stripped), "W291 trailing whitespace" | 207 | if stripped: |
869 | 208 | return len(stripped), "W291 trailing whitespace" | ||
870 | 209 | else: | ||
871 | 210 | return 0, "W293 blank line contains whitespace" | ||
872 | 156 | 211 | ||
873 | 157 | 212 | ||
874 | 158 | def trailing_blank_lines(physical_line, lines, line_number): | 213 | def trailing_blank_lines(physical_line, lines, line_number): |
876 | 159 | """ | 214 | r""" |
877 | 160 | JCR: Trailing blank lines are superfluous. | 215 | JCR: Trailing blank lines are superfluous. |
878 | 216 | |||
879 | 217 | Okay: spam(1) | ||
880 | 218 | W391: spam(1)\n | ||
881 | 161 | """ | 219 | """ |
882 | 162 | if physical_line.strip() == '' and line_number == len(lines): | 220 | if physical_line.strip() == '' and line_number == len(lines): |
883 | 163 | return 0, "W391 blank line at end of file" | 221 | return 0, "W391 blank line at end of file" |
884 | @@ -182,9 +240,18 @@ | |||
885 | 182 | For flowing long blocks of text (docstrings or comments), limiting the | 240 | For flowing long blocks of text (docstrings or comments), limiting the |
886 | 183 | length to 72 characters is recommended. | 241 | length to 72 characters is recommended. |
887 | 184 | """ | 242 | """ |
891 | 185 | length = len(physical_line.rstrip()) | 243 | line = physical_line.rstrip() |
892 | 186 | if length > 79: | 244 | length = len(line) |
893 | 187 | return 79, "E501 line too long (%d characters)" % length | 245 | if length > MAX_LINE_LENGTH: |
894 | 246 | try: | ||
895 | 247 | # The line could contain multi-byte characters | ||
896 | 248 | if not hasattr(line, 'decode'): # Python 3 | ||
897 | 249 | line = line.encode('latin-1') | ||
898 | 250 | length = len(line.decode('utf-8')) | ||
899 | 251 | except UnicodeDecodeError: | ||
900 | 252 | pass | ||
901 | 253 | if length > MAX_LINE_LENGTH: | ||
902 | 254 | return MAX_LINE_LENGTH, "E501 line too long (%d characters)" % length | ||
903 | 188 | 255 | ||
904 | 189 | 256 | ||
905 | 190 | ############################################################################## | 257 | ############################################################################## |
906 | @@ -193,8 +260,9 @@ | |||
907 | 193 | 260 | ||
908 | 194 | 261 | ||
909 | 195 | def blank_lines(logical_line, blank_lines, indent_level, line_number, | 262 | def blank_lines(logical_line, blank_lines, indent_level, line_number, |
912 | 196 | previous_logical): | 263 | previous_logical, previous_indent_level, |
913 | 197 | """ | 264 | blank_lines_before_comment): |
914 | 265 | r""" | ||
915 | 198 | Separate top-level function and class definitions with two blank lines. | 266 | Separate top-level function and class definitions with two blank lines. |
916 | 199 | 267 | ||
917 | 200 | Method definitions inside a class are separated by a single blank line. | 268 | Method definitions inside a class are separated by a single blank line. |
918 | @@ -204,20 +272,33 @@ | |||
919 | 204 | one-liners (e.g. a set of dummy implementations). | 272 | one-liners (e.g. a set of dummy implementations). |
920 | 205 | 273 | ||
921 | 206 | Use blank lines in functions, sparingly, to indicate logical sections. | 274 | Use blank lines in functions, sparingly, to indicate logical sections. |
922 | 275 | |||
923 | 276 | Okay: def a():\n pass\n\n\ndef b():\n pass | ||
924 | 277 | Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass | ||
925 | 278 | |||
926 | 279 | E301: class Foo:\n b = 0\n def bar():\n pass | ||
927 | 280 | E302: def a():\n pass\n\ndef b(n):\n pass | ||
928 | 281 | E303: def a():\n pass\n\n\n\ndef b(n):\n pass | ||
929 | 282 | E303: def a():\n\n\n\n pass | ||
930 | 283 | E304: @decorator\n\ndef a():\n pass | ||
931 | 207 | """ | 284 | """ |
932 | 208 | if line_number == 1: | 285 | if line_number == 1: |
934 | 209 | return # Don't expect blank lines before the first line | 286 | return # Don't expect blank lines before the first line |
935 | 287 | max_blank_lines = max(blank_lines, blank_lines_before_comment) | ||
936 | 210 | if previous_logical.startswith('@'): | 288 | if previous_logical.startswith('@'): |
947 | 211 | return # Don't expect blank lines after function decorator | 289 | if max_blank_lines: |
948 | 212 | if (logical_line.startswith('def ') or | 290 | return 0, "E304 blank lines found after function decorator" |
949 | 213 | logical_line.startswith('class ') or | 291 | elif max_blank_lines > 2 or (indent_level and max_blank_lines == 2): |
950 | 214 | logical_line.startswith('@')): | 292 | return 0, "E303 too many blank lines (%d)" % max_blank_lines |
951 | 215 | if indent_level > 0 and blank_lines != 1: | 293 | elif (logical_line.startswith('def ') or |
952 | 216 | return 0, "E301 expected 1 blank line, found %d" % blank_lines | 294 | logical_line.startswith('class ') or |
953 | 217 | if indent_level == 0 and blank_lines != 2: | 295 | logical_line.startswith('@')): |
954 | 218 | return 0, "E302 expected 2 blank lines, found %d" % blank_lines | 296 | if indent_level: |
955 | 219 | if blank_lines > 2: | 297 | if not (max_blank_lines or previous_indent_level < indent_level or |
956 | 220 | return 0, "E303 too many blank lines (%d)" % blank_lines | 298 | DOCSTRING_REGEX.match(previous_logical)): |
957 | 299 | return 0, "E301 expected 1 blank line, found 0" | ||
958 | 300 | elif max_blank_lines != 2: | ||
959 | 301 | return 0, "E302 expected 2 blank lines, found %d" % max_blank_lines | ||
960 | 221 | 302 | ||
961 | 222 | 303 | ||
962 | 223 | def extraneous_whitespace(logical_line): | 304 | def extraneous_whitespace(logical_line): |
963 | @@ -227,45 +308,75 @@ | |||
964 | 227 | - Immediately inside parentheses, brackets or braces. | 308 | - Immediately inside parentheses, brackets or braces. |
965 | 228 | 309 | ||
966 | 229 | - Immediately before a comma, semicolon, or colon. | 310 | - Immediately before a comma, semicolon, or colon. |
967 | 311 | |||
968 | 312 | Okay: spam(ham[1], {eggs: 2}) | ||
969 | 313 | E201: spam( ham[1], {eggs: 2}) | ||
970 | 314 | E201: spam(ham[ 1], {eggs: 2}) | ||
971 | 315 | E201: spam(ham[1], { eggs: 2}) | ||
972 | 316 | E202: spam(ham[1], {eggs: 2} ) | ||
973 | 317 | E202: spam(ham[1 ], {eggs: 2}) | ||
974 | 318 | E202: spam(ham[1], {eggs: 2 }) | ||
975 | 319 | |||
976 | 320 | E203: if x == 4: print x, y; x, y = y , x | ||
977 | 321 | E203: if x == 4: print x, y ; x, y = y, x | ||
978 | 322 | E203: if x == 4 : print x, y; x, y = y, x | ||
979 | 230 | """ | 323 | """ |
980 | 231 | line = logical_line | 324 | line = logical_line |
984 | 232 | for char in '([{': | 325 | for match in EXTRANEOUS_WHITESPACE_REGEX.finditer(line): |
985 | 233 | found = line.find(char + ' ') | 326 | text = match.group() |
986 | 234 | if found > -1: | 327 | char = text.strip() |
987 | 328 | found = match.start() | ||
988 | 329 | if text == char + ' ' and char in '([{': | ||
989 | 235 | return found + 1, "E201 whitespace after '%s'" % char | 330 | return found + 1, "E201 whitespace after '%s'" % char |
998 | 236 | for char in '}])': | 331 | if text == ' ' + char and line[found - 1] != ',': |
999 | 237 | found = line.find(' ' + char) | 332 | if char in '}])': |
1000 | 238 | if found > -1 and line[found - 1] != ',': | 333 | return found, "E202 whitespace before '%s'" % char |
1001 | 239 | return found, "E202 whitespace before '%s'" % char | 334 | if char in ',;:': |
1002 | 240 | for char in ',;:': | 335 | return found, "E203 whitespace before '%s'" % char |
995 | 241 | found = line.find(' ' + char) | ||
996 | 242 | if found > -1: | ||
997 | 243 | return found, "E203 whitespace before '%s'" % char | ||
1003 | 244 | 336 | ||
1004 | 245 | 337 | ||
1005 | 246 | def missing_whitespace(logical_line): | 338 | def missing_whitespace(logical_line): |
1006 | 247 | """ | 339 | """ |
1007 | 248 | JCR: Each comma, semicolon or colon should be followed by whitespace. | 340 | JCR: Each comma, semicolon or colon should be followed by whitespace. |
1008 | 341 | |||
1009 | 342 | Okay: [a, b] | ||
1010 | 343 | Okay: (3,) | ||
1011 | 344 | Okay: a[1:4] | ||
1012 | 345 | Okay: a[:4] | ||
1013 | 346 | Okay: a[1:] | ||
1014 | 347 | Okay: a[1:4:2] | ||
1015 | 348 | E231: ['a','b'] | ||
1016 | 349 | E231: foo(bar,baz) | ||
1017 | 249 | """ | 350 | """ |
1018 | 250 | line = logical_line | 351 | line = logical_line |
1019 | 251 | for index in range(len(line) - 1): | 352 | for index in range(len(line) - 1): |
1020 | 252 | char = line[index] | 353 | char = line[index] |
1022 | 253 | if char in ',;:' and line[index + 1] != ' ': | 354 | if char in ',;:' and line[index + 1] not in WHITESPACE: |
1023 | 254 | before = line[:index] | 355 | before = line[:index] |
1024 | 255 | if char == ':' and before.count('[') > before.count(']'): | 356 | if char == ':' and before.count('[') > before.count(']'): |
1026 | 256 | continue # Slice syntax, no space required | 357 | continue # Slice syntax, no space required |
1027 | 257 | if char == ',' and line[index + 1] == ')': | 358 | if char == ',' and line[index + 1] == ')': |
1029 | 258 | continue # Singleton tuple syntax, no space required | 359 | continue # Allow tuple with only one element: (3,) |
1030 | 259 | return index, "E231 missing whitespace after '%s'" % char | 360 | return index, "E231 missing whitespace after '%s'" % char |
1031 | 260 | 361 | ||
1032 | 261 | 362 | ||
1033 | 262 | def indentation(logical_line, previous_logical, indent_char, | 363 | def indentation(logical_line, previous_logical, indent_char, |
1034 | 263 | indent_level, previous_indent_level): | 364 | indent_level, previous_indent_level): |
1036 | 264 | """ | 365 | r""" |
1037 | 265 | Use 4 spaces per indentation level. | 366 | Use 4 spaces per indentation level. |
1038 | 266 | 367 | ||
1039 | 267 | For really old code that you don't want to mess up, you can continue to | 368 | For really old code that you don't want to mess up, you can continue to |
1040 | 268 | use 8-space tabs. | 369 | use 8-space tabs. |
1041 | 370 | |||
1042 | 371 | Okay: a = 1 | ||
1043 | 372 | Okay: if a == 0:\n a = 1 | ||
1044 | 373 | E111: a = 1 | ||
1045 | 374 | |||
1046 | 375 | Okay: for item in items:\n pass | ||
1047 | 376 | E112: for item in items:\npass | ||
1048 | 377 | |||
1049 | 378 | Okay: a = 1\nb = 2 | ||
1050 | 379 | E113: a = 1\n b = 2 | ||
1051 | 269 | """ | 380 | """ |
1052 | 270 | if indent_char == ' ' and indent_level % 4: | 381 | if indent_char == ' ' and indent_level % 4: |
1053 | 271 | return 0, "E111 indentation is not a multiple of four" | 382 | return 0, "E111 indentation is not a multiple of four" |
1054 | @@ -285,6 +396,13 @@ | |||
1055 | 285 | 396 | ||
1056 | 286 | - Immediately before the open parenthesis that starts an indexing or | 397 | - Immediately before the open parenthesis that starts an indexing or |
1057 | 287 | slicing. | 398 | slicing. |
1058 | 399 | |||
1059 | 400 | Okay: spam(1) | ||
1060 | 401 | E211: spam (1) | ||
1061 | 402 | |||
1062 | 403 | Okay: dict['key'] = list[index] | ||
1063 | 404 | E211: dict ['key'] = list[index] | ||
1064 | 405 | E211: dict['key'] = list [index] | ||
1065 | 288 | """ | 406 | """ |
1066 | 289 | prev_type = tokens[0][0] | 407 | prev_type = tokens[0][0] |
1067 | 290 | prev_text = tokens[0][1] | 408 | prev_text = tokens[0][1] |
1068 | @@ -294,9 +412,11 @@ | |||
1069 | 294 | if (token_type == tokenize.OP and | 412 | if (token_type == tokenize.OP and |
1070 | 295 | text in '([' and | 413 | text in '([' and |
1071 | 296 | start != prev_end and | 414 | start != prev_end and |
1073 | 297 | prev_type == tokenize.NAME and | 415 | (prev_type == tokenize.NAME or prev_text in '}])') and |
1074 | 416 | # Syntax "class A (B):" is allowed, but avoid it | ||
1075 | 298 | (index < 2 or tokens[index - 2][1] != 'class') and | 417 | (index < 2 or tokens[index - 2][1] != 'class') and |
1077 | 299 | (not iskeyword(prev_text))): | 418 | # Allow "return (a.foo for a in range(5))" |
1078 | 419 | (not keyword.iskeyword(prev_text))): | ||
1079 | 300 | return prev_end, "E211 whitespace before '%s'" % text | 420 | return prev_end, "E211 whitespace before '%s'" % text |
1080 | 301 | prev_type = token_type | 421 | prev_type = token_type |
1081 | 302 | prev_text = text | 422 | prev_text = text |
1082 | @@ -309,21 +429,97 @@ | |||
1083 | 309 | 429 | ||
1084 | 310 | - More than one space around an assignment (or other) operator to | 430 | - More than one space around an assignment (or other) operator to |
1085 | 311 | align it with another. | 431 | align it with another. |
1101 | 312 | """ | 432 | |
1102 | 313 | line = logical_line | 433 | Okay: a = 12 + 3 |
1103 | 314 | for operator in operators: | 434 | E221: a = 4 + 5 |
1104 | 315 | found = line.find(' ' + operator) | 435 | E222: a = 4 + 5 |
1105 | 316 | if found > -1: | 436 | E223: a = 4\t+ 5 |
1106 | 317 | return found, "E221 multiple spaces before operator" | 437 | E224: a = 4 +\t5 |
1107 | 318 | found = line.find(operator + ' ') | 438 | """ |
1108 | 319 | if found > -1: | 439 | for match in WHITESPACE_AROUND_OPERATOR_REGEX.finditer(logical_line): |
1109 | 320 | return found, "E222 multiple spaces after operator" | 440 | before, whitespace, after = match.groups() |
1110 | 321 | found = line.find('\t' + operator) | 441 | tab = whitespace == '\t' |
1111 | 322 | if found > -1: | 442 | offset = match.start(2) |
1112 | 323 | return found, "E223 tab before operator" | 443 | if before in OPERATORS: |
1113 | 324 | found = line.find(operator + '\t') | 444 | return offset, (tab and "E224 tab after operator" or |
1114 | 325 | if found > -1: | 445 | "E222 multiple spaces after operator") |
1115 | 326 | return found, "E224 tab after operator" | 446 | elif after in OPERATORS: |
1116 | 447 | return offset, (tab and "E223 tab before operator" or | ||
1117 | 448 | "E221 multiple spaces before operator") | ||
1118 | 449 | |||
1119 | 450 | |||
1120 | 451 | def missing_whitespace_around_operator(logical_line, tokens): | ||
1121 | 452 | r""" | ||
1122 | 453 | - Always surround these binary operators with a single space on | ||
1123 | 454 | either side: assignment (=), augmented assignment (+=, -= etc.), | ||
1124 | 455 | comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), | ||
1125 | 456 | Booleans (and, or, not). | ||
1126 | 457 | |||
1127 | 458 | - Use spaces around arithmetic operators. | ||
1128 | 459 | |||
1129 | 460 | Okay: i = i + 1 | ||
1130 | 461 | Okay: submitted += 1 | ||
1131 | 462 | Okay: x = x * 2 - 1 | ||
1132 | 463 | Okay: hypot2 = x * x + y * y | ||
1133 | 464 | Okay: c = (a + b) * (a - b) | ||
1134 | 465 | Okay: foo(bar, key='word', *args, **kwargs) | ||
1135 | 466 | Okay: baz(**kwargs) | ||
1136 | 467 | Okay: negative = -1 | ||
1137 | 468 | Okay: spam(-1) | ||
1138 | 469 | Okay: alpha[:-i] | ||
1139 | 470 | Okay: if not -5 < x < +5:\n pass | ||
1140 | 471 | Okay: lambda *args, **kw: (args, kw) | ||
1141 | 472 | |||
1142 | 473 | E225: i=i+1 | ||
1143 | 474 | E225: submitted +=1 | ||
1144 | 475 | E225: x = x*2 - 1 | ||
1145 | 476 | E225: hypot2 = x*x + y*y | ||
1146 | 477 | E225: c = (a+b) * (a-b) | ||
1147 | 478 | E225: c = alpha -4 | ||
1148 | 479 | E225: z = x **y | ||
1149 | 480 | """ | ||
1150 | 481 | parens = 0 | ||
1151 | 482 | need_space = False | ||
1152 | 483 | prev_type = tokenize.OP | ||
1153 | 484 | prev_text = prev_end = None | ||
1154 | 485 | for token_type, text, start, end, line in tokens: | ||
1155 | 486 | if token_type in (tokenize.NL, tokenize.NEWLINE, tokenize.ERRORTOKEN): | ||
1156 | 487 | # ERRORTOKEN is triggered by backticks in Python 3000 | ||
1157 | 488 | continue | ||
1158 | 489 | if text in ('(', 'lambda'): | ||
1159 | 490 | parens += 1 | ||
1160 | 491 | elif text == ')': | ||
1161 | 492 | parens -= 1 | ||
1162 | 493 | if need_space: | ||
1163 | 494 | if start != prev_end: | ||
1164 | 495 | need_space = False | ||
1165 | 496 | elif text == '>' and prev_text == '<': | ||
1166 | 497 | # Tolerate the "<>" operator, even if running Python 3 | ||
1167 | 498 | pass | ||
1168 | 499 | else: | ||
1169 | 500 | return prev_end, "E225 missing whitespace around operator" | ||
1170 | 501 | elif token_type == tokenize.OP and prev_end is not None: | ||
1171 | 502 | if text == '=' and parens: | ||
1172 | 503 | # Allow keyword args or defaults: foo(bar=None). | ||
1173 | 504 | pass | ||
1174 | 505 | elif text in BINARY_OPERATORS: | ||
1175 | 506 | need_space = True | ||
1176 | 507 | elif text in UNARY_OPERATORS: | ||
1177 | 508 | # Allow unary operators: -123, -x, +1. | ||
1178 | 509 | # Allow argument unpacking: foo(*args, **kwargs). | ||
1179 | 510 | if prev_type == tokenize.OP: | ||
1180 | 511 | if prev_text in '}])': | ||
1181 | 512 | need_space = True | ||
1182 | 513 | elif prev_type == tokenize.NAME: | ||
1183 | 514 | if prev_text not in E225NOT_KEYWORDS: | ||
1184 | 515 | need_space = True | ||
1185 | 516 | else: | ||
1186 | 517 | need_space = True | ||
1187 | 518 | if need_space and start == prev_end: | ||
1188 | 519 | return prev_end, "E225 missing whitespace around operator" | ||
1189 | 520 | prev_type = token_type | ||
1190 | 521 | prev_text = text | ||
1191 | 522 | prev_end = end | ||
1192 | 327 | 523 | ||
1193 | 328 | 524 | ||
1194 | 329 | def whitespace_around_comma(logical_line): | 525 | def whitespace_around_comma(logical_line): |
1195 | @@ -334,6 +530,11 @@ | |||
1196 | 334 | align it with another. | 530 | align it with another. |
1197 | 335 | 531 | ||
1198 | 336 | JCR: This should also be applied around comma etc. | 532 | JCR: This should also be applied around comma etc. |
1199 | 533 | Note: these checks are disabled by default | ||
1200 | 534 | |||
1201 | 535 | Okay: a = (1, 2) | ||
1202 | 536 | E241: a = (1, 2) | ||
1203 | 537 | E242: a = (1,\t2) | ||
1204 | 337 | """ | 538 | """ |
1205 | 338 | line = logical_line | 539 | line = logical_line |
1206 | 339 | for separator in ',;:': | 540 | for separator in ',;:': |
1207 | @@ -345,9 +546,77 @@ | |||
1208 | 345 | return found + 1, "E242 tab after '%s'" % separator | 546 | return found + 1, "E242 tab after '%s'" % separator |
1209 | 346 | 547 | ||
1210 | 347 | 548 | ||
1211 | 549 | def whitespace_around_named_parameter_equals(logical_line): | ||
1212 | 550 | """ | ||
1213 | 551 | Don't use spaces around the '=' sign when used to indicate a | ||
1214 | 552 | keyword argument or a default parameter value. | ||
1215 | 553 | |||
1216 | 554 | Okay: def complex(real, imag=0.0): | ||
1217 | 555 | Okay: return magic(r=real, i=imag) | ||
1218 | 556 | Okay: boolean(a == b) | ||
1219 | 557 | Okay: boolean(a != b) | ||
1220 | 558 | Okay: boolean(a <= b) | ||
1221 | 559 | Okay: boolean(a >= b) | ||
1222 | 560 | |||
1223 | 561 | E251: def complex(real, imag = 0.0): | ||
1224 | 562 | E251: return magic(r = real, i = imag) | ||
1225 | 563 | """ | ||
1226 | 564 | parens = 0 | ||
1227 | 565 | for match in WHITESPACE_AROUND_NAMED_PARAMETER_REGEX.finditer( | ||
1228 | 566 | logical_line): | ||
1229 | 567 | text = match.group() | ||
1230 | 568 | if parens and len(text) == 3: | ||
1231 | 569 | issue = "E251 no spaces around keyword / parameter equals" | ||
1232 | 570 | return match.start(), issue | ||
1233 | 571 | if text == '(': | ||
1234 | 572 | parens += 1 | ||
1235 | 573 | elif text == ')': | ||
1236 | 574 | parens -= 1 | ||
1237 | 575 | |||
1238 | 576 | |||
1239 | 577 | def whitespace_before_inline_comment(logical_line, tokens): | ||
1240 | 578 | """ | ||
1241 | 579 | Separate inline comments by at least two spaces. | ||
1242 | 580 | |||
1243 | 581 | An inline comment is a comment on the same line as a statement. Inline | ||
1244 | 582 | comments should be separated by at least two spaces from the statement. | ||
1245 | 583 | They should start with a # and a single space. | ||
1246 | 584 | |||
1247 | 585 | Okay: x = x + 1 # Increment x | ||
1248 | 586 | Okay: x = x + 1 # Increment x | ||
1249 | 587 | E261: x = x + 1 # Increment x | ||
1250 | 588 | E262: x = x + 1 #Increment x | ||
1251 | 589 | E262: x = x + 1 # Increment x | ||
1252 | 590 | """ | ||
1253 | 591 | prev_end = (0, 0) | ||
1254 | 592 | for token_type, text, start, end, line in tokens: | ||
1255 | 593 | if token_type == tokenize.NL: | ||
1256 | 594 | continue | ||
1257 | 595 | if token_type == tokenize.COMMENT: | ||
1258 | 596 | if not line[:start[1]].strip(): | ||
1259 | 597 | continue | ||
1260 | 598 | if prev_end[0] == start[0] and start[1] < prev_end[1] + 2: | ||
1261 | 599 | return (prev_end, | ||
1262 | 600 | "E261 at least two spaces before inline comment") | ||
1263 | 601 | if (len(text) > 1 and text.startswith('# ') | ||
1264 | 602 | or not text.startswith('# ')): | ||
1265 | 603 | return start, "E262 inline comment should start with '# '" | ||
1266 | 604 | else: | ||
1267 | 605 | prev_end = end | ||
1268 | 606 | |||
1269 | 607 | |||
1270 | 348 | def imports_on_separate_lines(logical_line): | 608 | def imports_on_separate_lines(logical_line): |
1272 | 349 | """ | 609 | r""" |
1273 | 350 | Imports should usually be on separate lines. | 610 | Imports should usually be on separate lines. |
1274 | 611 | |||
1275 | 612 | Okay: import os\nimport sys | ||
1276 | 613 | E401: import sys, os | ||
1277 | 614 | |||
1278 | 615 | Okay: from subprocess import Popen, PIPE | ||
1279 | 616 | Okay: from myclas import MyClass | ||
1280 | 617 | Okay: from foo.bar.yourclass import YourClass | ||
1281 | 618 | Okay: import myclass | ||
1282 | 619 | Okay: import foo.bar.yourclass | ||
1283 | 351 | """ | 620 | """ |
1284 | 352 | line = logical_line | 621 | line = logical_line |
1285 | 353 | if line.startswith('import '): | 622 | if line.startswith('import '): |
1286 | @@ -357,17 +626,37 @@ | |||
1287 | 357 | 626 | ||
1288 | 358 | 627 | ||
1289 | 359 | def compound_statements(logical_line): | 628 | def compound_statements(logical_line): |
1291 | 360 | """ | 629 | r""" |
1292 | 361 | Compound statements (multiple statements on the same line) are | 630 | Compound statements (multiple statements on the same line) are |
1293 | 362 | generally discouraged. | 631 | generally discouraged. |
1294 | 632 | |||
1295 | 633 | While sometimes it's okay to put an if/for/while with a small body | ||
1296 | 634 | on the same line, never do this for multi-clause statements. Also | ||
1297 | 635 | avoid folding such long lines! | ||
1298 | 636 | |||
1299 | 637 | Okay: if foo == 'blah':\n do_blah_thing() | ||
1300 | 638 | Okay: do_one() | ||
1301 | 639 | Okay: do_two() | ||
1302 | 640 | Okay: do_three() | ||
1303 | 641 | |||
1304 | 642 | E701: if foo == 'blah': do_blah_thing() | ||
1305 | 643 | E701: for x in lst: total += x | ||
1306 | 644 | E701: while t < 10: t = delay() | ||
1307 | 645 | E701: if foo == 'blah': do_blah_thing() | ||
1308 | 646 | E701: else: do_non_blah_thing() | ||
1309 | 647 | E701: try: something() | ||
1310 | 648 | E701: finally: cleanup() | ||
1311 | 649 | E701: if foo == 'blah': one(); two(); three() | ||
1312 | 650 | |||
1313 | 651 | E702: do_one(); do_two(); do_three() | ||
1314 | 363 | """ | 652 | """ |
1315 | 364 | line = logical_line | 653 | line = logical_line |
1316 | 365 | found = line.find(':') | 654 | found = line.find(':') |
1317 | 366 | if -1 < found < len(line) - 1: | 655 | if -1 < found < len(line) - 1: |
1318 | 367 | before = line[:found] | 656 | before = line[:found] |
1322 | 368 | if (before.count('{') <= before.count('}') and # {'a': 1} (dict) | 657 | if (before.count('{') <= before.count('}') and # {'a': 1} (dict) |
1323 | 369 | before.count('[') <= before.count(']') and # [1:2] (slice) | 658 | before.count('[') <= before.count(']') and # [1:2] (slice) |
1324 | 370 | not re.search(r'\blambda\b', before)): # lambda x: x | 659 | not re.search(r'\blambda\b', before)): # lambda x: x |
1325 | 371 | return found, "E701 multiple statements on one line (colon)" | 660 | return found, "E701 multiple statements on one line (colon)" |
1326 | 372 | found = line.find(';') | 661 | found = line.find(';') |
1327 | 373 | if -1 < found: | 662 | if -1 < found: |
1328 | @@ -397,16 +686,49 @@ | |||
1329 | 397 | continuation characters thanks to the containing parentheses. The older | 686 | continuation characters thanks to the containing parentheses. The older |
1330 | 398 | form will be removed in Python 3000. | 687 | form will be removed in Python 3000. |
1331 | 399 | """ | 688 | """ |
1333 | 400 | match = raise_comma_match(logical_line) | 689 | match = RAISE_COMMA_REGEX.match(logical_line) |
1334 | 401 | if match: | 690 | if match: |
1335 | 402 | return match.start(1), "W602 deprecated form of raising exception" | 691 | return match.start(1), "W602 deprecated form of raising exception" |
1336 | 403 | 692 | ||
1337 | 404 | 693 | ||
1338 | 694 | def python_3000_not_equal(logical_line): | ||
1339 | 695 | """ | ||
1340 | 696 | != can also be written <>, but this is an obsolete usage kept for | ||
1341 | 697 | backwards compatibility only. New code should always use !=. | ||
1342 | 698 | The older syntax is removed in Python 3000. | ||
1343 | 699 | """ | ||
1344 | 700 | pos = logical_line.find('<>') | ||
1345 | 701 | if pos > -1: | ||
1346 | 702 | return pos, "W603 '<>' is deprecated, use '!='" | ||
1347 | 703 | |||
1348 | 704 | |||
1349 | 705 | def python_3000_backticks(logical_line): | ||
1350 | 706 | """ | ||
1351 | 707 | Backticks are removed in Python 3000. | ||
1352 | 708 | Use repr() instead. | ||
1353 | 709 | """ | ||
1354 | 710 | pos = logical_line.find('`') | ||
1355 | 711 | if pos > -1: | ||
1356 | 712 | return pos, "W604 backticks are deprecated, use 'repr()'" | ||
1357 | 713 | |||
1358 | 714 | |||
1359 | 405 | ############################################################################## | 715 | ############################################################################## |
1360 | 406 | # Helper functions | 716 | # Helper functions |
1361 | 407 | ############################################################################## | 717 | ############################################################################## |
1362 | 408 | 718 | ||
1363 | 409 | 719 | ||
1364 | 720 | if '' == ''.encode(): | ||
1365 | 721 | # Python 2: implicit encoding. | ||
1366 | 722 | def readlines(filename): | ||
1367 | 723 | return open(filename).readlines() | ||
1368 | 724 | else: | ||
1369 | 725 | # Python 3: decode to latin-1. | ||
1370 | 726 | # This function is lazy, it does not read the encoding declaration. | ||
1371 | 727 | # XXX: use tokenize.detect_encoding() | ||
1372 | 728 | def readlines(filename): | ||
1373 | 729 | return open(filename, encoding='latin-1').readlines() | ||
1374 | 730 | |||
1375 | 731 | |||
1376 | 410 | def expand_indent(line): | 732 | def expand_indent(line): |
1377 | 411 | """ | 733 | """ |
1378 | 412 | Return the amount of indentation. | 734 | Return the amount of indentation. |
1379 | @@ -426,7 +748,7 @@ | |||
1380 | 426 | result = 0 | 748 | result = 0 |
1381 | 427 | for char in line: | 749 | for char in line: |
1382 | 428 | if char == '\t': | 750 | if char == '\t': |
1384 | 429 | result = result / 8 * 8 + 8 | 751 | result = result // 8 * 8 + 8 |
1385 | 430 | elif char == ' ': | 752 | elif char == ' ': |
1386 | 431 | result += 1 | 753 | result += 1 |
1387 | 432 | else: | 754 | else: |
1388 | @@ -434,34 +756,6 @@ | |||
1389 | 434 | return result | 756 | return result |
1390 | 435 | 757 | ||
1391 | 436 | 758 | ||
1392 | 437 | ############################################################################## | ||
1393 | 438 | # Framework to run all checks | ||
1394 | 439 | ############################################################################## | ||
1395 | 440 | |||
1396 | 441 | |||
1397 | 442 | def message(text): | ||
1398 | 443 | """Print a message.""" | ||
1399 | 444 | # print >> sys.stderr, options.prog + ': ' + text | ||
1400 | 445 | # print >> sys.stderr, text | ||
1401 | 446 | print text | ||
1402 | 447 | |||
1403 | 448 | |||
1404 | 449 | def find_checks(argument_name): | ||
1405 | 450 | """ | ||
1406 | 451 | Find all globally visible functions where the first argument name | ||
1407 | 452 | starts with argument_name. | ||
1408 | 453 | """ | ||
1409 | 454 | checks = [] | ||
1410 | 455 | function_type = type(find_checks) | ||
1411 | 456 | for name, function in globals().iteritems(): | ||
1412 | 457 | if type(function) is function_type: | ||
1413 | 458 | args = inspect.getargspec(function)[0] | ||
1414 | 459 | if len(args) >= 1 and args[0].startswith(argument_name): | ||
1415 | 460 | checks.append((name, function, args)) | ||
1416 | 461 | checks.sort() | ||
1417 | 462 | return checks | ||
1418 | 463 | |||
1419 | 464 | |||
1420 | 465 | def mute_string(text): | 759 | def mute_string(text): |
1421 | 466 | """ | 760 | """ |
1422 | 467 | Replace contents with 'xxx' to prevent syntax matching. | 761 | Replace contents with 'xxx' to prevent syntax matching. |
1423 | @@ -487,18 +781,53 @@ | |||
1424 | 487 | return text[:start] + 'x' * (end - start) + text[end:] | 781 | return text[:start] + 'x' * (end - start) + text[end:] |
1425 | 488 | 782 | ||
1426 | 489 | 783 | ||
1428 | 490 | class Checker: | 784 | def message(text): |
1429 | 785 | """Print a message.""" | ||
1430 | 786 | # print >> sys.stderr, options.prog + ': ' + text | ||
1431 | 787 | # print >> sys.stderr, text | ||
1432 | 788 | print(text) | ||
1433 | 789 | |||
1434 | 790 | |||
1435 | 791 | ############################################################################## | ||
1436 | 792 | # Framework to run all checks | ||
1437 | 793 | ############################################################################## | ||
1438 | 794 | |||
1439 | 795 | |||
1440 | 796 | def find_checks(argument_name): | ||
1441 | 797 | """ | ||
1442 | 798 | Find all globally visible functions where the first argument name | ||
1443 | 799 | starts with argument_name. | ||
1444 | 800 | """ | ||
1445 | 801 | checks = [] | ||
1446 | 802 | for name, function in globals().items(): | ||
1447 | 803 | if not inspect.isfunction(function): | ||
1448 | 804 | continue | ||
1449 | 805 | args = inspect.getargspec(function)[0] | ||
1450 | 806 | if args and args[0].startswith(argument_name): | ||
1451 | 807 | codes = ERRORCODE_REGEX.findall(inspect.getdoc(function) or '') | ||
1452 | 808 | for code in codes or ['']: | ||
1453 | 809 | if not code or not ignore_code(code): | ||
1454 | 810 | checks.append((name, function, args)) | ||
1455 | 811 | break | ||
1456 | 812 | checks.sort() | ||
1457 | 813 | return checks | ||
1458 | 814 | |||
1459 | 815 | |||
1460 | 816 | class Checker(object): | ||
1461 | 491 | """ | 817 | """ |
1462 | 492 | Load a Python source file, tokenize it, check coding style. | 818 | Load a Python source file, tokenize it, check coding style. |
1463 | 493 | """ | 819 | """ |
1464 | 494 | 820 | ||
1466 | 495 | def __init__(self, filename): | 821 | def __init__(self, filename, lines=None): |
1467 | 496 | self.filename = filename | 822 | self.filename = filename |
1473 | 497 | self.lines = file(filename).readlines() | 823 | if filename is None: |
1474 | 498 | self.physical_checks = find_checks('physical_line') | 824 | self.filename = 'stdin' |
1475 | 499 | self.logical_checks = find_checks('logical_line') | 825 | self.lines = lines or [] |
1476 | 500 | options.counters['physical lines'] = \ | 826 | elif lines is None: |
1477 | 501 | options.counters.get('physical lines', 0) + len(self.lines) | 827 | self.lines = readlines(filename) |
1478 | 828 | else: | ||
1479 | 829 | self.lines = lines | ||
1480 | 830 | options.counters['physical lines'] += len(self.lines) | ||
1481 | 502 | 831 | ||
1482 | 503 | def readline(self): | 832 | def readline(self): |
1483 | 504 | """ | 833 | """ |
1484 | @@ -535,7 +864,7 @@ | |||
1485 | 535 | self.physical_line = line | 864 | self.physical_line = line |
1486 | 536 | if self.indent_char is None and len(line) and line[0] in ' \t': | 865 | if self.indent_char is None and len(line) and line[0] in ' \t': |
1487 | 537 | self.indent_char = line[0] | 866 | self.indent_char = line[0] |
1489 | 538 | for name, check, argument_names in self.physical_checks: | 867 | for name, check, argument_names in options.physical_checks: |
1490 | 539 | result = self.run_check(check, argument_names) | 868 | result = self.run_check(check, argument_names) |
1491 | 540 | if result is not None: | 869 | if result is not None: |
1492 | 541 | offset, text = result | 870 | offset, text = result |
1493 | @@ -551,20 +880,20 @@ | |||
1494 | 551 | previous = None | 880 | previous = None |
1495 | 552 | for token in self.tokens: | 881 | for token in self.tokens: |
1496 | 553 | token_type, text = token[0:2] | 882 | token_type, text = token[0:2] |
1500 | 554 | if token_type in (tokenize.COMMENT, tokenize.NL, | 883 | if token_type in SKIP_TOKENS: |
1498 | 555 | tokenize.INDENT, tokenize.DEDENT, | ||
1499 | 556 | tokenize.NEWLINE): | ||
1501 | 557 | continue | 884 | continue |
1502 | 558 | if token_type == tokenize.STRING: | 885 | if token_type == tokenize.STRING: |
1503 | 559 | text = mute_string(text) | 886 | text = mute_string(text) |
1504 | 560 | if previous: | 887 | if previous: |
1505 | 561 | end_line, end = previous[3] | 888 | end_line, end = previous[3] |
1506 | 562 | start_line, start = token[2] | 889 | start_line, start = token[2] |
1509 | 563 | if end_line != start_line: # different row | 890 | if end_line != start_line: # different row |
1510 | 564 | if self.lines[end_line - 1][end - 1] not in '{[(': | 891 | prev_text = self.lines[end_line - 1][end - 1] |
1511 | 892 | if prev_text == ',' or (prev_text not in '{[(' | ||
1512 | 893 | and text not in '}])'): | ||
1513 | 565 | logical.append(' ') | 894 | logical.append(' ') |
1514 | 566 | length += 1 | 895 | length += 1 |
1516 | 567 | elif end != start: # different column | 896 | elif end != start: # different column |
1517 | 568 | fill = self.lines[end_line - 1][end:start] | 897 | fill = self.lines[end_line - 1][end:start] |
1518 | 569 | logical.append(fill) | 898 | logical.append(fill) |
1519 | 570 | length += len(fill) | 899 | length += len(fill) |
1520 | @@ -580,22 +909,21 @@ | |||
1521 | 580 | """ | 909 | """ |
1522 | 581 | Build a line from tokens and run all logical checks on it. | 910 | Build a line from tokens and run all logical checks on it. |
1523 | 582 | """ | 911 | """ |
1526 | 583 | options.counters['logical lines'] = \ | 912 | options.counters['logical lines'] += 1 |
1525 | 584 | options.counters.get('logical lines', 0) + 1 | ||
1527 | 585 | self.build_tokens_line() | 913 | self.build_tokens_line() |
1528 | 586 | first_line = self.lines[self.mapping[0][1][2][0] - 1] | 914 | first_line = self.lines[self.mapping[0][1][2][0] - 1] |
1529 | 587 | indent = first_line[:self.mapping[0][1][2][1]] | 915 | indent = first_line[:self.mapping[0][1][2][1]] |
1530 | 588 | self.previous_indent_level = self.indent_level | 916 | self.previous_indent_level = self.indent_level |
1531 | 589 | self.indent_level = expand_indent(indent) | 917 | self.indent_level = expand_indent(indent) |
1532 | 590 | if options.verbose >= 2: | 918 | if options.verbose >= 2: |
1537 | 591 | print self.logical_line[:80].rstrip() | 919 | print(self.logical_line[:80].rstrip()) |
1538 | 592 | for name, check, argument_names in self.logical_checks: | 920 | for name, check, argument_names in options.logical_checks: |
1539 | 593 | if options.verbose >= 3: | 921 | if options.verbose >= 4: |
1540 | 594 | print ' ', name | 922 | print(' ' + name) |
1541 | 595 | result = self.run_check(check, argument_names) | 923 | result = self.run_check(check, argument_names) |
1542 | 596 | if result is not None: | 924 | if result is not None: |
1543 | 597 | offset, text = result | 925 | offset, text = result |
1545 | 598 | if type(offset) is tuple: | 926 | if isinstance(offset, tuple): |
1546 | 599 | original_number, original_offset = offset | 927 | original_number, original_offset = offset |
1547 | 600 | else: | 928 | else: |
1548 | 601 | for token_offset, token in self.mapping: | 929 | for token_offset, token in self.mapping: |
1549 | @@ -607,20 +935,29 @@ | |||
1550 | 607 | text, check) | 935 | text, check) |
1551 | 608 | self.previous_logical = self.logical_line | 936 | self.previous_logical = self.logical_line |
1552 | 609 | 937 | ||
1554 | 610 | def check_all(self): | 938 | def check_all(self, expected=None, line_offset=0): |
1555 | 611 | """ | 939 | """ |
1556 | 612 | Run all checks on the input file. | 940 | Run all checks on the input file. |
1557 | 613 | """ | 941 | """ |
1558 | 942 | self.expected = expected or () | ||
1559 | 943 | self.line_offset = line_offset | ||
1560 | 944 | self.line_number = 0 | ||
1561 | 614 | self.file_errors = 0 | 945 | self.file_errors = 0 |
1562 | 615 | self.line_number = 0 | ||
1563 | 616 | self.indent_char = None | 946 | self.indent_char = None |
1564 | 617 | self.indent_level = 0 | 947 | self.indent_level = 0 |
1565 | 618 | self.previous_logical = '' | 948 | self.previous_logical = '' |
1566 | 619 | self.blank_lines = 0 | 949 | self.blank_lines = 0 |
1567 | 950 | self.blank_lines_before_comment = 0 | ||
1568 | 620 | self.tokens = [] | 951 | self.tokens = [] |
1569 | 621 | parens = 0 | 952 | parens = 0 |
1570 | 622 | for token in tokenize.generate_tokens(self.readline_check_physical): | 953 | for token in tokenize.generate_tokens(self.readline_check_physical): |
1572 | 623 | # print tokenize.tok_name[token[0]], repr(token) | 954 | if options.verbose >= 3: |
1573 | 955 | if token[2][0] == token[3][0]: | ||
1574 | 956 | pos = '[%s:%s]' % (token[2][1] or '', token[3][1]) | ||
1575 | 957 | else: | ||
1576 | 958 | pos = 'l.%s' % token[3][0] | ||
1577 | 959 | print('l.%s\t%s\t%s\t%r' % | ||
1578 | 960 | (token[2][0], pos, tokenize.tok_name[token[0]], token[1])) | ||
1579 | 624 | self.tokens.append(token) | 961 | self.tokens.append(token) |
1580 | 625 | token_type, text = token[0:2] | 962 | token_type, text = token[0:2] |
1581 | 626 | if token_type == tokenize.OP and text in '([{': | 963 | if token_type == tokenize.OP and text in '([{': |
1582 | @@ -630,40 +967,49 @@ | |||
1583 | 630 | if token_type == tokenize.NEWLINE and not parens: | 967 | if token_type == tokenize.NEWLINE and not parens: |
1584 | 631 | self.check_logical() | 968 | self.check_logical() |
1585 | 632 | self.blank_lines = 0 | 969 | self.blank_lines = 0 |
1586 | 970 | self.blank_lines_before_comment = 0 | ||
1587 | 633 | self.tokens = [] | 971 | self.tokens = [] |
1588 | 634 | if token_type == tokenize.NL and not parens: | 972 | if token_type == tokenize.NL and not parens: |
1590 | 635 | self.blank_lines += 1 | 973 | if len(self.tokens) <= 1: |
1591 | 974 | # The physical line contains only this token. | ||
1592 | 975 | self.blank_lines += 1 | ||
1593 | 636 | self.tokens = [] | 976 | self.tokens = [] |
1594 | 637 | if token_type == tokenize.COMMENT: | 977 | if token_type == tokenize.COMMENT: |
1595 | 638 | source_line = token[4] | 978 | source_line = token[4] |
1596 | 639 | token_start = token[2][1] | 979 | token_start = token[2][1] |
1597 | 640 | if source_line[:token_start].strip() == '': | 980 | if source_line[:token_start].strip() == '': |
1598 | 981 | self.blank_lines_before_comment = max(self.blank_lines, | ||
1599 | 982 | self.blank_lines_before_comment) | ||
1600 | 641 | self.blank_lines = 0 | 983 | self.blank_lines = 0 |
1601 | 984 | if text.endswith('\n') and not parens: | ||
1602 | 985 | # The comment also ends a physical line. This works around | ||
1603 | 986 | # Python < 2.6 behaviour, which does not generate NL after | ||
1604 | 987 | # a comment which is on a line by itself. | ||
1605 | 988 | self.tokens = [] | ||
1606 | 642 | return self.file_errors | 989 | return self.file_errors |
1607 | 643 | 990 | ||
1608 | 644 | def report_error(self, line_number, offset, text, check): | 991 | def report_error(self, line_number, offset, text, check): |
1609 | 645 | """ | 992 | """ |
1610 | 646 | Report an error, according to options. | 993 | Report an error, according to options. |
1611 | 647 | """ | 994 | """ |
1612 | 995 | code = text[:4] | ||
1613 | 996 | if ignore_code(code): | ||
1614 | 997 | return | ||
1615 | 648 | if options.quiet == 1 and not self.file_errors: | 998 | if options.quiet == 1 and not self.file_errors: |
1616 | 649 | message(self.filename) | 999 | message(self.filename) |
1617 | 1000 | if code in options.counters: | ||
1618 | 1001 | options.counters[code] += 1 | ||
1619 | 1002 | else: | ||
1620 | 1003 | options.counters[code] = 1 | ||
1621 | 1004 | options.messages[code] = text[5:] | ||
1622 | 1005 | if options.quiet or code in self.expected: | ||
1623 | 1006 | # Don't care about expected errors or warnings | ||
1624 | 1007 | return | ||
1625 | 650 | self.file_errors += 1 | 1008 | self.file_errors += 1 |
1626 | 651 | code = text[:4] | ||
1627 | 652 | options.counters[code] = options.counters.get(code, 0) + 1 | ||
1628 | 653 | options.messages[code] = text[5:] | ||
1629 | 654 | if options.quiet: | ||
1630 | 655 | return | ||
1631 | 656 | if options.testsuite: | ||
1632 | 657 | base = os.path.basename(self.filename)[:4] | ||
1633 | 658 | if base == code: | ||
1634 | 659 | return | ||
1635 | 660 | if base[0] == 'E' and code[0] == 'W': | ||
1636 | 661 | return | ||
1637 | 662 | if ignore_code(code): | ||
1638 | 663 | return | ||
1639 | 664 | if options.counters[code] == 1 or options.repeat: | 1009 | if options.counters[code] == 1 or options.repeat: |
1640 | 665 | message("%s:%s:%d: %s" % | 1010 | message("%s:%s:%d: %s" % |
1642 | 666 | (self.filename, line_number, offset + 1, text)) | 1011 | (self.filename, self.line_offset + line_number, |
1643 | 1012 | offset + 1, text)) | ||
1644 | 667 | if options.show_source: | 1013 | if options.show_source: |
1645 | 668 | line = self.lines[line_number - 1] | 1014 | line = self.lines[line_number - 1] |
1646 | 669 | message(line.rstrip()) | 1015 | message(line.rstrip()) |
1647 | @@ -676,35 +1022,33 @@ | |||
1648 | 676 | """ | 1022 | """ |
1649 | 677 | Run all checks on a Python source file. | 1023 | Run all checks on a Python source file. |
1650 | 678 | """ | 1024 | """ |
1651 | 679 | if excluded(filename) or not filename_match(filename): | ||
1652 | 680 | return {} | ||
1653 | 681 | if options.verbose: | 1025 | if options.verbose: |
1654 | 682 | message('checking ' + filename) | 1026 | message('checking ' + filename) |
1655 | 683 | options.counters['files'] = options.counters.get('files', 0) + 1 | ||
1656 | 684 | errors = Checker(filename).check_all() | 1027 | errors = Checker(filename).check_all() |
1662 | 685 | if options.testsuite and not errors: | 1028 | |
1663 | 686 | message("%s: %s" % (filename, "no errors found")) | 1029 | |
1664 | 687 | 1030 | def input_dir(dirname, runner=None): | |
1660 | 688 | |||
1661 | 689 | def input_dir(dirname): | ||
1665 | 690 | """ | 1031 | """ |
1666 | 691 | Check all Python source files in this directory and all subdirectories. | 1032 | Check all Python source files in this directory and all subdirectories. |
1667 | 692 | """ | 1033 | """ |
1668 | 693 | dirname = dirname.rstrip('/') | 1034 | dirname = dirname.rstrip('/') |
1669 | 694 | if excluded(dirname): | 1035 | if excluded(dirname): |
1670 | 695 | return | 1036 | return |
1671 | 1037 | if runner is None: | ||
1672 | 1038 | runner = input_file | ||
1673 | 696 | for root, dirs, files in os.walk(dirname): | 1039 | for root, dirs, files in os.walk(dirname): |
1674 | 697 | if options.verbose: | 1040 | if options.verbose: |
1675 | 698 | message('directory ' + root) | 1041 | message('directory ' + root) |
1678 | 699 | options.counters['directories'] = \ | 1042 | options.counters['directories'] += 1 |
1677 | 700 | options.counters.get('directories', 0) + 1 | ||
1679 | 701 | dirs.sort() | 1043 | dirs.sort() |
1680 | 702 | for subdir in dirs: | 1044 | for subdir in dirs: |
1681 | 703 | if excluded(subdir): | 1045 | if excluded(subdir): |
1682 | 704 | dirs.remove(subdir) | 1046 | dirs.remove(subdir) |
1683 | 705 | files.sort() | 1047 | files.sort() |
1684 | 706 | for filename in files: | 1048 | for filename in files: |
1686 | 707 | input_file(os.path.join(root, filename)) | 1049 | if filename_match(filename) and not excluded(filename): |
1687 | 1050 | options.counters['files'] += 1 | ||
1688 | 1051 | runner(os.path.join(root, filename)) | ||
1689 | 708 | 1052 | ||
1690 | 709 | 1053 | ||
1691 | 710 | def excluded(filename): | 1054 | def excluded(filename): |
1692 | @@ -733,12 +1077,23 @@ | |||
1693 | 733 | def ignore_code(code): | 1077 | def ignore_code(code): |
1694 | 734 | """ | 1078 | """ |
1695 | 735 | Check if options.ignore contains a prefix of the error code. | 1079 | Check if options.ignore contains a prefix of the error code. |
1696 | 1080 | If options.select contains a prefix of the error code, do not ignore it. | ||
1697 | 736 | """ | 1081 | """ |
1698 | 1082 | for select in options.select: | ||
1699 | 1083 | if code.startswith(select): | ||
1700 | 1084 | return False | ||
1701 | 737 | for ignore in options.ignore: | 1085 | for ignore in options.ignore: |
1702 | 738 | if code.startswith(ignore): | 1086 | if code.startswith(ignore): |
1703 | 739 | return True | 1087 | return True |
1704 | 740 | 1088 | ||
1705 | 741 | 1089 | ||
1706 | 1090 | def reset_counters(): | ||
1707 | 1091 | for key in list(options.counters.keys()): | ||
1708 | 1092 | if key not in BENCHMARK_KEYS: | ||
1709 | 1093 | del options.counters[key] | ||
1710 | 1094 | options.messages = {} | ||
1711 | 1095 | |||
1712 | 1096 | |||
1713 | 742 | def get_error_statistics(): | 1097 | def get_error_statistics(): |
1714 | 743 | """Get error statistics.""" | 1098 | """Get error statistics.""" |
1715 | 744 | return get_statistics("E") | 1099 | return get_statistics("E") |
1716 | @@ -759,7 +1114,7 @@ | |||
1717 | 759 | prefix='E4' matches all errors that have to do with imports | 1114 | prefix='E4' matches all errors that have to do with imports |
1718 | 760 | """ | 1115 | """ |
1719 | 761 | stats = [] | 1116 | stats = [] |
1721 | 762 | keys = options.messages.keys() | 1117 | keys = list(options.messages.keys()) |
1722 | 763 | keys.sort() | 1118 | keys.sort() |
1723 | 764 | for key in keys: | 1119 | for key in keys: |
1724 | 765 | if key.startswith(prefix): | 1120 | if key.startswith(prefix): |
1725 | @@ -768,24 +1123,131 @@ | |||
1726 | 768 | return stats | 1123 | return stats |
1727 | 769 | 1124 | ||
1728 | 770 | 1125 | ||
1729 | 1126 | def get_count(prefix=''): | ||
1730 | 1127 | """Return the total count of errors and warnings.""" | ||
1731 | 1128 | keys = list(options.messages.keys()) | ||
1732 | 1129 | count = 0 | ||
1733 | 1130 | for key in keys: | ||
1734 | 1131 | if key.startswith(prefix): | ||
1735 | 1132 | count += options.counters[key] | ||
1736 | 1133 | return count | ||
1737 | 1134 | |||
1738 | 1135 | |||
1739 | 771 | def print_statistics(prefix=''): | 1136 | def print_statistics(prefix=''): |
1740 | 772 | """Print overall statistics (number of errors and warnings).""" | 1137 | """Print overall statistics (number of errors and warnings).""" |
1741 | 773 | for line in get_statistics(prefix): | 1138 | for line in get_statistics(prefix): |
1743 | 774 | print line | 1139 | print(line) |
1744 | 775 | 1140 | ||
1745 | 776 | 1141 | ||
1746 | 777 | def print_benchmark(elapsed): | 1142 | def print_benchmark(elapsed): |
1747 | 778 | """ | 1143 | """ |
1748 | 779 | Print benchmark numbers. | 1144 | Print benchmark numbers. |
1749 | 780 | """ | 1145 | """ |
1758 | 781 | print '%-7.2f %s' % (elapsed, 'seconds elapsed') | 1146 | print('%-7.2f %s' % (elapsed, 'seconds elapsed')) |
1759 | 782 | keys = ['directories', 'files', | 1147 | for key in BENCHMARK_KEYS: |
1760 | 783 | 'logical lines', 'physical lines'] | 1148 | print('%-7d %s per second (%d total)' % ( |
1761 | 784 | for key in keys: | 1149 | options.counters[key] / elapsed, key, |
1762 | 785 | if key in options.counters: | 1150 | options.counters[key])) |
1763 | 786 | print '%-7d %s per second (%d total)' % ( | 1151 | |
1764 | 787 | options.counters[key] / elapsed, key, | 1152 | |
1765 | 788 | options.counters[key]) | 1153 | def run_tests(filename): |
1766 | 1154 | """ | ||
1767 | 1155 | Run all the tests from a file. | ||
1768 | 1156 | |||
1769 | 1157 | A test file can provide many tests. Each test starts with a declaration. | ||
1770 | 1158 | This declaration is a single line starting with '#:'. | ||
1771 | 1159 | It declares codes of expected failures, separated by spaces or 'Okay' | ||
1772 | 1160 | if no failure is expected. | ||
1773 | 1161 | If the file does not contain such declaration, it should pass all tests. | ||
1774 | 1162 | If the declaration is empty, following lines are not checked, until next | ||
1775 | 1163 | declaration. | ||
1776 | 1164 | |||
1777 | 1165 | Examples: | ||
1778 | 1166 | |||
1779 | 1167 | * Only E224 and W701 are expected: #: E224 W701 | ||
1780 | 1168 | * Following example is conform: #: Okay | ||
1781 | 1169 | * Don't check these lines: #: | ||
1782 | 1170 | """ | ||
1783 | 1171 | lines = readlines(filename) + ['#:\n'] | ||
1784 | 1172 | line_offset = 0 | ||
1785 | 1173 | codes = ['Okay'] | ||
1786 | 1174 | testcase = [] | ||
1787 | 1175 | for index, line in enumerate(lines): | ||
1788 | 1176 | if not line.startswith('#:'): | ||
1789 | 1177 | if codes: | ||
1790 | 1178 | # Collect the lines of the test case | ||
1791 | 1179 | testcase.append(line) | ||
1792 | 1180 | continue | ||
1793 | 1181 | if codes and index > 0: | ||
1794 | 1182 | label = '%s:%s:1' % (filename, line_offset + 1) | ||
1795 | 1183 | codes = [c for c in codes if c != 'Okay'] | ||
1796 | 1184 | # Run the checker | ||
1797 | 1185 | errors = Checker(filename, testcase).check_all(codes, line_offset) | ||
1798 | 1186 | # Check if the expected errors were found | ||
1799 | 1187 | for code in codes: | ||
1800 | 1188 | if not options.counters.get(code): | ||
1801 | 1189 | errors += 1 | ||
1802 | 1190 | message('%s: error %s not found' % (label, code)) | ||
1803 | 1191 | if options.verbose and not errors: | ||
1804 | 1192 | message('%s: passed (%s)' % (label, ' '.join(codes))) | ||
1805 | 1193 | # Keep showing errors for multiple tests | ||
1806 | 1194 | reset_counters() | ||
1807 | 1195 | # output the real line numbers | ||
1808 | 1196 | line_offset = index | ||
1809 | 1197 | # configure the expected errors | ||
1810 | 1198 | codes = line.split()[1:] | ||
1811 | 1199 | # empty the test case buffer | ||
1812 | 1200 | del testcase[:] | ||
1813 | 1201 | |||
1814 | 1202 | |||
1815 | 1203 | def selftest(): | ||
1816 | 1204 | """ | ||
1817 | 1205 | Test all check functions with test cases in docstrings. | ||
1818 | 1206 | """ | ||
1819 | 1207 | count_passed = 0 | ||
1820 | 1208 | count_failed = 0 | ||
1821 | 1209 | checks = options.physical_checks + options.logical_checks | ||
1822 | 1210 | for name, check, argument_names in checks: | ||
1823 | 1211 | for line in check.__doc__.splitlines(): | ||
1824 | 1212 | line = line.lstrip() | ||
1825 | 1213 | match = SELFTEST_REGEX.match(line) | ||
1826 | 1214 | if match is None: | ||
1827 | 1215 | continue | ||
1828 | 1216 | code, source = match.groups() | ||
1829 | 1217 | checker = Checker(None) | ||
1830 | 1218 | for part in source.split(r'\n'): | ||
1831 | 1219 | part = part.replace(r'\t', '\t') | ||
1832 | 1220 | part = part.replace(r'\s', ' ') | ||
1833 | 1221 | checker.lines.append(part + '\n') | ||
1834 | 1222 | options.quiet = 2 | ||
1835 | 1223 | checker.check_all() | ||
1836 | 1224 | error = None | ||
1837 | 1225 | if code == 'Okay': | ||
1838 | 1226 | if len(options.counters) > len(BENCHMARK_KEYS): | ||
1839 | 1227 | codes = [key for key in options.counters.keys() | ||
1840 | 1228 | if key not in BENCHMARK_KEYS] | ||
1841 | 1229 | error = "incorrectly found %s" % ', '.join(codes) | ||
1842 | 1230 | elif not options.counters.get(code): | ||
1843 | 1231 | error = "failed to find %s" % code | ||
1844 | 1232 | # Reset the counters | ||
1845 | 1233 | reset_counters() | ||
1846 | 1234 | if not error: | ||
1847 | 1235 | count_passed += 1 | ||
1848 | 1236 | else: | ||
1849 | 1237 | count_failed += 1 | ||
1850 | 1238 | if len(checker.lines) == 1: | ||
1851 | 1239 | print("pep8.py: %s: %s" % | ||
1852 | 1240 | (error, checker.lines[0].rstrip())) | ||
1853 | 1241 | else: | ||
1854 | 1242 | print("pep8.py: %s:" % error) | ||
1855 | 1243 | for line in checker.lines: | ||
1856 | 1244 | print(line.rstrip()) | ||
1857 | 1245 | if options.verbose: | ||
1858 | 1246 | print("%d passed and %d failed." % (count_passed, count_failed)) | ||
1859 | 1247 | if count_failed: | ||
1860 | 1248 | print("Test failed.") | ||
1861 | 1249 | else: | ||
1862 | 1250 | print("Test passed.") | ||
1863 | 789 | 1251 | ||
1864 | 790 | 1252 | ||
1865 | 791 | def process_options(arglist=None): | 1253 | def process_options(arglist=None): |
1866 | @@ -793,26 +1255,36 @@ | |||
1867 | 793 | Process options passed either via arglist or via command line args. | 1255 | Process options passed either via arglist or via command line args. |
1868 | 794 | """ | 1256 | """ |
1869 | 795 | global options, args | 1257 | global options, args |
1872 | 796 | usage = "%prog [options] input ..." | 1258 | parser = OptionParser(version=__version__, |
1873 | 797 | parser = OptionParser(usage) | 1259 | usage="%prog [options] input ...") |
1874 | 798 | parser.add_option('-v', '--verbose', default=0, action='count', | 1260 | parser.add_option('-v', '--verbose', default=0, action='count', |
1875 | 799 | help="print status messages, or debug with -vv") | 1261 | help="print status messages, or debug with -vv") |
1876 | 800 | parser.add_option('-q', '--quiet', default=0, action='count', | 1262 | parser.add_option('-q', '--quiet', default=0, action='count', |
1877 | 801 | help="report only file names, or nothing with -qq") | 1263 | help="report only file names, or nothing with -qq") |
1882 | 802 | parser.add_option('--exclude', metavar='patterns', default=default_exclude, | 1264 | parser.add_option('-r', '--repeat', action='store_true', |
1883 | 803 | help="skip matches (default %s)" % default_exclude) | 1265 | help="show all occurrences of the same error") |
1884 | 804 | parser.add_option('--filename', metavar='patterns', | 1266 | parser.add_option('--exclude', metavar='patterns', default=DEFAULT_EXCLUDE, |
1885 | 805 | help="only check matching files (e.g. *.py)") | 1267 | help="exclude files or directories which match these " |
1886 | 1268 | "comma separated patterns (default: %s)" % | ||
1887 | 1269 | DEFAULT_EXCLUDE) | ||
1888 | 1270 | parser.add_option('--filename', metavar='patterns', default='*.py', | ||
1889 | 1271 | help="when parsing directories, only check filenames " | ||
1890 | 1272 | "matching these comma separated patterns (default: " | ||
1891 | 1273 | "*.py)") | ||
1892 | 1274 | parser.add_option('--select', metavar='errors', default='', | ||
1893 | 1275 | help="select errors and warnings (e.g. E,W6)") | ||
1894 | 806 | parser.add_option('--ignore', metavar='errors', default='', | 1276 | parser.add_option('--ignore', metavar='errors', default='', |
1895 | 807 | help="skip errors and warnings (e.g. E4,W)") | 1277 | help="skip errors and warnings (e.g. E4,W)") |
1896 | 808 | parser.add_option('--repeat', action='store_true', | ||
1897 | 809 | help="show all occurrences of the same error") | ||
1898 | 810 | parser.add_option('--show-source', action='store_true', | 1278 | parser.add_option('--show-source', action='store_true', |
1899 | 811 | help="show source code for each error") | 1279 | help="show source code for each error") |
1900 | 812 | parser.add_option('--show-pep8', action='store_true', | 1280 | parser.add_option('--show-pep8', action='store_true', |
1901 | 813 | help="show text of PEP 8 for each error") | 1281 | help="show text of PEP 8 for each error") |
1902 | 814 | parser.add_option('--statistics', action='store_true', | 1282 | parser.add_option('--statistics', action='store_true', |
1903 | 815 | help="count errors and warnings") | 1283 | help="count errors and warnings") |
1904 | 1284 | parser.add_option('--count', action='store_true', | ||
1905 | 1285 | help="print total number of errors and warnings " | ||
1906 | 1286 | "to standard error and set exit code to 1 if " | ||
1907 | 1287 | "total is not null") | ||
1908 | 816 | parser.add_option('--benchmark', action='store_true', | 1288 | parser.add_option('--benchmark', action='store_true', |
1909 | 817 | help="measure processing speed") | 1289 | help="measure processing speed") |
1910 | 818 | parser.add_option('--testsuite', metavar='dir', | 1290 | parser.add_option('--testsuite', metavar='dir', |
1911 | @@ -822,7 +1294,7 @@ | |||
1912 | 822 | options, args = parser.parse_args(arglist) | 1294 | options, args = parser.parse_args(arglist) |
1913 | 823 | if options.testsuite: | 1295 | if options.testsuite: |
1914 | 824 | args.append(options.testsuite) | 1296 | args.append(options.testsuite) |
1916 | 825 | if len(args) == 0: | 1297 | if not args and not options.doctest: |
1917 | 826 | parser.error('input not specified') | 1298 | parser.error('input not specified') |
1918 | 827 | options.prog = os.path.basename(sys.argv[0]) | 1299 | options.prog = os.path.basename(sys.argv[0]) |
1919 | 828 | options.exclude = options.exclude.split(',') | 1300 | options.exclude = options.exclude.split(',') |
1920 | @@ -830,13 +1302,25 @@ | |||
1921 | 830 | options.exclude[index] = options.exclude[index].rstrip('/') | 1302 | options.exclude[index] = options.exclude[index].rstrip('/') |
1922 | 831 | if options.filename: | 1303 | if options.filename: |
1923 | 832 | options.filename = options.filename.split(',') | 1304 | options.filename = options.filename.split(',') |
1924 | 1305 | if options.select: | ||
1925 | 1306 | options.select = options.select.split(',') | ||
1926 | 1307 | else: | ||
1927 | 1308 | options.select = [] | ||
1928 | 833 | if options.ignore: | 1309 | if options.ignore: |
1929 | 834 | options.ignore = options.ignore.split(',') | 1310 | options.ignore = options.ignore.split(',') |
1931 | 835 | else: | 1311 | elif options.select: |
1932 | 1312 | # Ignore all checks which are not explicitly selected | ||
1933 | 1313 | options.ignore = [''] | ||
1934 | 1314 | elif options.testsuite or options.doctest: | ||
1935 | 1315 | # For doctest and testsuite, all checks are required | ||
1936 | 836 | options.ignore = [] | 1316 | options.ignore = [] |
1938 | 837 | options.counters = {} | 1317 | else: |
1939 | 1318 | # The default choice: ignore controversial checks | ||
1940 | 1319 | options.ignore = DEFAULT_IGNORE.split(',') | ||
1941 | 1320 | options.physical_checks = find_checks('physical_line') | ||
1942 | 1321 | options.logical_checks = find_checks('logical_line') | ||
1943 | 1322 | options.counters = dict.fromkeys(BENCHMARK_KEYS, 0) | ||
1944 | 838 | options.messages = {} | 1323 | options.messages = {} |
1945 | 839 | |||
1946 | 840 | return options, args | 1324 | return options, args |
1947 | 841 | 1325 | ||
1948 | 842 | 1326 | ||
1949 | @@ -847,18 +1331,29 @@ | |||
1950 | 847 | options, args = process_options() | 1331 | options, args = process_options() |
1951 | 848 | if options.doctest: | 1332 | if options.doctest: |
1952 | 849 | import doctest | 1333 | import doctest |
1954 | 850 | return doctest.testmod() | 1334 | doctest.testmod(verbose=options.verbose) |
1955 | 1335 | selftest() | ||
1956 | 1336 | if options.testsuite: | ||
1957 | 1337 | runner = run_tests | ||
1958 | 1338 | else: | ||
1959 | 1339 | runner = input_file | ||
1960 | 851 | start_time = time.time() | 1340 | start_time = time.time() |
1961 | 852 | for path in args: | 1341 | for path in args: |
1962 | 853 | if os.path.isdir(path): | 1342 | if os.path.isdir(path): |
1966 | 854 | input_dir(path) | 1343 | input_dir(path, runner=runner) |
1967 | 855 | else: | 1344 | elif not excluded(path): |
1968 | 856 | input_file(path) | 1345 | options.counters['files'] += 1 |
1969 | 1346 | runner(path) | ||
1970 | 857 | elapsed = time.time() - start_time | 1347 | elapsed = time.time() - start_time |
1971 | 858 | if options.statistics: | 1348 | if options.statistics: |
1972 | 859 | print_statistics() | 1349 | print_statistics() |
1973 | 860 | if options.benchmark: | 1350 | if options.benchmark: |
1974 | 861 | print_benchmark(elapsed) | 1351 | print_benchmark(elapsed) |
1975 | 1352 | count = get_count() | ||
1976 | 1353 | if count: | ||
1977 | 1354 | if options.count: | ||
1978 | 1355 | sys.stderr.write(str(count) + '\n') | ||
1979 | 1356 | sys.exit(1) | ||
1980 | 862 | 1357 | ||
1981 | 863 | 1358 | ||
1982 | 864 | if __name__ == '__main__': | 1359 | if __name__ == '__main__': |
1983 | 865 | 1360 | ||
1984 | === modified file 'pocketlint/formatcheck.py' | |||
1985 | --- pocketlint/formatcheck.py 2011-04-15 13:37:44 +0000 | |||
1986 | +++ pocketlint/formatcheck.py 2011-10-14 21:24:26 +0000 | |||
1987 | @@ -3,10 +3,15 @@ | |||
1988 | 3 | # This software is licensed under the MIT license (see the file COPYING). | 3 | # This software is licensed under the MIT license (see the file COPYING). |
1989 | 4 | """Check for syntax and style problems.""" | 4 | """Check for syntax and style problems.""" |
1990 | 5 | 5 | ||
1991 | 6 | from __future__ import with_statement | ||
1992 | 7 | |||
1993 | 8 | __metaclass__ = type | 6 | __metaclass__ = type |
1994 | 9 | 7 | ||
1995 | 8 | |||
1996 | 9 | __all__ = [ | ||
1997 | 10 | 'Reporter', | ||
1998 | 11 | 'UniversalChecker', | ||
1999 | 12 | ] | ||
2000 | 13 | |||
2001 | 14 | |||
2002 | 10 | import compiler | 15 | import compiler |
2003 | 11 | import htmlentitydefs | 16 | import htmlentitydefs |
2004 | 12 | import logging | 17 | import logging |
2005 | @@ -31,26 +36,39 @@ | |||
2006 | 31 | from formatdoctest import DoctestReviewer | 36 | from formatdoctest import DoctestReviewer |
2007 | 32 | 37 | ||
2008 | 33 | import contrib.pep8 as pep8 | 38 | import contrib.pep8 as pep8 |
2010 | 34 | from contrib.pyflakes.checker import Checker | 39 | from contrib.cssccc import CSSCodingConventionChecker |
2011 | 40 | from contrib.pyflakes.checker import Checker as PyFlakesChecker | ||
2012 | 35 | try: | 41 | try: |
2013 | 36 | import cssutils | 42 | import cssutils |
2014 | 37 | HAS_CSSUTILS = True | 43 | HAS_CSSUTILS = True |
2015 | 38 | except ImportError: | 44 | except ImportError: |
2016 | 39 | HAS_CSSUTILS = False | 45 | HAS_CSSUTILS = False |
2017 | 40 | 46 | ||
2031 | 41 | # Javascript checking is available if spider money's js is available. | 47 | |
2032 | 42 | js = subprocess.Popen( | 48 | def find_exec(names): |
2033 | 43 | ['which', 'js'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 49 | """Return the name of a GI enabled JS interpreter.""" |
2034 | 44 | js_exec, ignore = js.communicate() | 50 | for name in names: |
2035 | 45 | if js.returncode != 0: | 51 | js = subprocess.Popen( |
2036 | 46 | JS = None | 52 | ['which', name], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
2037 | 47 | else: | 53 | js_exec, ignore = js.communicate() |
2038 | 48 | JS = js_exec.strip() | 54 | if js.returncode == 0: |
2039 | 49 | 55 | return js_exec.strip() | |
2040 | 50 | __all__ = [ | 56 | |
2041 | 51 | 'Reporter', | 57 | |
2042 | 52 | 'UniversalChecker', | 58 | JS = find_exec(['gjs', 'seed']) |
2043 | 53 | ] | 59 | |
2044 | 60 | |||
2045 | 61 | class PocketLintPyFlakesChecker(PyFlakesChecker): | ||
2046 | 62 | '''PocketLint checker for pyflakes. | ||
2047 | 63 | |||
2048 | 64 | This is here to work around some of the pyflakes problems. | ||
2049 | 65 | ''' | ||
2050 | 66 | |||
2051 | 67 | def NAME(self, node): | ||
2052 | 68 | '''Locate name. Ignore WindowsErrors.''' | ||
2053 | 69 | if node.name == 'WindowsError': | ||
2054 | 70 | return | ||
2055 | 71 | return super(PocketLintPyFlakesChecker, self).NAME(node) | ||
2056 | 54 | 72 | ||
2057 | 55 | 73 | ||
2058 | 56 | class Reporter: | 74 | class Reporter: |
2059 | @@ -65,10 +83,12 @@ | |||
2060 | 65 | self.treestore = self.file_lines_view.get_model() | 83 | self.treestore = self.file_lines_view.get_model() |
2061 | 66 | self.piter = None | 84 | self.piter = None |
2062 | 67 | self._last_file_name = None | 85 | self._last_file_name = None |
2063 | 86 | self.call_count = 0 | ||
2064 | 68 | 87 | ||
2065 | 69 | def __call__(self, line_no, message, icon=None, | 88 | def __call__(self, line_no, message, icon=None, |
2066 | 70 | base_dir=None, file_name=None): | 89 | base_dir=None, file_name=None): |
2067 | 71 | """Report a message.""" | 90 | """Report a message.""" |
2068 | 91 | self.call_count += 1 | ||
2069 | 72 | if self.report_type == self.FILE_LINES: | 92 | if self.report_type == self.FILE_LINES: |
2070 | 73 | self._message_file_lines( | 93 | self._message_file_lines( |
2071 | 74 | line_no, message, icon=icon, | 94 | line_no, message, icon=icon, |
2072 | @@ -117,6 +137,7 @@ | |||
2073 | 117 | ZCML = object() | 137 | ZCML = object() |
2074 | 118 | DOCBOOK = object() | 138 | DOCBOOK = object() |
2075 | 119 | LOG = object() | 139 | LOG = object() |
2076 | 140 | SQL = object() | ||
2077 | 120 | 141 | ||
2078 | 121 | XML_LIKE = (XML, XSLT, HTML, ZPT, ZCML, DOCBOOK) | 142 | XML_LIKE = (XML, XSLT, HTML, ZPT, ZCML, DOCBOOK) |
2079 | 122 | 143 | ||
2080 | @@ -130,6 +151,7 @@ | |||
2081 | 130 | 'text/css': CSS, | 151 | 'text/css': CSS, |
2082 | 131 | 'text/html': HTML, | 152 | 'text/html': HTML, |
2083 | 132 | 'text/plain': TEXT, | 153 | 'text/plain': TEXT, |
2084 | 154 | 'text/x-sql': SQL, | ||
2085 | 133 | 'text/x-log': LOG, | 155 | 'text/x-log': LOG, |
2086 | 134 | 'application/javascript': JAVASCRIPT, | 156 | 'application/javascript': JAVASCRIPT, |
2087 | 135 | 'application/xml': XML, | 157 | 'application/xml': XML, |
2088 | @@ -285,6 +307,20 @@ | |||
2089 | 285 | self.check_conflicts(line_no, line) | 307 | self.check_conflicts(line_no, line) |
2090 | 286 | 308 | ||
2091 | 287 | 309 | ||
2092 | 310 | class SQLChecker(BaseChecker, AnyTextMixin): | ||
2093 | 311 | """Verify SQL style.""" | ||
2094 | 312 | |||
2095 | 313 | def check(self): | ||
2096 | 314 | """Call each line_method for each line in text.""" | ||
2097 | 315 | # Consider http://code.google.com/p/python-sqlparse/ to verify | ||
2098 | 316 | # keywords and reformatting. | ||
2099 | 317 | for line_no, line in enumerate(self.text.splitlines()): | ||
2100 | 318 | line_no += 1 | ||
2101 | 319 | self.check_trailing_whitespace(line_no, line) | ||
2102 | 320 | self.check_tab(line_no, line) | ||
2103 | 321 | self.check_conflicts(line_no, line) | ||
2104 | 322 | |||
2105 | 323 | |||
2106 | 288 | class XMLChecker(BaseChecker, AnyTextMixin): | 324 | class XMLChecker(BaseChecker, AnyTextMixin): |
2107 | 289 | """Check XML documents.""" | 325 | """Check XML documents.""" |
2108 | 290 | 326 | ||
2109 | @@ -312,7 +348,7 @@ | |||
2110 | 312 | start, end = match.span(0) | 348 | start, end = match.span(0) |
2111 | 313 | text = text[:start] + self.xhtml_doctype + text[end:] | 349 | text = text[:start] + self.xhtml_doctype + text[end:] |
2112 | 314 | try: | 350 | try: |
2114 | 315 | root = ElementTree.parse(StringIO(text), parser) | 351 | ElementTree.parse(StringIO(text), parser) |
2115 | 316 | except (ExpatError, ParseError), error: | 352 | except (ExpatError, ParseError), error: |
2116 | 317 | if hasattr(error, 'code'): | 353 | if hasattr(error, 'code'): |
2117 | 318 | error_message = ErrorString(error.code) | 354 | error_message = ErrorString(error.code) |
2118 | @@ -326,7 +362,7 @@ | |||
2119 | 326 | error_lineno = 0 | 362 | error_lineno = 0 |
2120 | 327 | else: | 363 | else: |
2121 | 328 | error_message, location = str(error).rsplit(':') | 364 | error_message, location = str(error).rsplit(':') |
2123 | 329 | error_lineno = int(location.split(',')[0].split()[1])- offset | 365 | error_lineno = int(location.split(',')[0].split()[1]) - offset |
2124 | 330 | self.message(error_lineno, error_message, icon='error') | 366 | self.message(error_lineno, error_message, icon='error') |
2125 | 331 | self.check_text() | 367 | self.check_text() |
2126 | 332 | 368 | ||
2127 | @@ -378,7 +414,18 @@ | |||
2128 | 378 | 414 | ||
2129 | 379 | def check(self): | 415 | def check(self): |
2130 | 380 | """Check the syntax of the CSS code.""" | 416 | """Check the syntax of the CSS code.""" |
2132 | 381 | if self.text == '' or not HAS_CSSUTILS: | 417 | if self.text == '': |
2133 | 418 | return | ||
2134 | 419 | |||
2135 | 420 | self.check_cssutils() | ||
2136 | 421 | self.check_text() | ||
2137 | 422 | # CSS coding conventoins checks should go last since they rely | ||
2138 | 423 | # on previous checks. | ||
2139 | 424 | self.check_css_coding_conventions() | ||
2140 | 425 | |||
2141 | 426 | def check_cssutils(self): | ||
2142 | 427 | """Check the CSS code by parsing it using CSSUtils module.""" | ||
2143 | 428 | if not HAS_CSSUTILS: | ||
2144 | 382 | return | 429 | return |
2145 | 383 | handler = CSSReporterHandler(self) | 430 | handler = CSSReporterHandler(self) |
2146 | 384 | log = logging.getLogger('pocket-lint') | 431 | log = logging.getLogger('pocket-lint') |
2147 | @@ -387,7 +434,6 @@ | |||
2148 | 387 | log=log, loglevel=logging.INFO, raiseExceptions=False) | 434 | log=log, loglevel=logging.INFO, raiseExceptions=False) |
2149 | 388 | parser.parseString(self.text) | 435 | parser.parseString(self.text) |
2150 | 389 | log.removeHandler(handler) | 436 | log.removeHandler(handler) |
2151 | 390 | self.check_text() | ||
2152 | 391 | 437 | ||
2153 | 392 | def check_text(self): | 438 | def check_text(self): |
2154 | 393 | """Call each line_method for each line in text.""" | 439 | """Call each line_method for each line in text.""" |
2155 | @@ -398,22 +444,29 @@ | |||
2156 | 398 | self.check_conflicts(line_no, line) | 444 | self.check_conflicts(line_no, line) |
2157 | 399 | self.check_tab(line_no, line) | 445 | self.check_tab(line_no, line) |
2158 | 400 | 446 | ||
2159 | 447 | def check_css_coding_conventions(self): | ||
2160 | 448 | """Check the input using CSS Coding Convention checker.""" | ||
2161 | 449 | CSSCodingConventionChecker(self.text, logger=self.message).check() | ||
2162 | 450 | |||
2163 | 401 | 451 | ||
2164 | 402 | class PythonChecker(BaseChecker, AnyTextMixin): | 452 | class PythonChecker(BaseChecker, AnyTextMixin): |
2165 | 403 | """Check python source code.""" | 453 | """Check python source code.""" |
2166 | 404 | 454 | ||
2167 | 455 | # This regex is taken from PEP 0263. | ||
2168 | 456 | encoding_pattern = re.compile("coding[:=]\s*([-\w.]+)") | ||
2169 | 457 | |||
2170 | 405 | def __init__(self, file_path, text, reporter=None): | 458 | def __init__(self, file_path, text, reporter=None): |
2171 | 406 | super(PythonChecker, self).__init__( | 459 | super(PythonChecker, self).__init__( |
2172 | 407 | file_path, text, reporter=reporter) | 460 | file_path, text, reporter=reporter) |
2174 | 408 | self.is_utf8 = False | 461 | self.encoding = 'ascii' |
2175 | 409 | 462 | ||
2176 | 410 | def check(self): | 463 | def check(self): |
2177 | 411 | """Check the syntax of the python code.""" | 464 | """Check the syntax of the python code.""" |
2178 | 412 | if self.text == '': | 465 | if self.text == '': |
2179 | 413 | return | 466 | return |
2180 | 467 | self.check_text() | ||
2181 | 414 | self.check_flakes() | 468 | self.check_flakes() |
2182 | 415 | self.check_pep8() | 469 | self.check_pep8() |
2183 | 416 | self.check_text() | ||
2184 | 417 | 470 | ||
2185 | 418 | def check_flakes(self): | 471 | def check_flakes(self): |
2186 | 419 | """Check compilation and syntax.""" | 472 | """Check compilation and syntax.""" |
2187 | @@ -421,13 +474,12 @@ | |||
2188 | 421 | tree = compiler.parse(self.text) | 474 | tree = compiler.parse(self.text) |
2189 | 422 | except (SyntaxError, IndentationError), exc: | 475 | except (SyntaxError, IndentationError), exc: |
2190 | 423 | line_no = exc.lineno or 0 | 476 | line_no = exc.lineno or 0 |
2191 | 424 | offset = exc.offset or 0 | ||
2192 | 425 | line = exc.text or '' | 477 | line = exc.text or '' |
2193 | 426 | explanation = 'Could not compile; %s' % exc.msg | 478 | explanation = 'Could not compile; %s' % exc.msg |
2194 | 427 | message = '%s: %s' % (explanation, line.strip()) | 479 | message = '%s: %s' % (explanation, line.strip()) |
2195 | 428 | self.message(line_no, message, icon='error') | 480 | self.message(line_no, message, icon='error') |
2196 | 429 | else: | 481 | else: |
2198 | 430 | warnings = Checker(tree) | 482 | warnings = PocketLintPyFlakesChecker(tree) |
2199 | 431 | for warning in warnings.messages: | 483 | for warning in warnings.messages: |
2200 | 432 | dummy, line_no, message = str(warning).split(':') | 484 | dummy, line_no, message = str(warning).split(':') |
2201 | 433 | self.message(int(line_no), message.strip(), icon='error') | 485 | self.message(int(line_no), message.strip(), icon='error') |
2202 | @@ -448,20 +500,24 @@ | |||
2203 | 448 | except TokenError, er: | 500 | except TokenError, er: |
2204 | 449 | message, location = er.args | 501 | message, location = er.args |
2205 | 450 | self.message(location[0], message, icon='error') | 502 | self.message(location[0], message, icon='error') |
2206 | 503 | except IndentationError, er: | ||
2207 | 504 | message, location = er.args | ||
2208 | 505 | message = "%s: %s" % (message, location[3].strip()) | ||
2209 | 506 | self.message(location[1], message, icon='error') | ||
2210 | 451 | finally: | 507 | finally: |
2212 | 452 | Checker.report_error = original_report_error | 508 | pep8.Checker.report_error = original_report_error |
2213 | 453 | 509 | ||
2214 | 454 | def check_text(self): | 510 | def check_text(self): |
2215 | 455 | """Call each line_method for each line in text.""" | 511 | """Call each line_method for each line in text.""" |
2216 | 456 | for line_no, line in enumerate(self.text.splitlines()): | 512 | for line_no, line in enumerate(self.text.splitlines()): |
2217 | 457 | line_no += 1 | 513 | line_no += 1 |
2220 | 458 | if line_no in (1, 2) and '# -*- coding: utf-8 -*-' in line: | 514 | if line_no in (1, 2): |
2221 | 459 | self.is_utf8 = True | 515 | match = self.encoding_pattern.search(line) |
2222 | 516 | if match: | ||
2223 | 517 | self.encoding = match.group(1).lower() | ||
2224 | 460 | self.check_pdb(line_no, line) | 518 | self.check_pdb(line_no, line) |
2225 | 461 | self.check_length(line_no, line) | 519 | self.check_length(line_no, line) |
2226 | 462 | self.check_trailing_whitespace(line_no, line) | ||
2227 | 463 | self.check_conflicts(line_no, line) | 520 | self.check_conflicts(line_no, line) |
2228 | 464 | self.check_tab(line_no, line) | ||
2229 | 465 | self.check_ascii(line_no, line) | 521 | self.check_ascii(line_no, line) |
2230 | 466 | 522 | ||
2231 | 467 | def check_pdb(self, line_no, line): | 523 | def check_pdb(self, line_no, line): |
2232 | @@ -473,10 +529,10 @@ | |||
2233 | 473 | 529 | ||
2234 | 474 | def check_ascii(self, line_no, line): | 530 | def check_ascii(self, line_no, line): |
2235 | 475 | """Check that the line is ascii.""" | 531 | """Check that the line is ascii.""" |
2237 | 476 | if self.is_utf8: | 532 | if self.encoding != 'ascii': |
2238 | 477 | return | 533 | return |
2239 | 478 | try: | 534 | try: |
2241 | 479 | ascii_line = line.encode('ascii') | 535 | line.encode('ascii') |
2242 | 480 | except UnicodeEncodeError, error: | 536 | except UnicodeEncodeError, error: |
2243 | 481 | self.message( | 537 | self.message( |
2244 | 482 | line_no, 'Non-ascii characer at position %s.' % error.end, | 538 | line_no, 'Non-ascii characer at position %s.' % error.end, |
2245 | @@ -494,7 +550,7 @@ | |||
2246 | 494 | """Check the syntax of the javascript code.""" | 550 | """Check the syntax of the javascript code.""" |
2247 | 495 | if JS is None or self.text == '': | 551 | if JS is None or self.text == '': |
2248 | 496 | return | 552 | return |
2250 | 497 | args = [JS, '-f', self.FULLJSLINT, self.JSREPORTER, self.text] | 553 | args = [JS, self.JSREPORTER, self.FULLJSLINT, self.file_path] |
2251 | 498 | jslint = subprocess.Popen( | 554 | jslint = subprocess.Popen( |
2252 | 499 | args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 555 | args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
2253 | 500 | issues, errors = jslint.communicate() | 556 | issues, errors = jslint.communicate() |
2254 | @@ -502,7 +558,9 @@ | |||
2255 | 502 | if issues: | 558 | if issues: |
2256 | 503 | for issue in issues.splitlines(): | 559 | for issue in issues.splitlines(): |
2257 | 504 | line_no, char_no_, message = issue.split('::') | 560 | line_no, char_no_, message = issue.split('::') |
2259 | 505 | self.message(int(line_no), message, icon='error') | 561 | line_no = int(line_no) |
2260 | 562 | line_no -= 1 | ||
2261 | 563 | self.message(line_no, message, icon='error') | ||
2262 | 506 | self.check_text() | 564 | self.check_text() |
2263 | 507 | 565 | ||
2264 | 508 | def check_text(self): | 566 | def check_text(self): |
2265 | @@ -530,6 +588,7 @@ | |||
2266 | 530 | def check_sources(sources, reporter=None): | 588 | def check_sources(sources, reporter=None): |
2267 | 531 | if reporter is None: | 589 | if reporter is None: |
2268 | 532 | reporter = Reporter(Reporter.CONSOLE) | 590 | reporter = Reporter(Reporter.CONSOLE) |
2269 | 591 | reporter.call_count = 0 | ||
2270 | 533 | for source in sources: | 592 | for source in sources: |
2271 | 534 | file_path = os.path.normpath(source) | 593 | file_path = os.path.normpath(source) |
2272 | 535 | if os.path.isdir(source) or not Language.is_editable(source): | 594 | if os.path.isdir(source) or not Language.is_editable(source): |
2273 | @@ -540,6 +599,7 @@ | |||
2274 | 540 | checker = UniversalChecker( | 599 | checker = UniversalChecker( |
2275 | 541 | file_path, text=text, language=language, reporter=reporter) | 600 | file_path, text=text, language=language, reporter=reporter) |
2276 | 542 | checker.check() | 601 | checker.check() |
2277 | 602 | return reporter.call_count | ||
2278 | 543 | 603 | ||
2279 | 544 | 604 | ||
2280 | 545 | def main(argv=None): | 605 | def main(argv=None): |
2281 | @@ -554,7 +614,7 @@ | |||
2282 | 554 | if options.verbose: | 614 | if options.verbose: |
2283 | 555 | pass | 615 | pass |
2284 | 556 | reporter = Reporter(Reporter.CONSOLE) | 616 | reporter = Reporter(Reporter.CONSOLE) |
2286 | 557 | check_sources(sources, reporter) | 617 | return check_sources(sources, reporter) |
2287 | 558 | 618 | ||
2288 | 559 | 619 | ||
2289 | 560 | if __name__ == '__main__': | 620 | if __name__ == '__main__': |
2290 | 561 | 621 | ||
2291 | === modified file 'pocketlint/jsreporter.js' | |||
2292 | --- pocketlint/jsreporter.js 2011-04-15 13:37:44 +0000 | |||
2293 | +++ pocketlint/jsreporter.js 2011-10-14 21:24:26 +0000 | |||
2294 | @@ -1,44 +1,101 @@ | |||
2296 | 1 | // Copyright (C) 2009-2010 - Curtis Hovey <sinzui.is at verizon.net> | 1 | // Copyright (C) 2009-2011 - Curtis Hovey <sinzui.is at verizon.net> |
2297 | 2 | // This software is licensed under the MIT license (see the file COPYING). | 2 | // This software is licensed under the MIT license (see the file COPYING). |
2298 | 3 | 3 | ||
2299 | 4 | // Run like: | ||
2300 | 5 | // <seed|gjs> jsreporter.js <path/to/fulljslint.js> <path/file/to/lint.js> | ||
2301 | 6 | |||
2302 | 7 | |||
2303 | 8 | function get_seed() { | ||
2304 | 9 | // Define a common global object like seed. | ||
2305 | 10 | var argv = ['gjs', 'jsreporter.js']; | ||
2306 | 11 | var i; | ||
2307 | 12 | for (i = 0; i < ARGV.length; i++) { | ||
2308 | 13 | argv.push(ARGV[i]); | ||
2309 | 14 | } | ||
2310 | 15 | return { | ||
2311 | 16 | 'print': print, | ||
2312 | 17 | 'argv': argv | ||
2313 | 18 | }; | ||
2314 | 19 | } | ||
2315 | 20 | |||
2316 | 21 | |||
2317 | 22 | var Seed = Seed || get_seed(); | ||
2318 | 23 | |||
2319 | 24 | |||
2320 | 25 | jslint_path = Seed.argv[2].substring(0, Seed.argv[2].lastIndexOf('/')); | ||
2321 | 26 | imports.searchPath.push(jslint_path); | ||
2322 | 27 | var JSLINT = imports.fulljslint.JSLINT; | ||
2323 | 28 | |||
2324 | 29 | |||
2325 | 30 | function get_file_content(file_path) { | ||
2326 | 31 | // Return the content of the file. | ||
2327 | 32 | var Gio = imports.gi.Gio; | ||
2328 | 33 | var file = Gio.file_new_for_path(file_path); | ||
2329 | 34 | var istream = file.read(null); | ||
2330 | 35 | var dstream = new Gio.DataInputStream({base_stream: istream}); | ||
2331 | 36 | var content_and_count = dstream.read_upto("", -1, null); | ||
2332 | 37 | istream.close(null); | ||
2333 | 38 | dstream = null; | ||
2334 | 39 | return content_and_count[0]; | ||
2335 | 40 | } | ||
2336 | 41 | |||
2337 | 42 | |||
2338 | 4 | function report_implied_names() { | 43 | function report_implied_names() { |
2339 | 5 | // Report about implied global names. | 44 | // Report about implied global names. |
2340 | 6 | var implied_names = []; | 45 | var implied_names = []; |
2344 | 7 | for (var name in JSLINT.implied) { | 46 | var prop; |
2345 | 8 | if (JSLINT.implied.hasOwnPropery(name)) { | 47 | for (prop in JSLINT.implied) { |
2346 | 9 | implied_names.push(name); | 48 | if (JSLINT.implied.hasOwnProperty(prop)) { |
2347 | 49 | implied_names.push(prop); | ||
2348 | 10 | } | 50 | } |
2349 | 11 | } | 51 | } |
2350 | 12 | if (implied_names.length > 0) { | 52 | if (implied_names.length > 0) { |
2351 | 13 | implied_names.sort(); | 53 | implied_names.sort(); |
2353 | 14 | print('0::0::Implied globals:' + implied_names.join(', ')); | 54 | return '0::0::Implied globals:' + implied_names.join(', '); |
2354 | 15 | } | 55 | } |
2355 | 56 | return ''; | ||
2356 | 16 | } | 57 | } |
2357 | 17 | 58 | ||
2358 | 18 | 59 | ||
2359 | 19 | function report_lint_errors() { | 60 | function report_lint_errors() { |
2360 | 20 | // Report about lint errors. | 61 | // Report about lint errors. |
2362 | 21 | for (var i = 0; i < JSLINT.errors.length; i++) { | 62 | var errors = []; |
2363 | 63 | var i; | ||
2364 | 64 | for (i = 0; i < JSLINT.errors.length; i++) { | ||
2365 | 22 | var error = JSLINT.errors[i]; | 65 | var error = JSLINT.errors[i]; |
2366 | 23 | if (error === null) { | 66 | if (error === null) { |
2368 | 24 | print('0::0::JSLINT had a fatal error.'); | 67 | error = { |
2369 | 68 | 'line': -1, | ||
2370 | 69 | 'character': -1, | ||
2371 | 70 | 'reason': 'JSLINT had a fatal error.' | ||
2372 | 71 | }; | ||
2373 | 25 | } | 72 | } |
2374 | 26 | // Fix the line and character offset for editors. | 73 | // Fix the line and character offset for editors. |
2375 | 27 | error.line += 1; | 74 | error.line += 1; |
2376 | 28 | error.character += 1; | 75 | error.character += 1; |
2378 | 29 | print(error.line + '::' + error.character + '::' + error.reason); | 76 | errors.push( |
2379 | 77 | [error.line, error.character, error.reason].join('::')); | ||
2380 | 30 | } | 78 | } |
2381 | 79 | return errors.join('\n'); | ||
2382 | 31 | } | 80 | } |
2383 | 32 | 81 | ||
2384 | 33 | 82 | ||
2386 | 34 | function main(source_script) { | 83 | function lint_script() { |
2387 | 35 | // Lint the source and report errors. | 84 | // Lint the source and report errors. |
2389 | 36 | var result = JSLINT(source_script); | 85 | var script = get_file_content(Seed.argv[3]); |
2390 | 86 | var result = JSLINT(script); | ||
2391 | 37 | if (! result) { | 87 | if (! result) { |
2394 | 38 | report_lint_errors(); | 88 | var issues = []; |
2395 | 39 | report_implied_names(); | 89 | errors = report_lint_errors(); |
2396 | 90 | if (errors) { | ||
2397 | 91 | issues.push(errors); | ||
2398 | 92 | } | ||
2399 | 93 | implied = report_implied_names(); | ||
2400 | 94 | if (implied) { | ||
2401 | 95 | issues.push(implied); | ||
2402 | 96 | } | ||
2403 | 97 | Seed.print(issues.join('\n')); | ||
2404 | 40 | } | 98 | } |
2405 | 41 | } | 99 | } |
2406 | 42 | 100 | ||
2409 | 43 | 101 | lint_script(); | |
2408 | 44 | main(arguments[0]); | ||
2410 | 45 | 102 | ||
2411 | === modified file 'setup.py' (properties changed: -x to +x) | |||
2412 | --- setup.py 2011-04-16 15:32:48 +0000 | |||
2413 | +++ setup.py 2011-10-14 21:24:26 +0000 | |||
2414 | @@ -1,9 +1,26 @@ | |||
2415 | 1 | import subprocess | ||
2416 | 2 | |||
2417 | 1 | from distutils.core import setup | 3 | from distutils.core import setup |
2418 | 4 | from distutils.command.sdist import sdist | ||
2419 | 5 | |||
2420 | 6 | |||
2421 | 7 | class SignedSDistCommand(sdist): | ||
2422 | 8 | """Sign the source archive with a detached signature.""" | ||
2423 | 9 | |||
2424 | 10 | description = "Sign the source archive after it is generated." | ||
2425 | 11 | |||
2426 | 12 | def run(self): | ||
2427 | 13 | sdist.run(self) | ||
2428 | 14 | gpg_args = [ | ||
2429 | 15 | 'gpg', '--armor', '--sign', '--detach-sig', self.archive_files[0]] | ||
2430 | 16 | gpg = subprocess.Popen( | ||
2431 | 17 | gpg_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
2432 | 18 | gpg.communicate() | ||
2433 | 2 | 19 | ||
2434 | 3 | setup( | 20 | setup( |
2435 | 4 | name="pocketlint", | 21 | name="pocketlint", |
2436 | 5 | description="Pocket-lint a composite linter and style checker.", | 22 | description="Pocket-lint a composite linter and style checker.", |
2438 | 6 | version="0.5.13", | 23 | version="0.5.21", |
2439 | 7 | maintainer="Curtis C. Hovey", | 24 | maintainer="Curtis C. Hovey", |
2440 | 8 | maintainer_email="sinzui.is@verizon.net", | 25 | maintainer_email="sinzui.is@verizon.net", |
2441 | 9 | url="https://launchpad.net/pocket-lint", | 26 | url="https://launchpad.net/pocket-lint", |
2442 | @@ -17,4 +34,7 @@ | |||
2443 | 17 | 'pocketlint/contrib': ['fulljslint.js'], | 34 | 'pocketlint/contrib': ['fulljslint.js'], |
2444 | 18 | }, | 35 | }, |
2445 | 19 | scripts=['scripts/pocketlint'], | 36 | scripts=['scripts/pocketlint'], |
2446 | 37 | cmdclass={ | ||
2447 | 38 | 'signed_sdist': SignedSDistCommand, | ||
2448 | 39 | }, | ||
2449 | 20 | ) | 40 | ) |
It looks like debian/copyright needs updating at least for './pocketlint/ contrib/ cssccc. py', which is listed as "public domain", unlike the other files that are MIT.
The rest of it looks good to me.