def go( boost_root ): OUTPUT = "src/third_party/boost" if os.path.exists( OUTPUT ): shutil.rmtree( OUTPUT ) cmd = [ "bcp" , "--scan" , "--boost=%s" % boost_root ] src = utils.getAllSourceFiles() cmd += src cmd.append( OUTPUT ) if not os.path.exists( OUTPUT ): os.makedirs( OUTPUT ) res = utils.execsys( cmd ) out = open( OUTPUT + "/bcp-out.txt" , 'w' ) out.write( res[0] ) out.close() out = open( OUTPUT + "/notes.txt" , 'w' ) out.write( "command: " + " ".join( cmd ) ) out.close() print( res[1] )
def readErrorCodes( callback, replaceZero = False ): quick = [ "assert" , "Exception" , "verify" ] ps = [ re.compile( "(([umsgf]asser(t|ted))) *\(( *)(\d+)" ) , re.compile( "((User|Msg|MsgAssertion)Exceptio(n))\(( *)(\d+)" ) , re.compile( "(((verify))) *\(( *)(\d+)" ) ] for x in utils.getAllSourceFiles(): needReplace = [False] lines = [] lastCodes = [0] lineNum = 1 for line in open( x ): found = False for zz in quick: if line.find( zz ) >= 0: found = True break if found: for p in ps: def repl( m ): m = m.groups() start = m[0] spaces = m[3] code = m[4] if code == '0' and replaceZero : code = getNextCode( lastCodes ) lastCodes.append( code ) code = str( code ) needReplace[0] = True print( "Adding code " + code + " to line " + x + ":" + str( lineNum ) ) else : codes.append( ( x , lineNum , line , code ) ) callback( x , lineNum , line , code ) return start + "(" + spaces + code line = re.sub( p, repl, line ) # end if ps loop if replaceZero : lines.append( line ) lineNum = lineNum + 1 if replaceZero and needReplace[0] : print( "Replacing file " + x ) of = open( x + ".tmp", 'w' ) of.write( "".join( lines ) ) of.close() os.remove(x) os.rename( x + ".tmp", x )
def go(boost_root): OUTPUT = "src/third_party/boost" if os.path.exists(OUTPUT): shutil.rmtree(OUTPUT) cmd = ["bcp", "--scan", "--boost=%s" % boost_root] src = utils.getAllSourceFiles() cmd += src cmd.append(OUTPUT) if not os.path.exists(OUTPUT): os.makedirs(OUTPUT) res = utils.execsys(cmd) out = open(OUTPUT + "/bcp-out.txt", 'w') out.write(res[0]) out.close() out = open(OUTPUT + "/notes.txt", 'w') out.write("command: " + " ".join(cmd)) out.close() print(res[1])
def parseSourceFiles(callback): """Walks MongoDB sourcefiles and invokes callback for each AssertLocation found.""" quick = ["assert", "Exception"] patterns = [ re.compile(r"[umsg]asser(?:t|ted)(?:NoTrace)? *\( *(\d+)"), re.compile(r"(?:User|Msg|MsgAssertion)Exception *\( *(\d+)"), re.compile( r"fassert(?:Failed)?(?:WithStatus)?(?:NoTrace)?(?:StatusOK)? *\( *(\d+)" ), ] bad = [re.compile(r"^\s*assert *\(")] for sourceFile in utils.getAllSourceFiles(): if not sourceFile.find("src/mongo/") >= 0: # Skip generated sources continue with open(sourceFile) as f: line_iterator = enumerate(f, 1) for (lineNum, line) in line_iterator: # See if we can skip regexes if not any([zz in line for zz in quick]): continue for b in bad: if b.search(line): msg = "Bare assert prohibited. Replace with [umwdf]assert" print("%s:%s: %s\n%s" % (sourceFile, lineNum, msg, line)) raise Exception(msg) # no more than one pattern should ever match matches = [x for x in [p.search(line) for p in patterns] if x] assert len(matches) <= 1, matches if matches: match = matches[0] code = match.group(1) span = match.span() # Advance to statement terminator iff not on this line lines = [line.strip()] if not isTerminated(lines): for (_lineNum, line) in line_iterator: lines.append(line.strip()) if isTerminated(lines): break thisLoc = AssertLocation(sourceFile, lineNum, lines, code) callback(thisLoc)
def readErrorCodes( callback ): ps = [ re.compile( "([umsg]asser(t|ted)) *\( *(\d+)" ) , re.compile( "(User|Msg)Exceptio(n)\( *(\d+)" ) ] for x in utils.getAllSourceFiles(): lineNum = 1 for line in open( x ): for p in ps: for m in p.findall( line ): codes.append( ( x , lineNum , line , m[2] ) ) callback( x , lineNum , line , m[2] ) lineNum = lineNum + 1
def parseSourceFiles(callback): """Walks MongoDB sourcefiles and invokes callback for each AssertLocation found.""" quick = ["assert", "Exception"] patterns = [ re.compile(r"(?:u|m(?:sg)?)asser(?:t|ted)(?:NoTrace)?\s*\(\s*(\d+)", re.MULTILINE), re.compile(r"(?:User|Msg|MsgAssertion)Exception\s*\(\s*(\d+)", re.MULTILINE), re.compile( r"fassert(?:Failed)?(?:WithStatus)?(?:NoTrace)?(?:StatusOK)?\s*\(\s*(\d+)", re.MULTILINE), ] bad = [re.compile(r"^\s*assert *\(")] for sourceFile in utils.getAllSourceFiles(): if not sourceFile.find("src/mongo/") >= 0: # Skip generated sources continue with open(sourceFile) as f: text = f.read() if not any([zz in text for zz in quick]): continue # TODO: move check for bad assert type to the linter. for b in bad: if b.search(text): msg = "Bare assert prohibited. Replace with [umwdf]assert" print("%s: %s" % (sourceFile, msg)) raise Exception(msg) splitlines = text.splitlines(True) line_offsets = [0] for line in splitlines: line_offsets.append(line_offsets[-1] + len(line)) matchiters = [p.finditer(text) for p in patterns] for matchiter in matchiters: for match in matchiter: code = match.group(1) span = match.span() thisLoc = AssertLocation( sourceFile, getLineForPosition(line_offsets, span[1]), text[span[0]:span[1]], code) callback(thisLoc)
def parseSourceFiles( callback ): """Walks MongoDB sourcefiles and invokes callback for each AssertLocation found.""" quick = [ "assert" , "Exception"] patterns = [ re.compile( r"[umsgf]asser(?:t|ted) *\( *(\d+)" ) , re.compile( r"(?:User|Msg|MsgAssertion)Exception *\( *(\d+)" ), re.compile( r"fassertFailed(?:NoTrace|WithStatus)? *\( *(\d+)" ) ] bad = [ re.compile( r"^\s*assert *\(" ) ] for sourceFile in utils.getAllSourceFiles(): if not sourceFile.find( "src/mongo/" ) >= 0: # Skip generated sources continue with open(sourceFile) as f: line_iterator = enumerate(f, 1) for (lineNum, line) in line_iterator: # See if we can skip regexes if not any([zz in line for zz in quick]): continue for b in bad: if b.search(line): print( "%s\n%d" % (sourceFile, line) ) msg = "Bare assert prohibited. Replace with [umwdf]assert" raise Exception(msg) # no more than one pattern should ever match matches = [x for x in [p.search(line) for p in patterns] if x] assert len(matches) <= 1, matches if matches: match = matches[0] code = match.group(1) span = match.span() # Advance to statement terminator iff not on this line lines = [line.strip()] if not isTerminated(lines): for (_lineNum, line) in line_iterator: lines.append(line.strip()) if isTerminated(lines): break thisLoc = AssertLocation(sourceFile, lineNum, lines, code) callback( thisLoc )
def readErrorCodes(callback): ps = [ re.compile("([umsg]asser(t|ted)) *\( *(\d+)"), re.compile("(User|Msg)Exceptio(n)\( *(\d+)") ] for x in utils.getAllSourceFiles(): lineNum = 1 for line in open(x): for p in ps: for m in p.findall(line): codes.append((x, lineNum, line, m[2])) callback(x, lineNum, line, m[2]) lineNum = lineNum + 1
def readErrorCodes(callback, replaceZero=False): ps = [ re.compile("(([umsg]asser(t|ted))) *\(( *)(\d+)"), re.compile("((User|Msg|MsgAssertion)Exceptio(n))\(( *)(\d+)"), re.compile("(((verify))) *\(( *)(\d+)") ] for x in utils.getAllSourceFiles(): needReplace = [False] lines = [] lastCodes = [0] lineNum = 1 for line in open(x): for p in ps: def repl(m): m = m.groups() start = m[0] spaces = m[3] code = m[4] if code == '0' and replaceZero: code = getNextCode(lastCodes) lastCodes.append(code) code = str(code) needReplace[0] = True print("Adding code " + code + " to line " + x + ":" + str(lineNum)) else: codes.append((x, lineNum, line, code)) callback(x, lineNum, line, code) return start + "(" + spaces + code line = re.sub(p, repl, line) if replaceZero: lines.append(line) lineNum = lineNum + 1 if replaceZero and needReplace[0]: print("Replacing file " + x) of = open(x + ".tmp", 'w') of.write("".join(lines)) of.close() os.remove(x) os.rename(x + ".tmp", x)
def parseSourceFiles( callback ): """Walks MongoDB sourcefiles and invokes callback for each AssertLocation found.""" quick = [ "assert" , "Exception"] patterns = [ re.compile( r"(?:u|m(?:sg)?)asser(?:t|ted)(?:NoTrace)?\s*\(\s*(\d+)", re.MULTILINE ) , re.compile( r"(?:User|Msg|MsgAssertion)Exception\s*\(\s*(\d+)", re.MULTILINE ), re.compile( r"fassert(?:Failed)?(?:WithStatus)?(?:NoTrace)?(?:StatusOK)?\s*\(\s*(\d+)", re.MULTILINE ), ] bad = [ re.compile( r"^\s*assert *\(" ) ] for sourceFile in utils.getAllSourceFiles(): if not sourceFile.find( "src/mongo/" ) >= 0: # Skip generated sources continue with open(sourceFile) as f: text = f.read() if not any([zz in text for zz in quick]): continue # TODO: move check for bad assert type to the linter. for b in bad: if b.search(text): msg = "Bare assert prohibited. Replace with [umwdf]assert" print( "%s: %s" % (sourceFile, msg) ) raise Exception(msg) splitlines = text.splitlines(True) line_offsets = [0] for line in splitlines: line_offsets.append(line_offsets[-1] + len(line)) matchiters = [p.finditer(text) for p in patterns] for matchiter in matchiters: for match in matchiter: code = match.group(1) span = match.span() thisLoc = AssertLocation(sourceFile, getLineForPosition(line_offsets, span[1]), text[span[0]:span[1]], code) callback( thisLoc )
def assignErrorCodes(): cur = 10000 for root in assertNames: for x in utils.getAllSourceFiles(): print( x ) didAnything = False fixed = "" for line in open( x ): s = line.partition( root + "(" ) if s[1] == "" or line.startswith( "#define " + root): fixed += line continue fixed += s[0] + root + "( " + str( cur ) + " , " + s[2] cur = cur + 1 didAnything = True if didAnything: out = open( x , 'w' ) out.write( fixed ) out.close()
def parseSourceFiles( callback ): """Walks MongoDB sourcefiles and invokes callback for each AssertLocation found.""" quick = [ "assert" , "Exception"] patterns = [ re.compile( r"(?:u|m(?:sg)?)asser(?:t|ted)(?:NoTrace)?\s*\(\s*(\d+)", re.MULTILINE ) , re.compile( r"(?:DB|Assertion)Exception\s*\(\s*(\d+)", re.MULTILINE ), re.compile( r"fassert(?:Failed)?(?:WithStatus)?(?:NoTrace)?(?:StatusOK)?\s*\(\s*(\d+)", re.MULTILINE ), ] bad = [ re.compile( r"^\s*assert *\(" ) ] for sourceFile in utils.getAllSourceFiles(prefix='src/mongo/'): if list_files: print 'scanning file: ' + sourceFile with open(sourceFile) as f: text = f.read() if not any([zz in text for zz in quick]): continue # TODO: move check for bad assert type to the linter. for b in bad: if b.search(text): msg = "Bare assert prohibited. Replace with [umwdf]assert" print( "%s: %s" % (sourceFile, msg) ) raise Exception(msg) matchiters = [p.finditer(text) for p in patterns] for matchiter in matchiters: for match in matchiter: code = match.group(1) span = match.span() thisLoc = AssertLocation(sourceFile, span[1], text[span[0]:span[1]], code) callback( thisLoc )
def parseSourceFiles(callback): """Walks MongoDB sourcefiles and invokes callback for each AssertLocation found.""" quick = ["assert", "Exception", "ErrorCodes::Error"] patterns = [ re.compile(r"(?:u|m(?:sg)?)asser(?:t|ted)(?:NoTrace)?\s*\(\s*(\d+)", re.MULTILINE), re.compile(r"(?:DB|Assertion)Exception\s*[({]\s*(\d+)", re.MULTILINE), re.compile( r"fassert(?:Failed)?(?:WithStatus)?(?:NoTrace)?(?:StatusOK)?\s*\(\s*(\d+)", re.MULTILINE), re.compile(r"ErrorCodes::Error\s*[({]\s*(\d+)", re.MULTILINE) ] for sourceFile in utils.getAllSourceFiles(prefix='src/mongo/'): if list_files: print 'scanning file: ' + sourceFile with open(sourceFile) as f: text = f.read() if not any([zz in text for zz in quick]): continue matchiters = [p.finditer(text) for p in patterns] for matchiter in matchiters: for match in matchiter: code = match.group(1) codeOffset = match.start(1) # Note that this will include the text of the full match but will report the # position of the beginning of the code portion rather than the beginning of the # match. This is to position editors on the spot that needs to change. thisLoc = AssertLocation(sourceFile, codeOffset, text[match.start():match.end()], code) callback(thisLoc)
def parseSourceFiles( callback ): """Walks MongoDB sourcefiles and invokes callback for each AssertLocation found.""" quick = ["assert", "Exception", "ErrorCodes::Error"] patterns = [ re.compile( r"(?:u|m(?:sg)?)asser(?:t|ted)(?:NoTrace)?\s*\(\s*(\d+)", re.MULTILINE ) , re.compile( r"(?:DB|Assertion)Exception\s*[({]\s*(\d+)", re.MULTILINE ), re.compile( r"fassert(?:Failed)?(?:WithStatus)?(?:NoTrace)?(?:StatusOK)?\s*\(\s*(\d+)", re.MULTILINE ), re.compile( r"ErrorCodes::Error\s*[({]\s*(\d+)", re.MULTILINE ) ] for sourceFile in utils.getAllSourceFiles(prefix='src/mongo/'): if list_files: print 'scanning file: ' + sourceFile with open(sourceFile) as f: text = f.read() if not any([zz in text for zz in quick]): continue matchiters = [p.finditer(text) for p in patterns] for matchiter in matchiters: for match in matchiter: code = match.group(1) codeOffset = match.start(1) # Note that this will include the text of the full match but will report the # position of the beginning of the code portion rather than the beginning of the # match. This is to position editors on the spot that needs to change. thisLoc = AssertLocation(sourceFile, codeOffset, text[match.start():match.end()], code) callback( thisLoc )
def readErrorCodes(): """Open each source file in sourceroot and scan for potential error messages.""" sys.stderr.write("Analyzing source tree: {}\n".format(sourceroot)) quick = [ "assert" , "Exception"] ps = [ re.compile( "(([wum]asser(t|ted))) *\(( *)(\d+) *,\s*(\"\S[^\"]+\S\")\s*,?.*" ) , re.compile( "(([wum]asser(t|ted))) *\(( *)(\d+) *,\s*([\S\s+<\(\)\"]+) *,?.*" ) , re.compile( '((msgasser(t|ted))) *\(( *)(\d+) *, *(\"\S[^,^\"]+\S\") *,?' ) , re.compile( '((msgasser(t|ted)NoTrace)) *\(( *)(\d+) *, *(\"\S[^,^\"]+\S\") *,?' ) , re.compile( "((fasser(t|ted))) *\(( *)(\d+)()" ) , re.compile( "((DB|User|Msg|MsgAssertion)Exceptio(n))\(( *)(\d+) *,? *(\S+.+\S) *,?" ), re.compile( "((fassertFailed)()) *\(( *)(\d+)()" ), re.compile( "(([wum]asser(t|ted)))\s*\(([^\d]*)(\d+)\s*,?()"), re.compile( "((msgasser(t|ted)))\s*\(([^\d]*)(\d+)\s*,?()"), re.compile( "((msgasser(t|ted)NoTrace))\s*\(([^\d]*)(\d+)\s*,?()"), ] bad = [ re.compile( "\sassert *\(" ) ] arr=[] for x in utils.getAllSourceFiles(arr,product_source): if (debug == True): sys.stderr.write("Analyzing: {}\n".format(x)) needReplace = [False] lines = [] lastCodes = [0] lineNum = 1 stripChars = " " + "\n" sourcerootOffset = len(sourceroot) for line in open( x ): found = False for zz in quick: if line.find( zz ) >= 0: found = True break if found: for p in ps: def repl( m ): m = m.groups() severity = m[0] start = m[0] spaces = m[3] code = m[4] message = m[5] codes.append( ( x , lineNum , line , code, message, severity ) ) if x.startswith(sourceroot): fn = x[sourcerootOffset+1:].rpartition("/2")[2] msgDICT = { 'id': code, 'parsed':message, 'message':message, 'assert':severity, 'severity': returnSeverityText(severity), 'uresp':'', 'sysresp':'', 'linenum':lineNum, 'file':fn, 'src': line.strip(stripChars), 'altered': 0 } messages[int(code)] = msgDICT return start + "(" + spaces + code line = re.sub( p, repl, line ) lineNum = lineNum + 1
def run_lint(paths, nudgeOn=False): # errors are as of 10/14 # idea is not to let it any new type of error # as we knock one out, we should remove line # note: not all of these are things we want, so please check first nudge = [] # things we'd like to turn on sson, so don't make worse later = [] # things that are unlikely anytime soon, so meh never = [] # things we totally disagree with nudge.append("-build/c++11") # errors found: 6 never.append("-build/header_guard") # errors found: 345 nudge.append("-build/include") # errors found: 924 nudge.append("-build/include_order") # errors found: 511 nudge.append("-build/include_what_you_use") # errors found: 986 nudge.append("-build/namespaces") # errors found: 131 never.append("-readability/braces") # errors found: 880 later.append("-readability/casting") # errors found: 748 nudge.append("-readability/check") # errors found: 7 nudge.append("-readability/function") # errors found: 49 nudge.append("-readability/inheritance") # errors found: 7 later.append("-readability/namespace") # errors found: 876 later.append("-readability/streams") # errors found: 72 later.append("-readability/todo") # errors found: 309 nudge.append("-runtime/arrays") # errors found: 5 later.append("-runtime/explicit") # errors found: 322 never.append("-runtime/indentation_namespace") # errors found: 4601 later.append("-runtime/int") # errors found: 1420 later.append("-runtime/printf") # errors found: 29 nudge.append("-runtime/references") # errors found: 1338 nudge.append("-runtime/string") # errors found: 6 nudge.append("-runtime/threadsafe_fn") # errors found: 46 never.append("-whitespace/blank_line") # errors found: 2080 never.append("-whitespace/braces") # errors found: 962 later.append("-whitespace/comma") # errors found: 621 later.append("-whitespace/comments") # errors found: 2189 nudge.append("-whitespace/empty_loop_body") # errors found: 19 later.append("-whitespace/end_of_line") # errors found: 4340 later.append("-whitespace/line_length") # errors found: 14500 never.append("-whitespace/indent") # errors found: 4108 later.append("-whitespace/newline") # errors found: 1520 nudge.append("-whitespace/operators") # errors found: 2297 never.append("-whitespace/parens") # errors found: 49058 nudge.append("-whitespace/semicolon") # errors found: 121 nudge.append("-whitespace/tab") # errors found: 233 filters = later + never if not nudgeOn: filters = filters + nudge sourceFiles = [] for x in paths: utils.getAllSourceFiles(sourceFiles, x) args = ["--linelength=100", "--filter=" + ",".join(filters), "--counting=detailed"] + sourceFiles filenames = cpplint.ParseArguments(args) def _ourIsTestFilename(fn): if fn.find("dbtests") >= 0: return True if fn.endswith("_test.cpp"): return True return False cpplint._IsTestFilename = _ourIsTestFilename # Change stderr to write with replacement characters so we don't die # if we try to print something containing non-ASCII characters. sys.stderr = codecs.StreamReaderWriter(sys.stderr, codecs.getreader("utf8"), codecs.getwriter("utf8"), "replace") cpplint._cpplint_state.ResetErrorCounts() for filename in filenames: config_h_check_obj = CheckForConfigH() cpplint.ProcessFile(filename, cpplint._cpplint_state.verbose_level, extra_check_functions=[config_h_check_obj]) cpplint._cpplint_state.PrintErrorCounts() return cpplint._cpplint_state.error_count == 0
def run_lint(paths, nudgeOn=False): # errors are as of 10/14 # idea is not to let it any new type of error # as we knock one out, we should remove line # note: not all of these are things we want, so please check first nudge = [] # things we'd like to turn on sson, so don't make worse later = [] # things that are unlikely anytime soon, so meh never = [] # things we totally disagree with never.append('-build/header_guard') # errors found: 345 nudge.append('-build/include') # errors found: 924 nudge.append('-build/include_order') # errors found: 511 nudge.append('-build/include_what_you_use') # errors found: 986 nudge.append('-build/namespaces') # errors found: 131 never.append('-readability/braces') # errors found: 880 later.append('-readability/casting') # errors found: 748 nudge.append('-readability/function') # errors found: 49 later.append('-readability/streams') # errors found: 72 later.append('-readability/todo') # errors found: 309 nudge.append('-runtime/arrays') # errors found: 5 later.append('-runtime/explicit') # errors found: 322 later.append('-runtime/int') # errors found: 1420 later.append('-runtime/printf') # errors found: 29 nudge.append('-runtime/references') # errors found: 1338 nudge.append('-runtime/rtti') # errors found: 36 nudge.append('-runtime/sizeof') # errors found: 57 nudge.append('-runtime/string') # errors found: 6 nudge.append('-runtime/threadsafe_fn') # errors found: 46 never.append('-whitespace/blank_line') # errors found: 2080 never.append('-whitespace/braces') # errors found: 962 later.append('-whitespace/comma') # errors found: 621 later.append('-whitespace/comments') # errors found: 2189 later.append('-whitespace/end_of_line') # errors found: 4340 later.append('-whitespace/labels') # errors found: 58 later.append('-whitespace/line_length') # errors found: 14500 later.append('-whitespace/newline') # errors found: 1520 nudge.append('-whitespace/operators') # errors found: 2297 never.append('-whitespace/parens') # errors found: 49058 nudge.append('-whitespace/semicolon') # errors found: 121 nudge.append('-whitespace/tab') # errors found: 233 filters = later + never if not nudgeOn: filters = filters + nudge sourceFiles = [] for x in paths: utils.getAllSourceFiles(sourceFiles, x) args = ["--filter=" + ",".join(filters), "--counting=detailed" ] + sourceFiles filenames = cpplint.ParseArguments(args) def _ourIsTestFilename(fn): if fn.find("dbtests") >= 0: return True if fn.endswith("_test.cpp"): return True return False cpplint._IsTestFilename = _ourIsTestFilename # Change stderr to write with replacement characters so we don't die # if we try to print something containing non-ASCII characters. sys.stderr = codecs.StreamReaderWriter(sys.stderr, codecs.getreader('utf8'), codecs.getwriter('utf8'), 'replace') cpplint._cpplint_state.ResetErrorCounts() for filename in filenames: cpplint.ProcessFile(filename, cpplint._cpplint_state.verbose_level) cpplint._cpplint_state.PrintErrorCounts() return cpplint._cpplint_state.error_count == 0
def readErrorCodes(callback, replaceZero=False): quick = ["assert", "Exception"] ps = [ re.compile("(([umsgf]asser(t|ted))) *\(( *)(\d+)"), re.compile("((User|Msg|MsgAssertion)Exceptio(n))\(( *)(\d+)"), re.compile("((fassertFailed)()) *\(( *)(\d+)") ] bad = [re.compile("\sassert *\(")] for x in utils.getAllSourceFiles(): needReplace = [False] lines = [] lastCodes = [0] lineNum = 1 for line in open(x): found = False for zz in quick: if line.find(zz) >= 0: found = True break if found: if x.find("src/mongo/") >= 0: for b in bad: if len(b.findall(line)) > 0: print(x) print(line) raise Exception("you can't use a bare assert") for p in ps: def repl(m): m = m.groups() start = m[0] spaces = m[3] code = m[4] if code == '0' and replaceZero: code = getNextCode(lastCodes) lastCodes.append(code) code = str(code) needReplace[0] = True print("Adding code " + code + " to line " + x + ":" + str(lineNum)) else: codes.append((x, lineNum, line, code)) callback(x, lineNum, line, code) return start + "(" + spaces + code line = re.sub(p, repl, line) # end if ps loop if replaceZero: lines.append(line) lineNum = lineNum + 1 if replaceZero and needReplace[0]: print("Replacing file " + x) of = open(x + ".tmp", 'w') of.write("".join(lines)) of.close() os.remove(x) os.rename(x + ".tmp", x)
def run_lint( paths, nudgeOn=False ): # errors are as of 10/14 # idea is not to let it any new type of error # as we knock one out, we should remove line # note: not all of these are things we want, so please check first nudge = [] # things we'd like to turn on sson, so don't make worse later = [] # things that are unlikely anytime soon, so meh never = [] # things we totally disagree with nudge.append( '-build/class' ) # errors found: 1 never.append( '-build/header_guard' ) # errors found: 345 nudge.append( '-build/include' ) # errors found: 924 nudge.append( '-build/include_order' ) # errors found: 511 nudge.append( '-build/include_what_you_use' ) # errors found: 986 nudge.append( '-build/namespaces' ) # errors found: 131 never.append( '-readability/braces' ) # errors found: 880 later.append( '-readability/casting' ) # errors found: 748 nudge.append( '-readability/function' ) # errors found: 49 later.append( '-readability/streams' ) # errors found: 72 later.append( '-readability/todo' ) # errors found: 309 nudge.append( '-runtime/arrays' ) # errors found: 5 nudge.append( '-runtime/casting' ) # errors found: 2 later.append( '-runtime/explicit' ) # errors found: 322 later.append( '-runtime/int' ) # errors found: 1420 later.append( '-runtime/printf' ) # errors found: 29 nudge.append( '-runtime/references' ) # errors found: 1338 nudge.append( '-runtime/rtti' ) # errors found: 36 nudge.append( '-runtime/sizeof' ) # errors found: 57 nudge.append( '-runtime/string' ) # errors found: 6 nudge.append( '-runtime/threadsafe_fn' ) # errors found: 46 never.append( '-whitespace/blank_line' ) # errors found: 2080 never.append( '-whitespace/braces' ) # errors found: 962 later.append( '-whitespace/comma' ) # errors found: 621 later.append( '-whitespace/comments' ) # errors found: 2189 later.append( '-whitespace/end_of_line' ) # errors found: 4340 later.append( '-whitespace/labels' ) # errors found: 58 later.append( '-whitespace/line_length' ) # errors found: 14500 later.append( '-whitespace/newline' ) # errors found: 1520 nudge.append( '-whitespace/operators' ) # errors found: 2297 never.append( '-whitespace/parens' ) # errors found: 49058 nudge.append( '-whitespace/semicolon' ) # errors found: 121 nudge.append( '-whitespace/tab' ) # errors found: 233 filters = later + never if not nudgeOn: filters = filters + nudge sourceFiles = [] for x in paths: utils.getAllSourceFiles( sourceFiles, x ) args = [ "--filter=" + ",".join( filters ) , "--counting=detailed" ] + sourceFiles filenames = cpplint.ParseArguments( args ) def _ourIsTestFilename(fn): if fn.find( "dbtests" ) >= 0: return True if fn.endswith( "_test.cpp" ): return True return False cpplint._IsTestFilename = _ourIsTestFilename # Change stderr to write with replacement characters so we don't die # if we try to print something containing non-ASCII characters. sys.stderr = codecs.StreamReaderWriter(sys.stderr, codecs.getreader('utf8'), codecs.getwriter('utf8'), 'replace') cpplint._cpplint_state.ResetErrorCounts() for filename in filenames: cpplint.ProcessFile(filename, cpplint._cpplint_state.verbose_level) cpplint._cpplint_state.PrintErrorCounts() return cpplint._cpplint_state.error_count == 0