From d22b970a0eac1cc360bc3313a544ea320fa1cfbf Mon Sep 17 00:00:00 2001 From: "dilmah@chromium.org" Date: Fri, 26 Aug 2011 13:53:49 +0000 Subject: [PATCH] Ignore C++ comments while checking for Singleton in headers. (without ignoring comments this check gives false positives on code like base/threading/thread_local.h) Review URL: http://codereview.chromium.org/7747023 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@98421 0039d316-1c4b-4281-b951-d872f2087c98 --- presubmit_canned_checks.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 137c37641..0b79fc00b 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1,4 +1,4 @@ -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -828,14 +828,17 @@ def _CheckConstNSObject(input_api, output_api, source_file_filter): def _CheckSingletonInHeaders(input_api, output_api, source_file_filter): """Checks to make sure no header files have |Singleton<|.""" - pattern = input_api.re.compile(r'Singleton<') + pattern = input_api.re.compile(r'Singleton\s*<') files = [] for f in input_api.AffectedSourceFiles(source_file_filter): if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): contents = input_api.ReadFile(f) - if pattern.search(contents): - files.append(f) + for line in contents.splitlines(False): + line = input_api.re.sub(r'//.*$', '', line) # Strip C++ comment. + if pattern.search(line): + files.append(f) + break if files: return [ output_api.PresubmitError(