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

Side by Side Diff: tools/presubmit.py

Issue 119239: Add a check to presubmit.py linting python and SCons files for trailing white... Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 6 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 | « tools/js2c.py ('k') | tools/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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2008 the V8 project authors. All rights reserved. 3 # Copyright 2008 the V8 project authors. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 """ 130 """
131 131
132 def IsRelevant(self, name): 132 def IsRelevant(self, name):
133 return name.endswith('.cc') or name.endswith('.h') 133 return name.endswith('.cc') or name.endswith('.h')
134 134
135 def IgnoreDir(self, name): 135 def IgnoreDir(self, name):
136 return (super(CppLintProcessor, self).IgnoreDir(name) 136 return (super(CppLintProcessor, self).IgnoreDir(name)
137 or (name == 'third_party')) 137 or (name == 'third_party'))
138 138
139 IGNORE_LINT = ['flag-definitions.h'] 139 IGNORE_LINT = ['flag-definitions.h']
140 140
141 def IgnoreFile(self, name): 141 def IgnoreFile(self, name):
142 return (super(CppLintProcessor, self).IgnoreFile(name) 142 return (super(CppLintProcessor, self).IgnoreFile(name)
143 or (name in CppLintProcessor.IGNORE_LINT)) 143 or (name in CppLintProcessor.IGNORE_LINT))
144 144
145 def GetPathsToSearch(self): 145 def GetPathsToSearch(self):
146 return ['src', 'public', 'samples', join('test', 'cctest')] 146 return ['src', 'public', 'samples', join('test', 'cctest')]
147 147
148 def ProcessFiles(self, files): 148 def ProcessFiles(self, files):
149 filt = '-,' + ",".join(['+' + n for n in ENABLED_LINT_RULES]) 149 filt = '-,' + ",".join(['+' + n for n in ENABLED_LINT_RULES])
150 command = ['cpplint.py', '--filter', filt] + join(files) 150 command = ['cpplint.py', '--filter', filt] + join(files)
(...skipping 22 matching lines...) Expand all
173 173
174 def IgnoreDir(self, name): 174 def IgnoreDir(self, name):
175 return (super(SourceProcessor, self).IgnoreDir(name) 175 return (super(SourceProcessor, self).IgnoreDir(name)
176 or (name == 'third_party') 176 or (name == 'third_party')
177 or (name == 'obj')) 177 or (name == 'obj'))
178 178
179 IGNORE_COPYRIGHTS = ['earley-boyer.js', 'raytrace.js', 'crypto.js', 179 IGNORE_COPYRIGHTS = ['earley-boyer.js', 'raytrace.js', 'crypto.js',
180 'libraries.cc', 'libraries-empty.cc', 'jsmin.py', 'regexp-pcre.js'] 180 'libraries.cc', 'libraries-empty.cc', 'jsmin.py', 'regexp-pcre.js']
181 IGNORE_TABS = IGNORE_COPYRIGHTS + ['unicode-test.js', 181 IGNORE_TABS = IGNORE_COPYRIGHTS + ['unicode-test.js',
182 'html-comments.js'] 182 'html-comments.js']
183 NO_TRAILING_WHITESPACE_EXTENSIONS = ['py', 'SConscript', 'SConstruct']
183 184
184 def ProcessContents(self, name, contents): 185 def ProcessContents(self, name, contents):
185 result = True 186 result = True
186 base = basename(name) 187 base = basename(name)
188 extension = base.split('.').pop()
187 if not base in SourceProcessor.IGNORE_TABS: 189 if not base in SourceProcessor.IGNORE_TABS:
188 if '\t' in contents: 190 if '\t' in contents:
189 print "%s contains tabs" % name 191 print "%s contains tabs" % name
190 result = False 192 result = False
191 if not base in SourceProcessor.IGNORE_COPYRIGHTS: 193 if not base in SourceProcessor.IGNORE_COPYRIGHTS:
192 if not COPYRIGHT_HEADER_PATTERN.search(contents): 194 if not COPYRIGHT_HEADER_PATTERN.search(contents):
193 print "%s is missing a correct copyright header." % name 195 print "%s is missing a correct copyright header." % name
194 result = False 196 result = False
197 if extension in SourceProcessor.NO_TRAILING_WHITESPACE_EXTENSIONS:
198 if ' \n' in contents or contents.endswith(' '):
199 print "%s has trailing whitespace." % name
200 result = False
195 return result 201 return result
196 202
197 def ProcessFiles(self, files): 203 def ProcessFiles(self, files):
198 success = True 204 success = True
199 for file in files: 205 for file in files:
200 try: 206 try:
201 handle = open(file) 207 handle = open(file)
202 contents = handle.read() 208 contents = handle.read()
203 success = self.ProcessContents(file, contents) and success 209 success = self.ProcessContents(file, contents) and success
204 finally: 210 finally:
(...skipping 17 matching lines...) Expand all
222 success = CppLintProcessor().Run(workspace) and success 228 success = CppLintProcessor().Run(workspace) and success
223 success = SourceProcessor().Run(workspace) and success 229 success = SourceProcessor().Run(workspace) and success
224 if success: 230 if success:
225 return 0 231 return 0
226 else: 232 else:
227 return 1 233 return 1
228 234
229 235
230 if __name__ == '__main__': 236 if __name__ == '__main__':
231 sys.exit(Main()) 237 sys.exit(Main())
OLDNEW
« no previous file with comments | « tools/js2c.py ('k') | tools/test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698