summaryrefslogtreecommitdiff
path: root/buildscripts/lint.py
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2012-10-15 02:37:46 -0400
committerEliot Horowitz <eliot@10gen.com>2012-10-15 18:07:07 -0400
commitc4446255277ec3b8d15a89d340cbce37d5fb0019 (patch)
tree9063bde4f910747886ab33e3a410d54e04c34573 /buildscripts/lint.py
parenta8d20647d7f1a03b56ab422cda4169d9a1c59929 (diff)
downloadmongo-c4446255277ec3b8d15a89d340cbce37d5fb0019.tar.gz
move lint code to its own directory
Diffstat (limited to 'buildscripts/lint.py')
-rw-r--r--buildscripts/lint.py102
1 files changed, 102 insertions, 0 deletions
diff --git a/buildscripts/lint.py b/buildscripts/lint.py
new file mode 100644
index 00000000000..8b430e2dec7
--- /dev/null
+++ b/buildscripts/lint.py
@@ -0,0 +1,102 @@
+
+import sys
+import codecs
+
+import cpplint
+import utils
+
+
+def run_lint( prefix="src/mongo", 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
+ nudge.append( '-legal/copyright' ) # errors found: 65
+ 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
+ nudge.append( '-whitespace/indent' ) # errors found: 8
+ 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 = utils.getAllSourceFiles( prefix=prefix )
+ 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
+
+
+if __name__ == "__main__":
+ prefix = "src/mongo"
+ nudge = False
+
+ for arg in sys.argv[1:]:
+ if arg.startswith( "--" ):
+ arg = arg[2:]
+ if arg == "nudge":
+ nudge = True
+ else:
+ print( "unknown arg [%s]" % arg )
+ sys.exit(-1)
+ prefix = arg
+
+ if not run_lint( prefix, nudge ):
+ sys.exit(-1)