125 |
122 |
126 # Work around Python < 2.6 behaviour, which does not generate NL after |
123 # Work around Python < 2.6 behaviour, which does not generate NL after |
127 # a comment which is on a line by itself. |
124 # a comment which is on a line by itself. |
128 COMMENT_WITH_NL = tokenize.generate_tokens(['#\n'].pop).send(None)[1] == '#\n' |
125 COMMENT_WITH_NL = tokenize.generate_tokens(['#\n'].pop).send(None)[1] == '#\n' |
129 |
126 |
130 |
|
131 ############################################################################## |
|
132 # Helper functions for translated and formatted messages |
|
133 ############################################################################## |
|
134 |
|
135 |
|
136 pep8_messages = { |
|
137 "E101": QT_TRANSLATE_NOOP("pep8", |
|
138 "indentation contains mixed spaces and tabs"), |
|
139 "E111": QT_TRANSLATE_NOOP("pep8", |
|
140 "indentation is not a multiple of four"), |
|
141 "E112": QT_TRANSLATE_NOOP("pep8", |
|
142 "expected an indented block"), |
|
143 "E113": QT_TRANSLATE_NOOP("pep8", |
|
144 "unexpected indentation"), |
|
145 "E121": QT_TRANSLATE_NOOP("pep8", |
|
146 "continuation line indentation is not a multiple of four"), |
|
147 "E122": QT_TRANSLATE_NOOP("pep8", |
|
148 "continuation line missing indentation or outdented"), |
|
149 "E123": QT_TRANSLATE_NOOP("pep8", |
|
150 "closing bracket does not match indentation of opening" |
|
151 " bracket's line"), |
|
152 "E124": QT_TRANSLATE_NOOP("pep8", |
|
153 "closing bracket does not match visual indentation"), |
|
154 "E125": QT_TRANSLATE_NOOP("pep8", |
|
155 "continuation line does not distinguish itself from next" |
|
156 " logical line"), |
|
157 "E126": QT_TRANSLATE_NOOP("pep8", |
|
158 "continuation line over-indented for hanging indent"), |
|
159 "E127": QT_TRANSLATE_NOOP("pep8", |
|
160 "continuation line over-indented for visual indent"), |
|
161 "E128": QT_TRANSLATE_NOOP("pep8", |
|
162 "continuation line under-indented for visual indent"), |
|
163 "E133": QT_TRANSLATE_NOOP("pep8", |
|
164 "closing bracket is missing indentation"), |
|
165 "W191": QT_TRANSLATE_NOOP("pep8", |
|
166 "indentation contains tabs"), |
|
167 "E201": QT_TRANSLATE_NOOP("pep8", |
|
168 "whitespace after '{0}'"), |
|
169 "E202": QT_TRANSLATE_NOOP("pep8", |
|
170 "whitespace before '{0}'"), |
|
171 "E203": QT_TRANSLATE_NOOP("pep8", |
|
172 "whitespace before '{0}'"), |
|
173 "E211": QT_TRANSLATE_NOOP("pep8", |
|
174 "whitespace before '{0}'"), |
|
175 "E221": QT_TRANSLATE_NOOP("pep8", |
|
176 "multiple spaces before operator"), |
|
177 "E222": QT_TRANSLATE_NOOP("pep8", |
|
178 "multiple spaces after operator"), |
|
179 "E223": QT_TRANSLATE_NOOP("pep8", |
|
180 "tab before operator"), |
|
181 "E224": QT_TRANSLATE_NOOP("pep8", |
|
182 "tab after operator"), |
|
183 "E225": QT_TRANSLATE_NOOP("pep8", |
|
184 "missing whitespace around operator"), |
|
185 "E226": QT_TRANSLATE_NOOP("pep8", |
|
186 "missing whitespace around arithmetic operator"), |
|
187 "E227": QT_TRANSLATE_NOOP("pep8", |
|
188 "missing whitespace around bitwise or shift operator"), |
|
189 "E228": QT_TRANSLATE_NOOP("pep8", |
|
190 "missing whitespace around modulo operator"), |
|
191 "E231": QT_TRANSLATE_NOOP("pep8", |
|
192 "missing whitespace after '{0}'"), |
|
193 "E241": QT_TRANSLATE_NOOP("pep8", |
|
194 "multiple spaces after '{0}'"), |
|
195 "E242": QT_TRANSLATE_NOOP("pep8", |
|
196 "tab after '{0}'"), |
|
197 "E251": QT_TRANSLATE_NOOP("pep8", |
|
198 "unexpected spaces around keyword / parameter equals"), |
|
199 "E261": QT_TRANSLATE_NOOP("pep8", |
|
200 "at least two spaces before inline comment"), |
|
201 "E262": QT_TRANSLATE_NOOP("pep8", |
|
202 "inline comment should start with '# '"), |
|
203 "E271": QT_TRANSLATE_NOOP("pep8", |
|
204 "multiple spaces after keyword"), |
|
205 "E272": QT_TRANSLATE_NOOP("pep8", |
|
206 "multiple spaces before keyword"), |
|
207 "E273": QT_TRANSLATE_NOOP("pep8", |
|
208 "tab after keyword"), |
|
209 "E274": QT_TRANSLATE_NOOP("pep8", |
|
210 "tab before keyword"), |
|
211 "W291": QT_TRANSLATE_NOOP("pep8", |
|
212 "trailing whitespace"), |
|
213 "W292": QT_TRANSLATE_NOOP("pep8", |
|
214 "no newline at end of file"), |
|
215 "W293": QT_TRANSLATE_NOOP("pep8", |
|
216 "blank line contains whitespace"), |
|
217 "E301": QT_TRANSLATE_NOOP("pep8", |
|
218 "expected 1 blank line, found 0"), |
|
219 "E302": QT_TRANSLATE_NOOP("pep8", |
|
220 "expected 2 blank lines, found {0}"), |
|
221 "E303": QT_TRANSLATE_NOOP("pep8", |
|
222 "too many blank lines ({0})"), |
|
223 "E304": QT_TRANSLATE_NOOP("pep8", |
|
224 "blank lines found after function decorator"), |
|
225 "W391": QT_TRANSLATE_NOOP("pep8", |
|
226 "blank line at end of file"), |
|
227 "E401": QT_TRANSLATE_NOOP("pep8", |
|
228 "multiple imports on one line"), |
|
229 "E501": QT_TRANSLATE_NOOP("pep8", |
|
230 "line too long ({0} > {1} characters)"), |
|
231 "E502": QT_TRANSLATE_NOOP("pep8", |
|
232 "the backslash is redundant between brackets"), |
|
233 "W601": QT_TRANSLATE_NOOP("pep8", |
|
234 ".has_key() is deprecated, use 'in'"), |
|
235 "W602": QT_TRANSLATE_NOOP("pep8", |
|
236 "deprecated form of raising exception"), |
|
237 "W603": QT_TRANSLATE_NOOP("pep8", |
|
238 "'<>' is deprecated, use '!='"), |
|
239 "W604": QT_TRANSLATE_NOOP("pep8", |
|
240 "backticks are deprecated, use 'repr()'"), |
|
241 "E701": QT_TRANSLATE_NOOP("pep8", |
|
242 "multiple statements on one line (colon)"), |
|
243 "E702": QT_TRANSLATE_NOOP("pep8", |
|
244 "multiple statements on one line (semicolon)"), |
|
245 "E703": QT_TRANSLATE_NOOP("pep8", |
|
246 "statement ends with a semicolon"), |
|
247 "E711": QT_TRANSLATE_NOOP("pep8", |
|
248 "comparison to {0} should be {1}"), |
|
249 "E712": QT_TRANSLATE_NOOP("pep8", |
|
250 "comparison to {0} should be {1}"), |
|
251 "E721": QT_TRANSLATE_NOOP("pep8", |
|
252 "do not compare types, use 'isinstance()'"), |
|
253 "E901": QT_TRANSLATE_NOOP("pep8", |
|
254 "{0}: {1}"), |
|
255 } |
|
256 |
|
257 pep8_messages_sample_args = { |
|
258 "E201": ["([{"], |
|
259 "E202": ["}])"], |
|
260 "E203": [",;:"], |
|
261 "E211": ["(["], |
|
262 "E231": [",;:"], |
|
263 "E241": [",;:"], |
|
264 "E242": [",;:"], |
|
265 "E302": [1], |
|
266 "E303": [3], |
|
267 "E501": [85, 79], |
|
268 "E711": ["None", "'if cond is None:'"], |
|
269 "E712": ["True", "'if cond is True:' or 'if cond:'"], |
|
270 "E901": ["SyntaxError", "Invalid Syntax"], |
|
271 } |
|
272 |
|
273 |
|
274 def getMessage(code, *args): |
|
275 """ |
|
276 Function to get a translated and formatted message for a given code. |
|
277 |
|
278 @param code message code (string) |
|
279 @param args arguments for a formatted message (list) |
|
280 @return translated and formatted message (string) |
|
281 """ |
|
282 if code in pep8_messages: |
|
283 args = [str(arg) for arg in args] |
|
284 return '@@'.join([code + ' ' + pep8_messages[code]] + args) |
|
285 else: |
|
286 return code + ' ' + QT_TRANSLATE_NOOP( |
|
287 "pep8", "no message for this code defined") |
|
288 |
127 |
289 ############################################################################## |
128 ############################################################################## |
290 # Plugins (check functions) for physical lines |
129 # Plugins (check functions) for physical lines |
291 ############################################################################## |
130 ############################################################################## |
292 |
131 |