From c6ab60dbfc6da7b4f800c9e40893c8b58413960c Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Thu, 28 Aug 2014 09:34:23 -0600 Subject: Cargoify servo --- python/tidy.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 python/tidy.py (limited to 'python/tidy.py') diff --git a/python/tidy.py b/python/tidy.py new file mode 100644 index 00000000000..04743433dbf --- /dev/null +++ b/python/tidy.py @@ -0,0 +1,91 @@ +# Copyright 2013 The Servo Project Developers. See the COPYRIGHT +# file at the top-level directory of this distribution. +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +#!/usr/bin/env python + +import os +from licenseck import check_license + +# FIXME(#3242): Don't use globals +err = 0 + + +def report_error_name_no(name, no, s): + global err + print("%s:%d: %s" % (name, no, s)) + err = 1 + + +def do_license_check(name, contents): + if not check_license(name, contents): + report_error_name_no(name, 1, "incorrect license") + + +def do_whitespace_check(name, contents): + for idx, line in enumerate(contents): + if line[-1] == "\n": + line = line[:-1] + else: + report_error_name_no(name, idx + 1, "No newline at EOF") + + if line.endswith(' '): + report_error_name_no(name, idx + 1, "trailing whitespace") + + if '\t' in line: + report_error_name_no(name, idx + 1, "tab on line") + + if '\r' in line: + report_error_name_no(name, idx + 1, "CR on line") + + +exceptions = [ + # Upstream + "support", + "tests/wpt/web-platform-tests", + + # Generated and upstream code combined with our own. Could use cleanup + "components/script/dom/bindings/codegen", + "components/style/properties/mod.rs", +] + + +def should_check(name): + if ".#" in name: + return False + if not (name.endswith(".rs") + or name.endswith(".rc") + or name.endswith(".cpp") + or name.endswith(".c") + or name.endswith(".h") + or name.endswith(".py")): + return False + for exception in exceptions: + if exception in name: + return False + return True + + +def scan(start_path): + global err + err = 0 + + file_names = [] + for root, dirs, files in os.walk(start_path): + for myfile in files: + file_name = root + "/" + myfile + if should_check(file_name): + file_names.append(file_name) + + for path in file_names: + with open(path, "r") as fp: + lines = fp.readlines() + do_license_check(path, "".join(lines)) + do_whitespace_check(path, lines) + + return err -- cgit v1.2.3