contrib/check-code.py
changeset 41824 519b2faea261
parent 41823 7a139fc60eb0
child 41825 6d6bd9039ecd
equal deleted inserted replaced
41823:7a139fc60eb0 41824:519b2faea261
   667             # spelling, we write it with the expected spelling from
   667             # spelling, we write it with the expected spelling from
   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 
   671 
   672         if not _checkfiledata(name, f, pre, filters, pats, context,
   672         fc = _checkfiledata(name, f, pre, filters, pats, context,
   673                               logfunc, maxerr, warnings, blame, debug, lineno):
   673                             logfunc, maxerr, warnings, blame, debug, lineno)
       
   674         if fc:
   674             result = False
   675             result = False
   675 
   676 
   676     return result
   677     return result
   677 
   678 
   678 def _checkfiledata(name, f, filedata, filters, pats, context,
   679 def _checkfiledata(name, f, filedata, filters, pats, context,
   693     :warnings: whether warning level checks should be applied
   694     :warnings: whether warning level checks should be applied
   694     :blame: whether blame information should be displayed at error reporting
   695     :blame: whether blame information should be displayed at error reporting
   695     :debug: whether debug information should be displayed
   696     :debug: whether debug information should be displayed
   696     :lineno: whether lineno should be displayed at error reporting
   697     :lineno: whether lineno should be displayed at error reporting
   697 
   698 
   698     return True if no error is found, False otherwise.
   699     returns number of detected errors.
   699     """
   700     """
   700     blamecache = context['blamecache']
   701     blamecache = context['blamecache']
   701 
   702 
   702     fc = 0
   703     fc = 0
   703     pre = post = filedata
   704     pre = post = filedata
   704     result = True
       
   705 
   705 
   706     if True: # TODO: get rid of this redundant 'if' block
   706     if True: # TODO: get rid of this redundant 'if' block
   707         for p, r in filters:
   707         for p, r in filters:
   708             post = re.sub(p, r, post)
   708             post = re.sub(p, r, post)
   709         nerrs = len(pats[0]) # nerr elements are errors
   709         nerrs = len(pats[0]) # nerr elements are errors
   758                         bl, bu, br = blamecache[n]
   758                         bl, bu, br = blamecache[n]
   759                         if bl == l:
   759                         if bl == l:
   760                             bd = '%s@%s' % (bu, br)
   760                             bd = '%s@%s' % (bu, br)
   761 
   761 
   762                 errors.append((f, lineno and n + 1, l, msg, bd))
   762                 errors.append((f, lineno and n + 1, l, msg, bd))
   763                 result = False
       
   764 
   763 
   765         errors.sort()
   764         errors.sort()
   766         for e in errors:
   765         for e in errors:
   767             logfunc(*e)
   766             logfunc(*e)
   768             fc += 1
   767             fc += 1
   769             if maxerr and fc >= maxerr:
   768             if maxerr and fc >= maxerr:
   770                 print(" (too many errors, giving up)")
   769                 print(" (too many errors, giving up)")
   771                 break
   770                 break
   772 
   771 
   773     return result
   772     return fc
   774 
   773 
   775 def main():
   774 def main():
   776     parser = optparse.OptionParser("%prog [options] [files | -]")
   775     parser = optparse.OptionParser("%prog [options] [files | -]")
   777     parser.add_option("-w", "--warnings", action="store_true",
   776     parser.add_option("-w", "--warnings", action="store_true",
   778                       help="include warning-level checks")
   777                       help="include warning-level checks")