initial import
[vuplus_webkit] / Tools / Scripts / webkitpy / style / checkers / xcodeproj.py
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2011 Google Inc. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
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.
13 #
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.
25
26 """Checks Xcode project files."""
27
28 import re
29
30
31 class XcodeProjectFileChecker(object):
32
33     """Processes Xcode project file lines for checking style."""
34
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>.+);')
40
41     def _check_development_region(self, line_index, line):
42         """Returns True when developmentRegion is detected."""
43         matched = self._development_region_regex.search(line)
44         if not matched:
45             return False
46         if matched.group('region') != 'English':
47             self.handle_style_error(line_index,
48                                     'xcodeproj/settings', 5,
49                                     'developmentRegion is not English.')
50         return True
51
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
57
58         if not development_region_is_detected:
59             self.handle_style_error(len(lines),
60                                     'xcodeproj/settings', 5,
61                                     'Missing "developmentRegion = English".')