xcodeproj.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (C) 2011 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions
  5. # are met:
  6. # 1. Redistributions of source code must retain the above copyright
  7. # notice, this list of conditions and the following disclaimer.
  8. # 2. Redistributions in binary form must reproduce the above copyright
  9. # notice, this list of conditions and the following disclaimer in the
  10. # documentation and/or other materials provided with the distribution.
  11. #
  12. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  13. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  14. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  15. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  16. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  18. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  19. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  20. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  22. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. """Checks Xcode project files."""
  24. import re
  25. class XcodeProjectFileChecker(object):
  26. """Processes Xcode project file lines for checking style."""
  27. def __init__(self, file_path, handle_style_error):
  28. self.file_path = file_path
  29. self.handle_style_error = handle_style_error
  30. self.handle_style_error.turn_off_line_filtering()
  31. self._development_region_regex = re.compile('developmentRegion = (?P<region>.+);')
  32. def _check_development_region(self, line_index, line):
  33. """Returns True when developmentRegion is detected."""
  34. matched = self._development_region_regex.search(line)
  35. if not matched:
  36. return False
  37. if matched.group('region') != 'English':
  38. self.handle_style_error(line_index,
  39. 'xcodeproj/settings', 5,
  40. 'developmentRegion is not English.')
  41. return True
  42. def check(self, lines):
  43. development_region_is_detected = False
  44. for line_index, line in enumerate(lines):
  45. if self._check_development_region(line_index, line):
  46. development_region_is_detected = True
  47. if not development_region_is_detected:
  48. self.handle_style_error(len(lines),
  49. 'xcodeproj/settings', 5,
  50. 'Missing "developmentRegion = English".')