def parse_allowlist_file(filename):
data = defaultdict(lambda:defaultdict(set))
with open(filename) as f: for line in f:
line = line.strip() ifnot line or line.startswith("#"): continue
parts = [item.strip() for item in line.split(":")] if len(parts) == 2:
parts.append(None) else:
parts[-1] = int(parts[-1])
error_type, file_match, line_number = parts
data[file_match][error_type].add(line_number)
def inner(path, errors):
allowlisted = [Falsefor item in range(len(errors))]
for file_match, allowlist_errors in data.items(): if fnmatch.fnmatch(path, file_match): for i, (error_type, msg, line) in enumerate(errors): if"*"in allowlist_errors:
allowlisted[i] = True elif error_type in allowlist_errors:
allowed_lines = allowlist_errors[error_type] ifNonein allowed_lines or line in allowed_lines:
allowlisted[i] = True
return [item for i, item in enumerate(errors) ifnot allowlisted[i]] return inner
_allowlist_fn = None def allowlist_errors(path, errors): global _allowlist_fn
if _allowlist_fn isNone:
_allowlist_fn = parse_allowlist_file(os.path.join(lint_root, "lint.allowlist")) return _allowlist_fn(path, errors)
class TrailingWhitespaceRegexp(Regexp):
pattern = " $"
error = "TRAILING WHITESPACE"
class TabsRegexp(Regexp):
pattern = "^\t"
error = "INDENT TABS"
class CRRegexp(Regexp):
pattern = "\r$"
error = "CR AT EOL"
regexps = [item() for item in
[TrailingWhitespaceRegexp,
TabsRegexp,
CRRegexp]]
def check_regexp_line(path, f):
errors = []
applicable_regexps = [regexp for regexp in regexps if regexp.applies(path)]
try: for i, line in enumerate(f): for regexp in applicable_regexps: if regexp.search(line):
errors.append((regexp.error, "%s line %i" % (path, i+1), i+1)) except UnicodeDecodeError as e: return [("INVALID UNICODE", "File %s contains non-UTF-8 Unicode characters" % path, None)]
return errors
def output_errors(errors): for error_type, error, line_number in errors:
print("%s: %s" % (error_type, error))
by_type = " ".join("%s: %d" % item for item in error_count.items())
count = sum(error_count.values()) if count == 1:
print("There was 1 error (%s)" % (by_type,)) else:
print("There were %d errors (%s)" % (count, by_type))
def main(): global repo_root
error_count = defaultdict(int)
parser = OptionParser()
parser.add_option('-p', '--pull', dest="pull_request", action='store_true', default=False)
parser.add_option("-d", '--dir', dest="dir", help="specify the checking dir, e.g. tools")
parser.add_option("-r", '--repo', dest="repo", help="specify the repo, e.g. WebGL")
options, args = parser.parse_args() if options.pull_request == True:
options.pull_request = "WebGL"
repo_root = repo_root.replace("WebGL/sdk/tests", options.pull_request) if options.repo == ""or options.repo == None:
options.repo = "WebGL/sdk/tests"
repo_root = repo_root.replace("WebGL/sdk/tests", options.repo)
def run_lint(path, fn, *args):
errors = allowlist_errors(path, fn(path, *args))
output_errors(errors) for error_type, error, line in errors:
error_count[error_type] += 1
for path in iter_files(options.pull_request, options.dir):
abs_path = os.path.join(repo_root, path) ifnot os.path.exists(abs_path): continue for path_fn in file_path_lints:
run_lint(path, path_fn) for state_fn in file_state_lints:
run_lint(path, state_fn)
ifnot os.path.isdir(abs_path): if re.compile('\.html$|\.htm$|\.xhtml$|\.xhtm$|\.frag$|\.vert$|\.js$').search(abs_path): with open(abs_path) as f: for file_fn in file_content_lints:
run_lint(path, file_fn, f)
f.seek(0)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.