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

Unified Diff: PRESUBMIT.py

Issue 10946004: Add a presubmit check for "? true : false". (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 months 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: PRESUBMIT.py
===================================================================
--- PRESUBMIT.py (revision 157289)
+++ PRESUBMIT.py (working copy)
@@ -377,6 +377,25 @@
return []
+def _CheckNoTrinaryTrueFalse(input_api, output_api):
+ """Checks to make sure we don't introduce use of foo ? true : false."""
+ problems = []
+ pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
+ for f in input_api.AffectedFiles():
+ if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
+ continue
+
+ for line_num, line in f.ChangedContents():
+ if pattern.match(line):
+ problems.append(' %s:%d' % (f.LocalPath(), line_num))
+
+ if not problems:
+ return []
+ return [output_api.PresubmitPromptWarning(
+ 'Please consider avoiding the "? true : false" pattern if possible.\n' +
+ '\n'.join(problems))]
+
+
def _CheckUnwantedDependencies(input_api, output_api):
"""Runs checkdeps on #include statements added in this
change. Breaking - rules is an error, breaking ! rules is a
@@ -466,6 +485,7 @@
results.extend(_CheckNoDEPSGIT(input_api, output_api))
results.extend(_CheckNoBannedFunctions(input_api, output_api))
results.extend(_CheckNoPragmaOnce(input_api, output_api))
+ results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
results.extend(_CheckUnwantedDependencies(input_api, output_api))
results.extend(_CheckFilePermissions(input_api, output_api))
return results
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698