85 @type list |
85 @type list |
86 @return error code |
86 @return error code |
87 @rtype str |
87 @rtype str |
88 """ |
88 """ |
89 code = text.split(None, 1)[0] |
89 code = text.split(None, 1)[0] |
|
90 if self._ignore_code(code): |
|
91 return None |
|
92 |
90 errorCode = code[0] + "-" + code[1:] |
93 errorCode = code[0] + "-" + code[1:] |
91 if self._ignore_code(errorCode): |
|
92 return None |
|
93 |
94 |
94 if errorCode in self.counters: |
95 if errorCode in self.counters: |
95 self.counters[errorCode] += 1 |
96 self.counters[errorCode] += 1 |
96 else: |
97 else: |
97 self.counters[errorCode] = 1 |
98 self.counters[errorCode] = 1 |
447 else None |
448 else None |
448 ) |
449 ) |
449 |
450 |
450 if not errors: |
451 if not errors: |
451 if includeMessages: |
452 if includeMessages: |
452 select = [s.strip() for s in includeMessages.split(",") if s.strip()] |
453 selected = [s.strip() for s in includeMessages.split(",") if s.strip()] |
453 else: |
454 else: |
454 select = [] |
455 selected = [] |
455 if excludeMessages: |
456 if excludeMessages: |
456 ignore = [i.strip() for i in excludeMessages.split(",") if i.strip()] |
457 ignored = [i.strip() for i in excludeMessages.split(",") if i.strip()] |
457 else: |
458 else: |
458 ignore = [] |
459 ignored = [] |
459 |
460 |
460 syntaxError, syntaxStats, tree = __checkSyntax(filename, source) |
461 syntaxError, syntaxStats, tree = __checkSyntax(filename, source) |
461 |
462 |
462 # perform the checks only, if syntax is ok and AST tree was generated |
463 # perform the checks only, if syntax is ok and AST tree was generated |
463 if tree: |
464 if tree: |
466 for includeMessage in includeMessages.split(","): |
467 for includeMessage in includeMessages.split(","): |
467 category = includeMessage.strip().split("-", 1)[0] |
468 category = includeMessage.strip().split("-", 1)[0] |
468 enabledCategories.add(category) |
469 enabledCategories.add(category) |
469 |
470 |
470 # check coding style |
471 # check coding style |
471 pycodestyle.BLANK_LINES_CONFIG = { |
472 if "E" in enabledCategories or "W" in enabledCategories: |
472 # Top level class and function. |
473 pycodestyle.BLANK_LINES_CONFIG = { |
473 "top_level": blankLines[0], |
474 # Top level class and function. |
474 # Methods and nested class and function. |
475 "top_level": blankLines[0], |
475 "method": blankLines[1], |
476 # Methods and nested class and function. |
476 } |
477 "method": blankLines[1], |
477 styleGuide = pycodestyle.StyleGuide( |
478 } |
478 reporter=CodeStyleCheckerReport, |
479 styleGuide = pycodestyle.StyleGuide( |
479 repeat=repeatMessages, |
480 reporter=CodeStyleCheckerReport, |
480 select=[], |
481 repeat=repeatMessages, |
481 ignore=[x for x in ignore if x.startswith(("E", "W"))], |
482 select=[ |
482 max_line_length=maxLineLength, |
483 x.replace("-", "", 1) # change to pycodestyle error codes |
483 max_doc_length=maxDocLineLength, |
484 for x in selected |
484 hang_closing=hangClosing, |
485 if x.startswith(("E-", "W-")) |
485 ) |
486 ], |
486 report = styleGuide.options.report |
487 ignore=[ |
487 styleGuide.input_file(filename, lines=source) |
488 x.replace("-", "", 1) # change to pycodestyle error codes |
488 stats.update(report.counters) |
489 for x in ignored |
489 errors += report.errors |
490 if x.startswith(("E-", "W-")) |
|
491 ], |
|
492 max_line_length=maxLineLength, |
|
493 max_doc_length=maxDocLineLength, |
|
494 hang_closing=hangClosing, |
|
495 ) |
|
496 report = styleGuide.options.report |
|
497 styleGuide.input_file(filename, lines=source) |
|
498 stats.update(report.counters) |
|
499 errors += report.errors |
490 |
500 |
491 # check documentation style |
501 # check documentation style |
492 if DocStyleChecker.Category in enabledCategories: |
502 if DocStyleChecker.Category in enabledCategories: |
493 docStyleChecker = DocStyleChecker( |
503 docStyleChecker = DocStyleChecker( |
494 source, |
504 source, |
495 filename, |
505 filename, |
496 select, |
506 selected, |
497 ignore, |
507 ignored, |
498 [], |
508 [], |
499 repeatMessages, |
509 repeatMessages, |
500 maxLineLength=maxDocLineLength, |
510 maxLineLength=maxDocLineLength, |
501 docType=docType, |
511 docType=docType, |
502 ) |
512 ) |
521 errors += miscellaneousChecker.errors |
531 errors += miscellaneousChecker.errors |
522 |
532 |
523 # check code complexity |
533 # check code complexity |
524 if ComplexityChecker.Category in enabledCategories: |
534 if ComplexityChecker.Category in enabledCategories: |
525 complexityChecker = ComplexityChecker( |
535 complexityChecker = ComplexityChecker( |
526 source, filename, tree, select, ignore, codeComplexityArgs |
536 source, filename, tree, selected, ignored, codeComplexityArgs |
527 ) |
537 ) |
528 complexityChecker.run() |
538 complexityChecker.run() |
529 stats.update(complexityChecker.counters) |
539 stats.update(complexityChecker.counters) |
530 errors += complexityChecker.errors |
540 errors += complexityChecker.errors |
531 |
541 |
562 errors += securityChecker.errors |
572 errors += securityChecker.errors |
563 |
573 |
564 # check for pathlib usage |
574 # check for pathlib usage |
565 if PathlibChecker.Category in enabledCategories: |
575 if PathlibChecker.Category in enabledCategories: |
566 pathlibChecker = PathlibChecker( |
576 pathlibChecker = PathlibChecker( |
567 source, filename, tree, select, ignore, [], repeatMessages |
577 source, filename, tree, selected, ignored, [], repeatMessages |
568 ) |
578 ) |
569 pathlibChecker.run() |
579 pathlibChecker.run() |
570 stats.update(pathlibChecker.counters) |
580 stats.update(pathlibChecker.counters) |
571 errors += pathlibChecker.errors |
581 errors += pathlibChecker.errors |
572 |
582 |
573 # check for code simplifications |
583 # check for code simplifications |
574 if SimplifyChecker.Category in enabledCategories: |
584 if SimplifyChecker.Category in enabledCategories: |
575 simplifyChecker = SimplifyChecker( |
585 simplifyChecker = SimplifyChecker( |
576 source, filename, tree, select, ignore, [], repeatMessages |
586 source, filename, tree, selected, ignored, [], repeatMessages |
577 ) |
587 ) |
578 simplifyChecker.run() |
588 simplifyChecker.run() |
579 stats.update(simplifyChecker.counters) |
589 stats.update(simplifyChecker.counters) |
580 errors += simplifyChecker.errors |
590 errors += simplifyChecker.errors |
581 |
591 |