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

Side by Side Diff: PRESUBMIT.py

Issue 2576253002: ES6 Style: add presubmit prompt about => in code that might run on iOS9 (Closed)
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | PRESUBMIT_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Top-level presubmit script for Chromium. 5 """Top-level presubmit script for Chromium.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools. 8 for more details about the presubmit API built into depot_tools.
9 """ 9 """
10 10
(...skipping 1907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 1918
1919 if files: 1919 if files:
1920 return [output_api.PresubmitError( 1920 return [output_api.PresubmitError(
1921 'Found base::Singleton<T> in the following header files.\n' + 1921 'Found base::Singleton<T> in the following header files.\n' +
1922 'Please move them to an appropriate source file so that the ' + 1922 'Please move them to an appropriate source file so that the ' +
1923 'template gets instantiated in a single compilation unit.', 1923 'template gets instantiated in a single compilation unit.',
1924 files) ] 1924 files) ]
1925 return [] 1925 return []
1926 1926
1927 1927
1928 def _CheckNoDeprecatedCompiledResourcesGYP(input_api, output_api): 1928 def _CheckNoDeprecatedCompiledResourcesGyp(input_api, output_api):
1929 """Checks for old style compiled_resources.gyp files.""" 1929 """Checks for old style compiled_resources.gyp files."""
1930 is_compiled_resource = lambda fp: fp.endswith('compiled_resources.gyp') 1930 is_compiled_resource = lambda fp: fp.endswith('compiled_resources.gyp')
1931 1931
1932 added_compiled_resources = filter(is_compiled_resource, [ 1932 added_compiled_resources = filter(is_compiled_resource, [
1933 f.LocalPath() for f in input_api.AffectedFiles() if f.Action() == 'A' 1933 f.LocalPath() for f in input_api.AffectedFiles() if f.Action() == 'A'
1934 ]) 1934 ])
1935 1935
1936 if not added_compiled_resources: 1936 if not added_compiled_resources:
1937 return [] 1937 return []
1938 1938
(...skipping 23 matching lines...) Expand all
1962 1962
1963 # Functions 1963 # Functions
1964 ( "-webkit-gradient", "gradient" ), 1964 ( "-webkit-gradient", "gradient" ),
1965 ( "-webkit-repeating-gradient", "repeating-gradient" ), 1965 ( "-webkit-repeating-gradient", "repeating-gradient" ),
1966 ( "-webkit-linear-gradient", "linear-gradient" ), 1966 ( "-webkit-linear-gradient", "linear-gradient" ),
1967 ( "-webkit-repeating-linear-gradient", "repeating-linear-gradient" ), 1967 ( "-webkit-repeating-linear-gradient", "repeating-linear-gradient" ),
1968 ( "-webkit-radial-gradient", "radial-gradient" ), 1968 ( "-webkit-radial-gradient", "radial-gradient" ),
1969 ( "-webkit-repeating-radial-gradient", "repeating-radial-gradient" ), 1969 ( "-webkit-repeating-radial-gradient", "repeating-radial-gradient" ),
1970 ] 1970 ]
1971 1971
1972 def _CheckNoDeprecatedCSS(input_api, output_api): 1972 def _CheckNoDeprecatedCss(input_api, output_api):
1973 """ Make sure that we don't use deprecated CSS 1973 """ Make sure that we don't use deprecated CSS
1974 properties, functions or values. Our external 1974 properties, functions or values. Our external
1975 documentation and iOS CSS for dom distiller 1975 documentation and iOS CSS for dom distiller
1976 (reader mode) are ignored by the hooks as it 1976 (reader mode) are ignored by the hooks as it
1977 needs to be consumed by WebKit. """ 1977 needs to be consumed by WebKit. """
1978 results = [] 1978 results = []
1979 file_inclusion_pattern = (r".+\.css$",) 1979 file_inclusion_pattern = (r".+\.css$",)
1980 black_list = (_EXCLUDED_PATHS + 1980 black_list = (_EXCLUDED_PATHS +
1981 _TEST_CODE_EXCLUDED_PATHS + 1981 _TEST_CODE_EXCLUDED_PATHS +
1982 input_api.DEFAULT_BLACK_LIST + 1982 input_api.DEFAULT_BLACK_LIST +
(...skipping 14 matching lines...) Expand all
1997 (fpath.LocalPath(), line_num, deprecated_value, value))) 1997 (fpath.LocalPath(), line_num, deprecated_value, value)))
1998 return results 1998 return results
1999 1999
2000 2000
2001 _DEPRECATED_JS = [ 2001 _DEPRECATED_JS = [
2002 ( "__lookupGetter__", "Object.getOwnPropertyDescriptor" ), 2002 ( "__lookupGetter__", "Object.getOwnPropertyDescriptor" ),
2003 ( "__defineGetter__", "Object.defineProperty" ), 2003 ( "__defineGetter__", "Object.defineProperty" ),
2004 ( "__defineSetter__", "Object.defineProperty" ), 2004 ( "__defineSetter__", "Object.defineProperty" ),
2005 ] 2005 ]
2006 2006
2007 def _CheckNoDeprecatedJS(input_api, output_api): 2007 def _CheckNoDeprecatedJs(input_api, output_api):
2008 """Make sure that we don't use deprecated JS in Chrome code.""" 2008 """Make sure that we don't use deprecated JS in Chrome code."""
2009 results = [] 2009 results = []
2010 file_inclusion_pattern = (r".+\.js$",) # TODO(dbeam): .html? 2010 file_inclusion_pattern = (r".+\.js$",) # TODO(dbeam): .html?
2011 black_list = (_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS + 2011 black_list = (_EXCLUDED_PATHS + _TEST_CODE_EXCLUDED_PATHS +
2012 input_api.DEFAULT_BLACK_LIST) 2012 input_api.DEFAULT_BLACK_LIST)
2013 file_filter = lambda f: input_api.FilterSourceFile( 2013 file_filter = lambda f: input_api.FilterSourceFile(
2014 f, white_list=file_inclusion_pattern, black_list=black_list) 2014 f, white_list=file_inclusion_pattern, black_list=black_list)
2015 for fpath in input_api.AffectedFiles(file_filter=file_filter): 2015 for fpath in input_api.AffectedFiles(file_filter=file_filter):
2016 for lnum, line in fpath.ChangedContents(): 2016 for lnum, line in fpath.ChangedContents():
2017 for (deprecated, replacement) in _DEPRECATED_JS: 2017 for (deprecated, replacement) in _DEPRECATED_JS:
2018 if deprecated in line: 2018 if deprecated in line:
2019 results.append(output_api.PresubmitError( 2019 results.append(output_api.PresubmitError(
2020 "%s:%d: Use of deprecated JS %s, use %s instead" % 2020 "%s:%d: Use of deprecated JS %s, use %s instead" %
2021 (fpath.LocalPath(), lnum, deprecated, replacement))) 2021 (fpath.LocalPath(), lnum, deprecated, replacement)))
2022 return results 2022 return results
2023 2023
2024 2024
2025 def _CheckForRiskyJsFeatures(input_api, output_api):
2026 maybe_ios_js = (r"^(ios|components|ui\/webui\/resources)\/.+\.js$", )
2027 file_filter = lambda f: input_api.FilterSourceFile(f, white_list=maybe_ios_js)
2028
2029 arrow_lines = []
2030 for f in input_api.AffectedFiles(file_filter=file_filter):
2031 for lnum, line in f.ChangedContents():
2032 if ' => ' in line:
2033 arrow_lines.append((f.LocalPath(), lnum))
2034
2035 if not arrow_lines:
2036 return []
2037
2038 return [output_api.PresubmitPromptWarning("""
2039 Use of => operator detected in:
2040 %s
2041 Please ensure your code does not run on iOS9 (=> (arrow) does not work there).
2042 https://chromium.googlesource.com/chromium/src/+/master/docs/es6_chromium.md#Arr ow-Functions
2043 """ % "\n".join(" %s:%d\n" % line for line in arrow_lines))]
2044
2045
2025 def _AndroidSpecificOnUploadChecks(input_api, output_api): 2046 def _AndroidSpecificOnUploadChecks(input_api, output_api):
2026 """Groups checks that target android code.""" 2047 """Groups checks that target android code."""
2027 results = [] 2048 results = []
2028 results.extend(_CheckAndroidCrLogUsage(input_api, output_api)) 2049 results.extend(_CheckAndroidCrLogUsage(input_api, output_api))
2029 results.extend(_CheckAndroidNewMdpiAssetLocation(input_api, output_api)) 2050 results.extend(_CheckAndroidNewMdpiAssetLocation(input_api, output_api))
2030 results.extend(_CheckAndroidToastUsage(input_api, output_api)) 2051 results.extend(_CheckAndroidToastUsage(input_api, output_api))
2031 return results 2052 return results
2032 2053
2033 2054
2034 def _CommonChecks(input_api, output_api): 2055 def _CommonChecks(input_api, output_api):
(...skipping 28 matching lines...) Expand all
2063 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api)) 2084 results.extend(_CheckAddedDepsHaveTargetApprovals(input_api, output_api))
2064 results.extend( 2085 results.extend(
2065 input_api.canned_checks.CheckChangeHasNoTabs( 2086 input_api.canned_checks.CheckChangeHasNoTabs(
2066 input_api, 2087 input_api,
2067 output_api, 2088 output_api,
2068 source_file_filter=lambda x: x.LocalPath().endswith('.grd'))) 2089 source_file_filter=lambda x: x.LocalPath().endswith('.grd')))
2069 results.extend(_CheckSpamLogging(input_api, output_api)) 2090 results.extend(_CheckSpamLogging(input_api, output_api))
2070 results.extend(_CheckForAnonymousVariables(input_api, output_api)) 2091 results.extend(_CheckForAnonymousVariables(input_api, output_api))
2071 results.extend(_CheckCygwinShell(input_api, output_api)) 2092 results.extend(_CheckCygwinShell(input_api, output_api))
2072 results.extend(_CheckUserActionUpdate(input_api, output_api)) 2093 results.extend(_CheckUserActionUpdate(input_api, output_api))
2073 results.extend(_CheckNoDeprecatedCSS(input_api, output_api)) 2094 results.extend(_CheckNoDeprecatedCss(input_api, output_api))
2074 results.extend(_CheckNoDeprecatedJS(input_api, output_api)) 2095 results.extend(_CheckNoDeprecatedJs(input_api, output_api))
2075 results.extend(_CheckParseErrors(input_api, output_api)) 2096 results.extend(_CheckParseErrors(input_api, output_api))
2076 results.extend(_CheckForIPCRules(input_api, output_api)) 2097 results.extend(_CheckForIPCRules(input_api, output_api))
2077 results.extend(_CheckForWindowsLineEndings(input_api, output_api)) 2098 results.extend(_CheckForWindowsLineEndings(input_api, output_api))
2078 results.extend(_CheckSingletonInHeaders(input_api, output_api)) 2099 results.extend(_CheckSingletonInHeaders(input_api, output_api))
2079 results.extend(_CheckNoDeprecatedCompiledResourcesGYP(input_api, output_api)) 2100 results.extend(_CheckNoDeprecatedCompiledResourcesGyp(input_api, output_api))
2080 results.extend(_CheckPydepsNeedsUpdating(input_api, output_api)) 2101 results.extend(_CheckPydepsNeedsUpdating(input_api, output_api))
2081 results.extend(_CheckJavaStyle(input_api, output_api)) 2102 results.extend(_CheckJavaStyle(input_api, output_api))
2082 results.extend(_CheckIpcOwners(input_api, output_api)) 2103 results.extend(_CheckIpcOwners(input_api, output_api))
2083 results.extend(_CheckMojoUsesNewWrapperTypes(input_api, output_api)) 2104 results.extend(_CheckMojoUsesNewWrapperTypes(input_api, output_api))
2084 results.extend(_CheckUselessForwardDeclarations(input_api, output_api)) 2105 results.extend(_CheckUselessForwardDeclarations(input_api, output_api))
2106 results.extend(_CheckForRiskyJsFeatures(input_api, output_api))
2085 2107
2086 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()): 2108 if any('PRESUBMIT.py' == f.LocalPath() for f in input_api.AffectedFiles()):
2087 results.extend(input_api.canned_checks.RunUnitTestsInDirectory( 2109 results.extend(input_api.canned_checks.RunUnitTestsInDirectory(
2088 input_api, output_api, 2110 input_api, output_api,
2089 input_api.PresubmitLocalPath(), 2111 input_api.PresubmitLocalPath(),
2090 whitelist=[r'^PRESUBMIT_test\.py$'])) 2112 whitelist=[r'^PRESUBMIT_test\.py$']))
2091 return results 2113 return results
2092 2114
2093 2115
2094 def _CheckPatchFiles(input_api, output_api): 2116 def _CheckPatchFiles(input_api, output_api):
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 results.extend(input_api.canned_checks.CheckTreeIsOpen( 2350 results.extend(input_api.canned_checks.CheckTreeIsOpen(
2329 input_api, 2351 input_api,
2330 output_api, 2352 output_api,
2331 json_url='http://chromium-status.appspot.com/current?format=json')) 2353 json_url='http://chromium-status.appspot.com/current?format=json'))
2332 2354
2333 results.extend(input_api.canned_checks.CheckChangeHasBugField( 2355 results.extend(input_api.canned_checks.CheckChangeHasBugField(
2334 input_api, output_api)) 2356 input_api, output_api))
2335 results.extend(input_api.canned_checks.CheckChangeHasDescription( 2357 results.extend(input_api.canned_checks.CheckChangeHasDescription(
2336 input_api, output_api)) 2358 input_api, output_api))
2337 return results 2359 return results
OLDNEW
« 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