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

Unified Diff: PRESUBMIT.py

Issue 1993243002: ⛲ Add presubmit to prevent SharedPreferences misuse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add suppression for ContextUtils. Created 4 years, 7 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
Index: PRESUBMIT.py
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 10f1fd004897a37a746cb07c6b31d5e176163282..ff8e11dfa742292f17d3a3e3a67a829808dfdc7f 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -25,6 +25,7 @@ _EXCLUDED_PATHS = (
r"^chrome[\\\/]browser[\\\/]resources[\\\/]pdf[\\\/]index.js",
)
+
# The NetscapePlugIn library is excluded from pan-project as it will soon
# be deleted together with the rest of the NPAPI and it's not worthwhile to
# update the coding style until then.
@@ -32,10 +33,12 @@ _TESTRUNNER_PATHS = (
r"^content[\\\/]shell[\\\/]tools[\\\/]plugin[\\\/].*",
)
+
# Fragment of a regular expression that matches C++ and Objective-C++
# implementation files.
_IMPLEMENTATION_EXTENSIONS = r'\.(cc|cpp|cxx|mm)$'
+
# Regular expression that matches code only used for test binaries
# (best effort).
_TEST_CODE_EXCLUDED_PATHS = (
@@ -55,6 +58,7 @@ _TEST_CODE_EXCLUDED_PATHS = (
r'testing[\\\/]iossim[\\\/]iossim\.mm$',
)
+
_TEST_ONLY_WARNING = (
'You might be calling functions intended only for testing from\n'
'production code. It is OK to ignore this warning if you know what\n'
@@ -67,6 +71,7 @@ _INCLUDE_ORDER_WARNING = (
'collation (LC_COLLATE=C) and check\nhttps://google.github.io/styleguide/'
'cppguide.html#Names_and_Order_of_Includes')
+
_BANNED_OBJC_FUNCTIONS = (
(
'addTrackingRect:',
@@ -291,6 +296,7 @@ _BANNED_CPP_FUNCTIONS = (
),
)
+
_IPC_ENUM_TRAITS_DEPRECATED = (
'You are using IPC_ENUM_TRAITS() in your code. It has been deprecated.\n'
'See http://www.chromium.org/Home/chromium-security/education/security-tips-for-ipc')
@@ -322,10 +328,12 @@ _ANDROID_SPECIFIC_PYDEPS_FILES = [
'net/tools/testserver/testserver.pydeps',
]
+
_GENERIC_PYDEPS_FILES = [
'build/secondary/tools/swarming_client/isolate.pydeps',
]
+
_ALL_PYDEPS_FILES = _ANDROID_SPECIFIC_PYDEPS_FILES + _GENERIC_PYDEPS_FILES
@@ -491,6 +499,7 @@ def _CheckUmaHistogramChanges(input_api, output_api):
'been modified and the associated histogram name has no match in either '
'%s or the modifications of it:' % (histograms_xml_path), problems)]
+
def _CheckFlakyTestUsage(input_api, output_api):
"""Check that FlakyTest annotation is our own instead of the android one"""
pattern = input_api.re.compile(r'import android.test.FlakyTest;')
@@ -506,6 +515,7 @@ def _CheckFlakyTestUsage(input_api, output_api):
files)]
return []
+
def _CheckNoNewWStrings(input_api, output_api):
"""Checks to make sure we don't introduce use of wstrings."""
problems = []
@@ -566,51 +576,42 @@ def _CheckNoBannedFunctions(input_api, output_api):
warnings = []
errors = []
+ def IsBlacklisted(affected_file, blacklist):
+ local_path = affected_file.LocalPath()
+ for item in blacklist:
+ if input_api.re.match(item, local_path):
+ return True
+ return False
+
+ def CheckForMatch(affected_file, line_num, line, func_name, message, error):
+ matched = False
+ if func_name[0:1] == '/':
+ regex = func_name[1:]
+ if input_api.re.search(regex, line):
+ matched = True
+ elif func_name in line:
+ matched = True
+ if matched:
+ problems = warnings;
+ if error:
+ problems = errors;
+ problems.append(' %s:%d:' % (affected_file.LocalPath(), line_num))
+ for message_line in message:
+ problems.append(' %s' % message_line)
+
file_filter = lambda f: f.LocalPath().endswith(('.mm', '.m', '.h'))
for f in input_api.AffectedFiles(file_filter=file_filter):
for line_num, line in f.ChangedContents():
for func_name, message, error in _BANNED_OBJC_FUNCTIONS:
- matched = False
- if func_name[0:1] == '/':
- regex = func_name[1:]
- if input_api.re.search(regex, line):
- matched = True
- elif func_name in line:
- matched = True
- if matched:
- problems = warnings;
- if error:
- problems = errors;
- problems.append(' %s:%d:' % (f.LocalPath(), line_num))
- for message_line in message:
- problems.append(' %s' % message_line)
+ CheckForMatch(f, line_num, line, func_name, message, error)
file_filter = lambda f: f.LocalPath().endswith(('.cc', '.mm', '.h'))
for f in input_api.AffectedFiles(file_filter=file_filter):
for line_num, line in f.ChangedContents():
for func_name, message, error, excluded_paths in _BANNED_CPP_FUNCTIONS:
- def IsBlacklisted(affected_file, blacklist):
- local_path = affected_file.LocalPath()
- for item in blacklist:
- if input_api.re.match(item, local_path):
- return True
- return False
if IsBlacklisted(f, excluded_paths):
continue
- matched = False
- if func_name[0:1] == '/':
- regex = func_name[1:]
- if input_api.re.search(regex, line):
- matched = True
- elif func_name in line:
- matched = True
- if matched:
- problems = warnings;
- if error:
- problems = errors;
- problems.append(' %s:%d:' % (f.LocalPath(), line_num))
- for message_line in message:
- problems.append(' %s' % message_line)
+ CheckForMatch(f, line_num, line, func_name, message, error)
result = []
if (warnings):
@@ -1862,6 +1863,7 @@ def _CommonChecks(input_api, output_api):
results.extend(_CheckSingletonInHeaders(input_api, output_api))
results.extend(_CheckNoDeprecatedCompiledResourcesGYP(input_api, output_api))
results.extend(_CheckPydepsNeedsUpdating(input_api, output_api))
+ results.extend(_CheckJavaStyle(input_api, output_api))
if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
@@ -2085,7 +2087,6 @@ def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(_CommonChecks(input_api, output_api))
results.extend(_CheckValidHostsInDEPS(input_api, output_api))
- results.extend(_CheckJavaStyle(input_api, output_api))
results.extend(
input_api.canned_checks.CheckGNFormatted(input_api, output_api))
results.extend(_CheckUmaHistogramChanges(input_api, output_api))

Powered by Google App Engine
This is Rietveld 408576698