Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(581)

Unified Diff: presubmit_canned_checks.py

Issue 395022: - Add a presubmit check that lints C++ files (will submit CLs that... (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cpplint.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_canned_checks.py
===================================================================
--- presubmit_canned_checks.py (revision 32179)
+++ presubmit_canned_checks.py (working copy)
@@ -5,7 +5,6 @@
"""Generic presubmit checks that can be reused by other presubmit checks."""
-
### Description checks
def CheckChangeHasTestField(input_api, output_api):
@@ -76,6 +75,51 @@
return []
+def CheckChangeLintsClean(input_api, output_api, source_file_filter=None):
+ """Checks that all ".cc" and ".h" files pass cpplint.py."""
+ _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$')
+ result = []
+
+ # Initialize cpplint.
+ import cpplint
+ cpplint._cpplint_state.ResetErrorCounts()
+
+ # Justifications for each filter:
+ #
+ # - build/include : Too many; fix in the future.
+ # - build/include_order : Not happening; #ifdefed includes.
+ # - build/namespace : I'm surprised by how often we violate this rule.
+ # - readability/casting : Mistakes a whole bunch of function pointer.
+ # - runtime/int : Can be fixed long term; volume of errors too high
+ # - runtime/virtual : Broken now, but can be fixed in the future?
+ # - whitespace/braces : We have a lot of explicit scoping in chrome code.
+ cpplint._SetFilters("-build/include,-build/include_order,-build/namespace,"
+ "-readability/casting,-runtime/int,-runtime/virtual,"
+ "-whitespace/braces")
+
+ # We currently are more strict with normal code than unit tests; 4 and 5 are
+ # the verbosity level that would normally be passed to cpplint.py through
+ # --verbose=#. Hopefully, in the future, we can be more verbose.
+ files = [f.AbsoluteLocalPath() for f in
+ input_api.AffectedSourceFiles(source_file_filter)]
+ for file_name in files:
+ if _RE_IS_TEST.match(file_name):
+ level = 5
+ else:
+ level = 4
+
+ cpplint.ProcessFile(file_name, level)
+
+ if cpplint._cpplint_state.error_count > 0:
+ if input_api.is_committing:
+ res_type = output_api.PresubmitError
+ else:
+ res_type = output_api.PresubmitPromptWarning
+ result = [res_type("Changelist failed cpplint.py check.")]
+
+ return result
+
+
def CheckChangeHasNoCR(input_api, output_api, source_file_filter=None):
"""Checks no '\r' (CR) character is in any source files."""
cr_files = []
« no previous file with comments | « cpplint.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698