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