##// END OF EJS Templates
contrib: add line offset information to file check function of check-code.py...
FUJIWARA Katsunori -
r41991:6d6bd903 default
parent child Browse files
Show More
@@ -677,7 +677,8 b' def checkfile(f, logfunc=_defaultlogger.'
677 return result
677 return result
678
678
679 def _checkfiledata(name, f, filedata, filters, pats, context,
679 def _checkfiledata(name, f, filedata, filters, pats, context,
680 logfunc, maxerr, warnings, blame, debug, lineno):
680 logfunc, maxerr, warnings, blame, debug, lineno,
681 offset=None):
681 """Execute actual error check for file data
682 """Execute actual error check for file data
682
683
683 :name: of the checking category
684 :name: of the checking category
@@ -695,10 +696,17 b' def _checkfiledata(name, f, filedata, fi'
695 :blame: whether blame information should be displayed at error reporting
696 :blame: whether blame information should be displayed at error reporting
696 :debug: whether debug information should be displayed
697 :debug: whether debug information should be displayed
697 :lineno: whether lineno should be displayed at error reporting
698 :lineno: whether lineno should be displayed at error reporting
699 :offset: line number offset of 'filedata' in 'f' for checking
700 an embedded code fragment, or None (offset=0 is different
701 from offset=None)
698
702
699 returns number of detected errors.
703 returns number of detected errors.
700 """
704 """
701 blamecache = context['blamecache']
705 blamecache = context['blamecache']
706 if offset is None:
707 lineoffset = 0
708 else:
709 lineoffset = offset
702
710
703 fc = 0
711 fc = 0
704 pre = post = filedata
712 pre = post = filedata
@@ -746,7 +754,7 b' def _checkfiledata(name, f, filedata, fi'
746 if ignore and re.search(ignore, l, re.MULTILINE):
754 if ignore and re.search(ignore, l, re.MULTILINE):
747 if debug:
755 if debug:
748 print("Skipping %s for %s:%s (ignore pattern)" % (
756 print("Skipping %s for %s:%s (ignore pattern)" % (
749 name, f, n))
757 name, f, (n + lineoffset)))
750 continue
758 continue
751 bd = ""
759 bd = ""
752 if blame:
760 if blame:
@@ -754,12 +762,22 b' def _checkfiledata(name, f, filedata, fi'
754 if blamecache is None:
762 if blamecache is None:
755 blamecache = getblame(f)
763 blamecache = getblame(f)
756 context['blamecache'] = blamecache
764 context['blamecache'] = blamecache
757 if n < len(blamecache):
765 if (n + lineoffset) < len(blamecache):
758 bl, bu, br = blamecache[n]
766 bl, bu, br = blamecache[(n + lineoffset)]
759 if bl == l:
767 if offset is None and bl == l:
760 bd = '%s@%s' % (bu, br)
768 bd = '%s@%s' % (bu, br)
769 elif offset is not None and bl.endswith(l):
770 # "offset is not None" means "checking
771 # embedded code fragment". In this case,
772 # "l" does not have information about the
773 # beginning of an *original* line in the
774 # file (e.g. ' > ').
775 # Therefore, use "str.endswith()", and
776 # show "maybe" for a little loose
777 # examination.
778 bd = '%s@%s, maybe' % (bu, br)
761
779
762 errors.append((f, lineno and n + 1, l, msg, bd))
780 errors.append((f, lineno and (n + lineoffset + 1), l, msg, bd))
763
781
764 errors.sort()
782 errors.sort()
765 for e in errors:
783 for e in errors:
General Comments 0
You need to be logged in to leave comments. Login now