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

Unified Diff: PRESUBMIT.py

Issue 1407033004: Presubmit enforce that DCHECK_IS_ON() does not forget the braces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: presubmit: . Created 5 years, 2 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
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index e3ee9c4715bcf7cbc50c56129abb3f91ac142b0d..293d9dd3eeeb73a07bd2fd0de6ac67a2bd825d90 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -358,7 +358,7 @@ def _CheckNoIOStreamInHeaders(input_api, output_api):
def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
- """Checks to make sure no source files use UNIT_TEST"""
+ """Checks to make sure no source files use UNIT_TEST."""
problems = []
for f in input_api.AffectedFiles():
if (not f.LocalPath().endswith(('.cc', '.mm'))):
@@ -374,6 +374,23 @@ def _CheckNoUNIT_TESTInSourceFiles(input_api, output_api):
'\n'.join(problems))]
+def _CheckDCHECK_IS_ONHasBraces(input_api, output_api):
+ """Checks to make sure DCHECK_IS_ON() does not skip the braces."""
+ errors = []
+ pattern = input_api.re.compile(r'DCHECK_IS_ON(?!\(\))',
+ input_api.re.MULTILINE)
+ for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
+ if (not f.LocalPath().endswith(('.cc', '.mm', '.h'))):
+ continue
+ for lnum, line in f.ChangedContents():
+ if input_api.re.search(pattern, line):
+ errors.append(output_api.PresubmitError(
+ ('%s:%d: Use of DCHECK_IS_ON() must be written as "#if ' +
danakj 2015/10/23 21:53:42 The error is nicer now too :)
+ 'DCHECK_IS_ON()", not forgetting the braces.')
kjellander_chromium 2017/02/20 07:09:48 Shouldn't 'braces' be replaced by 'parentheses' or
danakj 2017/02/22 00:19:54 You can submit a CL to fix it if you want :)
+ % (f.LocalPath(), lnum)))
+ return errors
+
+
def _FindHistogramNameInLine(histogram_name, line):
"""Tries to find a histogram name or prefix in a line."""
if not "affected-histogram" in line:
@@ -1640,6 +1657,7 @@ def _CommonChecks(input_api, output_api):
_CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
+ results.extend(_CheckDCHECK_IS_ONHasBraces(input_api, output_api))
results.extend(_CheckNoNewWStrings(input_api, output_api))
results.extend(_CheckNoDEPSGIT(input_api, output_api))
results.extend(_CheckNoBannedFunctions(input_api, output_api))
« 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