1 # -*- coding:utf-8;mode:python;mode:font-lock -*-
3 # Example configuration for enforcer.
5 # Copyright (c) 2005 Wilfredo Sanchez Vega <wsanchez@wsanchez.net>.
8 # Permission to use, copy, modify, and distribute this software for any
9 # purpose with or without fee is hereby granted, provided that the above
10 # copyright notice and this permission notice appear in all copies.
12 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
13 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 # DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 # PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 # PERFORMANCE OF THIS SOFTWARE.
25 def cxx_comment_start(line):
26 # FIXME: This doesn't work correctly if // is quoted (eg. in a string).
27 return line.find("//")
29 def verify_file_modified(filename):
31 Here we verify files which may not meet our requirements.
32 Any failure, even if not due to the specific changes in the commit
35 ext = os.path.splitext(filename)[1]
38 # Find WODebug=true in WOD files
44 wod_file = open_file(filename)
46 regex_wodebug = re.compile("WODebug\s*=\s*(true|yes|1)")
49 if line[-1] == "\n": line = line[:-1] # Zap trailing newline
50 comment_start = cxx_comment_start(line)
51 if comment_start != -1:
52 line = line[:comment_start]
54 if regex_wodebug.match(line):
55 raise ValueError("WODebug enabled in WOD file %r" % filename)
57 finally: wod_file.close()
59 def verify_line_added(filename, line):
61 Here we verify new lines of code which may not meet our requirements.
62 Code not changed as part of this commit is not verified.
64 ext = os.path.splitext(filename)[1]
67 # Find NSLog calls and unauthorized println calls in Java code
70 # r10814: unauthorized println calls
72 # r25729: authorized println calls
75 comment_start = cxx_comment_start(line)
77 if comment_start == -1:
81 if line[comment_start:].startswith("// (authorized)"):
86 code = line[:comment_start] # Strip out comment
88 if code.find("NSLog") != -1:
89 raise ValueError("NSLog call found in Java code file %r: %s" % (filename, line.strip()))
91 if not authorized and code.find("println") != -1:
92 raise ValueError("unauthorized println call found in Java code file %r: %s" % (filename, line.strip()))
94 def verify_property_line_added(filename, property, line):
96 Here we verify new lines in a property which may not meet our requirements.
97 Lines not changed as part of this commit are not verified.
100 # Don't commit a file which has the x-no-commit property set on it.
102 if property == "x-no-commit":
103 raise ValueError("x-no-commit property is set on file %r: %s" % (filename, line))