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 24"""Checks Xcode project files.""" 25 26import re 27 28 29class XcodeProjectFileChecker(object): 30 31 """Processes Xcode project file lines for checking style.""" 32 33 def __init__(self, file_path, handle_style_error): 34 self.file_path = file_path 35 self.handle_style_error = handle_style_error 36 self.handle_style_error.turn_off_line_filtering() 37 self._development_region_regex = re.compile('developmentRegion = (?P<region>.+);') 38 39 def _check_development_region(self, line_index, line): 40 """Returns True when developmentRegion is detected.""" 41 matched = self._development_region_regex.search(line) 42 if not matched: 43 return False 44 if matched.group('region') != 'English': 45 self.handle_style_error(line_index, 46 'xcodeproj/settings', 5, 47 'developmentRegion is not English.') 48 return True 49 50 def check(self, lines): 51 development_region_is_detected = False 52 for line_index, line in enumerate(lines): 53 if self._check_development_region(line_index, line): 54 development_region_is_detected = True 55 56 if not development_region_is_detected: 57 self.handle_style_error(len(lines), 58 'xcodeproj/settings', 5, 59 'Missing "developmentRegion = English".') 60