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

Side by Side Diff: presubmit_canned_checks.py

Issue 9756001: Allow 'class Singleton<T>' in header files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: add unit test Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/presubmit_unittest.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 """Generic presubmit checks that can be reused by other presubmit checks.""" 5 """Generic presubmit checks that can be reused by other presubmit checks."""
6 6
7 7
8 ### Description checks 8 ### Description checks
9 9
10 def CheckChangeHasTestField(input_api, output_api): 10 def CheckChangeHasTestField(input_api, output_api):
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 if input_api.is_committing: 817 if input_api.is_committing:
818 res_type = output_api.PresubmitPromptWarning 818 res_type = output_api.PresubmitPromptWarning
819 else: 819 else:
820 res_type = output_api.PresubmitNotifyResult 820 res_type = output_api.PresubmitNotifyResult
821 return [ res_type('|const NSClass*| is wrong, see ' + 821 return [ res_type('|const NSClass*| is wrong, see ' +
822 'http://dev.chromium.org/developers/clang-mac', 822 'http://dev.chromium.org/developers/clang-mac',
823 files) ] 823 files) ]
824 return [] 824 return []
825 825
826 826
827 def _CheckSingletonInHeaders(input_api, output_api, source_file_filter): 827 def CheckSingletonInHeaders(input_api, output_api, source_file_filter=None):
828 """Checks to make sure no header files have |Singleton<|.""" 828 """Checks to make sure no header files have |Singleton<|."""
829 pattern = input_api.re.compile(r'Singleton\s*<') 829 pattern = input_api.re.compile(r'(?<!class\s)Singleton\s*<')
830 files = [] 830 files = []
831 for f in input_api.AffectedSourceFiles(source_file_filter): 831 for f in input_api.AffectedSourceFiles(source_file_filter):
832 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or 832 if (f.LocalPath().endswith('.h') or f.LocalPath().endswith('.hxx') or
833 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')): 833 f.LocalPath().endswith('.hpp') or f.LocalPath().endswith('.inl')):
834 contents = input_api.ReadFile(f) 834 contents = input_api.ReadFile(f)
835 for line in contents.splitlines(False): 835 for line in contents.splitlines(False):
836 line = input_api.re.sub(r'//.*$', '', line) # Strip C++ comment. 836 if (not input_api.re.match(r'//', line) and # Strip C++ comment.
837 if pattern.search(line): 837 pattern.search(line)):
838 files.append(f) 838 files.append(f)
839 break 839 break
840 840
841 if files: 841 if files:
842 return [ output_api.PresubmitError( 842 return [ output_api.PresubmitError(
843 'Found Singleton<T> in the following header files.\n' + 843 'Found Singleton<T> in the following header files.\n' +
844 'Please move them to an appropriate source file so that the ' + 844 'Please move them to an appropriate source file so that the ' +
845 'template gets instantiated in a single compilation unit.', 845 'template gets instantiated in a single compilation unit.',
846 files) ] 846 files) ]
847 return [] 847 return []
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 snapshot( "checking tabs") 917 snapshot( "checking tabs")
918 results.extend(input_api.canned_checks.CheckChangeHasNoTabs( 918 results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
919 input_api, output_api, source_file_filter=sources)) 919 input_api, output_api, source_file_filter=sources))
920 snapshot( "checking stray whitespace") 920 snapshot( "checking stray whitespace")
921 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( 921 results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
922 input_api, output_api, source_file_filter=sources)) 922 input_api, output_api, source_file_filter=sources))
923 snapshot("checking nsobjects") 923 snapshot("checking nsobjects")
924 results.extend(_CheckConstNSObject( 924 results.extend(_CheckConstNSObject(
925 input_api, output_api, source_file_filter=sources)) 925 input_api, output_api, source_file_filter=sources))
926 snapshot("checking singletons") 926 snapshot("checking singletons")
927 results.extend(_CheckSingletonInHeaders( 927 results.extend(CheckSingletonInHeaders(
928 input_api, output_api, source_file_filter=sources)) 928 input_api, output_api, source_file_filter=sources))
929 929
930 # The following checks are only done on commit, since the commit bot will 930 # The following checks are only done on commit, since the commit bot will
931 # auto-fix most of these. 931 # auto-fix most of these.
932 if input_api.is_committing: 932 if input_api.is_committing:
933 snapshot("checking eol style") 933 snapshot("checking eol style")
934 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle( 934 results.extend(input_api.canned_checks.CheckChangeSvnEolStyle(
935 input_api, output_api, source_file_filter=text_files)) 935 input_api, output_api, source_file_filter=text_files))
936 snapshot("checking svn mime types") 936 snapshot("checking svn mime types")
937 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( 937 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
938 input_api, output_api)) 938 input_api, output_api))
939 snapshot("checking license") 939 snapshot("checking license")
940 results.extend(input_api.canned_checks.CheckLicense( 940 results.extend(input_api.canned_checks.CheckLicense(
941 input_api, output_api, license_header, source_file_filter=sources)) 941 input_api, output_api, license_header, source_file_filter=sources))
942 snapshot("checking was uploaded") 942 snapshot("checking was uploaded")
943 results.extend(input_api.canned_checks.CheckChangeWasUploaded( 943 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
944 input_api, output_api)) 944 input_api, output_api))
945 snapshot("done") 945 snapshot("done")
946 return results 946 return results
OLDNEW
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698