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

Unified Diff: PRESUBMIT.py

Issue 98143005: Adds PRESUBMIT.py check to look for unprefixed string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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 | PRESUBMIT_test.py » ('j') | 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 e4db30215d9063d9874a696a26c4516e4f8c8738..bd31ff1673d17e9d8b5ec8e9d69c4545d1ceb48e 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -1026,6 +1026,7 @@ def _CommonChecks(input_api, output_api):
results.extend(_CheckForAnonymousVariables(input_api, output_api))
results.extend(_CheckCygwinShell(input_api, output_api))
results.extend(_CheckJavaStyle(input_api, output_api))
+ results.extend(_CheckForString16(input_api, output_api))
if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
@@ -1168,6 +1169,35 @@ def _CheckForInvalidOSMacros(input_api, output_api):
'or add your macro to src/PRESUBMIT.py.', bad_macros)]
+def _CheckForString16InFile(input_api, f):
+ """Check for string16 without base:: in front."""
+ reg = input_api.re.compile(r'\b(?<!base::)string16\b')
+ use = 'using base::string16;'
+ include = '#include "base/strings/string16.h"'
+ results = []
+ for lnum, line in f.ChangedContents():
+ if reg.search(line) and not include in line and not use in f.NewContents():
+ results.append(' %s:%d' % (f.LocalPath(), lnum))
+ return results
+
+
+def _CheckForString16(input_api, output_api):
+ file_filter = lambda f: input_api.FilterSourceFile(f,
+ white_list=(r'^chrome[\\\/]browser[\\\/]', ),
+ black_list=(_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS +
+ input_api.DEFAULT_BLACK_LIST))
+
+ unprefixed = []
+ for f in input_api.AffectedFiles(file_filter=file_filter):
+ unprefixed.extend(_CheckForString16InFile(input_api, f))
+
+ if not unprefixed:
+ return []
+
+ return [output_api.PresubmitPromptWarning(
+ 'string16 should be prefixed with base:: namespace.', unprefixed)]
+
+
def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_CommonChecks(input_api, output_api))
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698