240 hold a list containing details about the error/ warnings |
240 hold a list containing details about the error/ warnings |
241 (file name, line number, column, codestring (only at syntax |
241 (file name, line number, column, codestring (only at syntax |
242 errors), the message, a list with arguments for the message) |
242 errors), the message, a list with arguments for the message) |
243 @rtype dict |
243 @rtype dict |
244 """ |
244 """ |
245 try: |
245 if codestring: |
246 # Check for VCS conflict markers |
246 try: |
247 for conflictMarkerRe in VcsConflictMarkerRegExpList: |
247 # Check for VCS conflict markers |
248 conflict = conflictMarkerRe.search(codestring) |
248 for conflictMarkerRe in VcsConflictMarkerRegExpList: |
249 if conflict is not None: |
249 conflict = conflictMarkerRe.search(codestring) |
250 start, i = conflict.span() |
250 if conflict is not None: |
251 lineindex = 1 + codestring.count("\n", 0, start) |
251 start, i = conflict.span() |
252 return [ |
252 lineindex = 1 + codestring.count("\n", 0, start) |
253 {"error": (filename, lineindex, 0, "", "VCS conflict marker found")} |
253 return [ |
254 ] |
254 { |
255 |
255 "error": ( |
256 if filename.endswith(".ptl"): |
256 filename, |
|
257 lineindex, |
|
258 0, |
|
259 "", |
|
260 "VCS conflict marker found", |
|
261 ) |
|
262 } |
|
263 ] |
|
264 |
|
265 if filename.endswith(".ptl"): |
|
266 try: |
|
267 import quixote.ptl_compile # __IGNORE_WARNING_I10__ |
|
268 except ImportError: |
|
269 return [ |
|
270 {"error": (filename, 0, 0, "", "Quixote plugin not found.")} |
|
271 ] |
|
272 template = quixote.ptl_compile.Template(codestring, filename) |
|
273 template.compile() |
|
274 else: |
|
275 module = builtins.compile( |
|
276 codestring, filename, "exec", ast.PyCF_ONLY_AST |
|
277 ) |
|
278 except SyntaxError as detail: |
|
279 index = 0 |
|
280 code = "" |
|
281 error = "" |
|
282 lines = traceback.format_exception_only(SyntaxError, detail) |
|
283 match = re.match( |
|
284 r'\s*File "(.+)", line (\d+)', lines[0].replace("<string>", filename) |
|
285 ) |
|
286 if match is not None: |
|
287 fn, line = match.group(1, 2) |
|
288 if lines[1].startswith("SyntaxError:"): |
|
289 error = re.match("SyntaxError: (.+)", lines[1]).group(1) |
|
290 else: |
|
291 code = re.match("(.+)", lines[1]).group(1) |
|
292 for seLine in lines[2:]: |
|
293 if seLine.startswith("SyntaxError:"): |
|
294 error = re.match("SyntaxError: (.+)", seLine).group(1) |
|
295 elif seLine.rstrip().endswith("^"): |
|
296 index = len(seLine.rstrip()) - 4 |
|
297 else: |
|
298 fn = detail.filename |
|
299 line = detail.lineno or 1 |
|
300 error = detail.msg |
|
301 return [{"error": (fn, int(line), index, code.strip(), error)}] |
|
302 except ValueError as detail: |
257 try: |
303 try: |
258 import quixote.ptl_compile # __IGNORE_WARNING_I10__ |
304 fn = detail.filename |
259 except ImportError: |
305 line = detail.lineno |
260 return [{"error": (filename, 0, 0, "", "Quixote plugin not found.")}] |
306 error = detail.msg |
261 template = quixote.ptl_compile.Template(codestring, filename) |
307 except AttributeError: |
262 template.compile() |
308 fn = filename |
263 else: |
309 line = 1 |
264 module = builtins.compile(codestring, filename, "exec", ast.PyCF_ONLY_AST) |
310 error = str(detail) |
265 except SyntaxError as detail: |
311 return [{"error": (fn, line, 0, "", error)}] |
266 index = 0 |
312 except Exception as detail: |
267 code = "" |
313 with contextlib.suppress(AttributeError): |
268 error = "" |
314 fn = detail.filename |
269 lines = traceback.format_exception_only(SyntaxError, detail) |
315 line = detail.lineno |
270 match = re.match( |
316 error = detail.msg |
271 r'\s*File "(.+)", line (\d+)', lines[0].replace("<string>", filename) |
317 return [{"error": (fn, line, 0, "", error)}] |
272 ) |
318 |
273 if match is not None: |
319 # pyflakes |
274 fn, line = match.group(1, 2) |
320 if not checkFlakes: |
275 if lines[1].startswith("SyntaxError:"): |
321 return [{}] |
276 error = re.match("SyntaxError: (.+)", lines[1]).group(1) |
322 |
277 else: |
323 results = [] |
278 code = re.match("(.+)", lines[1]).group(1) |
324 lines = codestring.splitlines() |
279 for seLine in lines[2:]: |
|
280 if seLine.startswith("SyntaxError:"): |
|
281 error = re.match("SyntaxError: (.+)", seLine).group(1) |
|
282 elif seLine.rstrip().endswith("^"): |
|
283 index = len(seLine.rstrip()) - 4 |
|
284 else: |
|
285 fn = detail.filename |
|
286 line = detail.lineno or 1 |
|
287 error = detail.msg |
|
288 return [{"error": (fn, int(line), index, code.strip(), error)}] |
|
289 except ValueError as detail: |
|
290 try: |
325 try: |
291 fn = detail.filename |
326 warnings = Checker( |
292 line = detail.lineno |
327 module, filename, builtins=additionalBuiltins, withDoctest=True |
293 error = detail.msg |
328 ) |
294 except AttributeError: |
329 warnings.messages.sort(key=lambda a: a.lineno) |
295 fn = filename |
330 for warning in warnings.messages: |
296 line = 1 |
331 if ignoreStarImportWarnings and isinstance( |
297 error = str(detail) |
332 warning, (ImportStarUsed, ImportStarUsage) |
298 return [{"error": (fn, line, 0, "", error)}] |
333 ): |
299 except Exception as detail: |
334 continue |
300 with contextlib.suppress(AttributeError): |
335 |
301 fn = detail.filename |
336 _fn, lineno, col, message, msg_args = warning.getMessageData() |
302 line = detail.lineno |
337 lineFlags = extractLineFlags(lines[lineno - 1].strip()) |
303 error = detail.msg |
338 with contextlib.suppress(IndexError): |
304 return [{"error": (fn, line, 0, "", error)}] |
339 lineFlags += extractLineFlags(lines[lineno].strip(), flagsLine=True) |
305 |
340 if ( |
306 # pyflakes |
341 "__IGNORE_WARNING__" not in lineFlags |
307 if not checkFlakes: |
342 and "__IGNORE_FLAKES_WARNING__" not in lineFlags |
|
343 and "noqa" not in lineFlags |
|
344 ): |
|
345 results.append((_fn, lineno, col, "", message, msg_args)) |
|
346 except SyntaxError as err: |
|
347 msg = err.text.strip() if err.text.strip() else err.msg |
|
348 results.append((filename, err.lineno, 0, "FLAKES_ERROR", msg, [])) |
|
349 |
|
350 return [{"warnings": results}] |
|
351 |
|
352 else: |
308 return [{}] |
353 return [{}] |
309 |
|
310 results = [] |
|
311 lines = codestring.splitlines() |
|
312 try: |
|
313 warnings = Checker( |
|
314 module, filename, builtins=additionalBuiltins, withDoctest=True |
|
315 ) |
|
316 warnings.messages.sort(key=lambda a: a.lineno) |
|
317 for warning in warnings.messages: |
|
318 if ignoreStarImportWarnings and isinstance( |
|
319 warning, (ImportStarUsed, ImportStarUsage) |
|
320 ): |
|
321 continue |
|
322 |
|
323 _fn, lineno, col, message, msg_args = warning.getMessageData() |
|
324 lineFlags = extractLineFlags(lines[lineno - 1].strip()) |
|
325 with contextlib.suppress(IndexError): |
|
326 lineFlags += extractLineFlags(lines[lineno].strip(), flagsLine=True) |
|
327 if ( |
|
328 "__IGNORE_WARNING__" not in lineFlags |
|
329 and "__IGNORE_FLAKES_WARNING__" not in lineFlags |
|
330 and "noqa" not in lineFlags |
|
331 ): |
|
332 results.append((_fn, lineno, col, "", message, msg_args)) |
|
333 except SyntaxError as err: |
|
334 msg = err.text.strip() if err.text.strip() else err.msg |
|
335 results.append((filename, err.lineno, 0, "FLAKES_ERROR", msg, [])) |
|
336 |
|
337 return [{"warnings": results}] |
|