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

Side by Side Diff: PRESUBMIT.py

Issue 10946004: Add a presubmit check for "? true : false". (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 | no next file » | 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 gcl. 8 for more details about the presubmit API built into gcl.
9 """ 9 """
10 10
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 files.append(f) 370 files.append(f)
371 371
372 if files: 372 if files:
373 return [output_api.PresubmitError( 373 return [output_api.PresubmitError(
374 'Do not use #pragma once in header files.\n' 374 'Do not use #pragma once in header files.\n'
375 'See http://www.chromium.org/developers/coding-style#TOC-File-headers', 375 'See http://www.chromium.org/developers/coding-style#TOC-File-headers',
376 files)] 376 files)]
377 return [] 377 return []
378 378
379 379
380 def _CheckNoTrinaryTrueFalse(input_api, output_api):
381 """Checks to make sure we don't introduce use of foo ? true : false."""
382 problems = []
383 pattern = input_api.re.compile(r'\?\s*(true|false)\s*:\s*(true|false)')
384 for f in input_api.AffectedFiles():
385 if not f.LocalPath().endswith(('.cc', '.h', '.inl', '.m', '.mm')):
386 continue
387
388 for line_num, line in f.ChangedContents():
389 if pattern.match(line):
390 problems.append(' %s:%d' % (f.LocalPath(), line_num))
391
392 if not problems:
393 return []
394 return [output_api.PresubmitPromptWarning(
395 'Please consider avoiding the "? true : false" pattern if possible.\n' +
396 '\n'.join(problems))]
397
398
380 def _CheckUnwantedDependencies(input_api, output_api): 399 def _CheckUnwantedDependencies(input_api, output_api):
381 """Runs checkdeps on #include statements added in this 400 """Runs checkdeps on #include statements added in this
382 change. Breaking - rules is an error, breaking ! rules is a 401 change. Breaking - rules is an error, breaking ! rules is a
383 warning. 402 warning.
384 """ 403 """
385 # We need to wait until we have an input_api object and use this 404 # We need to wait until we have an input_api object and use this
386 # roundabout construct to import checkdeps because this file is 405 # roundabout construct to import checkdeps because this file is
387 # eval-ed and thus doesn't have __file__. 406 # eval-ed and thus doesn't have __file__.
388 original_sys_path = sys.path 407 original_sys_path = sys.path
389 try: 408 try:
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 input_api, output_api, excluded_paths=_EXCLUDED_PATHS)) 478 input_api, output_api, excluded_paths=_EXCLUDED_PATHS))
460 results.extend(_CheckAuthorizedAuthor(input_api, output_api)) 479 results.extend(_CheckAuthorizedAuthor(input_api, output_api))
461 results.extend( 480 results.extend(
462 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api)) 481 _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
463 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api)) 482 results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
464 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api)) 483 results.extend(_CheckNoUNIT_TESTInSourceFiles(input_api, output_api))
465 results.extend(_CheckNoNewWStrings(input_api, output_api)) 484 results.extend(_CheckNoNewWStrings(input_api, output_api))
466 results.extend(_CheckNoDEPSGIT(input_api, output_api)) 485 results.extend(_CheckNoDEPSGIT(input_api, output_api))
467 results.extend(_CheckNoBannedFunctions(input_api, output_api)) 486 results.extend(_CheckNoBannedFunctions(input_api, output_api))
468 results.extend(_CheckNoPragmaOnce(input_api, output_api)) 487 results.extend(_CheckNoPragmaOnce(input_api, output_api))
488 results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
469 results.extend(_CheckUnwantedDependencies(input_api, output_api)) 489 results.extend(_CheckUnwantedDependencies(input_api, output_api))
470 results.extend(_CheckFilePermissions(input_api, output_api)) 490 results.extend(_CheckFilePermissions(input_api, output_api))
471 return results 491 return results
472 492
473 493
474 def _CheckSubversionConfig(input_api, output_api): 494 def _CheckSubversionConfig(input_api, output_api):
475 """Verifies the subversion config file is correctly setup. 495 """Verifies the subversion config file is correctly setup.
476 496
477 Checks that autoprops are enabled, returns an error otherwise. 497 Checks that autoprops are enabled, returns an error otherwise.
478 """ 498 """
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 # Same for ash and chromeos. 615 # Same for ash and chromeos.
596 if any(re.search('[/_](ash|aura)', f) for f in files): 616 if any(re.search('[/_](ash|aura)', f) for f in files):
597 trybots += ['linux_chromeos', 'linux_chromeos_clang:compile', 'win_aura', 617 trybots += ['linux_chromeos', 'linux_chromeos_clang:compile', 'win_aura',
598 'linux_chromeos_asan'] 618 'linux_chromeos_asan']
599 else: 619 else:
600 if any(re.search('[/_]chromeos', f) for f in files): 620 if any(re.search('[/_]chromeos', f) for f in files):
601 trybots += ['linux_chromeos', 'linux_chromeos_clang:compile', 621 trybots += ['linux_chromeos', 'linux_chromeos_clang:compile',
602 'linux_chromeos_asan'] 622 'linux_chromeos_asan']
603 623
604 return trybots 624 return trybots
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698