##// END OF EJS Templates
contrib: factor out actual error check for file data of check-code.py...
FUJIWARA Katsunori -
r41989:7a139fc6 default
parent child Browse files
Show More
@@ -635,7 +635,6 b' def checkfile(f, logfunc=_defaultlogger.'
635
635
636 return True if no error is found, False otherwise.
636 return True if no error is found, False otherwise.
637 """
637 """
638 blamecache = None
639 result = True
638 result = True
640
639
641 try:
640 try:
@@ -649,11 +648,12 b' def checkfile(f, logfunc=_defaultlogger.'
649 print("Skipping %s, %s" % (f, str(e).split(':', 1)[0]))
648 print("Skipping %s, %s" % (f, str(e).split(':', 1)[0]))
650 return result
649 return result
651
650
651 # context information shared while single checkfile() invocation
652 context = {'blamecache': None}
653
652 for name, match, magic, filters, pats in checks:
654 for name, match, magic, filters, pats in checks:
653 post = pre # discard filtering result of previous check
654 if debug:
655 if debug:
655 print(name, f)
656 print(name, f)
656 fc = 0
657 if not (re.match(match, f) or (magic and re.search(magic, pre))):
657 if not (re.match(match, f) or (magic and re.search(magic, pre))):
658 if debug:
658 if debug:
659 print("Skipping %s for %s it doesn't match %s" % (
659 print("Skipping %s for %s it doesn't match %s" % (
@@ -668,6 +668,42 b' def checkfile(f, logfunc=_defaultlogger.'
668 # tests/test-check-code.t
668 # tests/test-check-code.t
669 print("Skipping %s it has no-che?k-code (glob)" % f)
669 print("Skipping %s it has no-che?k-code (glob)" % f)
670 return "Skip" # skip checking this file
670 return "Skip" # skip checking this file
671
672 if not _checkfiledata(name, f, pre, filters, pats, context,
673 logfunc, maxerr, warnings, blame, debug, lineno):
674 result = False
675
676 return result
677
678 def _checkfiledata(name, f, filedata, filters, pats, context,
679 logfunc, maxerr, warnings, blame, debug, lineno):
680 """Execute actual error check for file data
681
682 :name: of the checking category
683 :f: filepath
684 :filedata: content of a file
685 :filters: to be applied before checking
686 :pats: to detect errors
687 :context: a dict of information shared while single checkfile() invocation
688 Valid keys: 'blamecache'.
689 :logfunc: function used to report error
690 logfunc(filename, linenumber, linecontent, errormessage)
691 :maxerr: number of error to display before aborting, or False to
692 report all errors
693 :warnings: whether warning level checks should be applied
694 :blame: whether blame information should be displayed at error reporting
695 :debug: whether debug information should be displayed
696 :lineno: whether lineno should be displayed at error reporting
697
698 return True if no error is found, False otherwise.
699 """
700 blamecache = context['blamecache']
701
702 fc = 0
703 pre = post = filedata
704 result = True
705
706 if True: # TODO: get rid of this redundant 'if' block
671 for p, r in filters:
707 for p, r in filters:
672 post = re.sub(p, r, post)
708 post = re.sub(p, r, post)
673 nerrs = len(pats[0]) # nerr elements are errors
709 nerrs = len(pats[0]) # nerr elements are errors
@@ -715,8 +751,9 b' def checkfile(f, logfunc=_defaultlogger.'
715 bd = ""
751 bd = ""
716 if blame:
752 if blame:
717 bd = 'working directory'
753 bd = 'working directory'
718 if not blamecache:
754 if blamecache is None:
719 blamecache = getblame(f)
755 blamecache = getblame(f)
756 context['blamecache'] = blamecache
720 if n < len(blamecache):
757 if n < len(blamecache):
721 bl, bu, br = blamecache[n]
758 bl, bu, br = blamecache[n]
722 if bl == l:
759 if bl == l:
General Comments 0
You need to be logged in to leave comments. Login now