aboutsummaryrefslogtreecommitdiffstats
path: root/python/tidy
diff options
context:
space:
mode:
Diffstat (limited to 'python/tidy')
-rw-r--r--python/tidy/servo_tidy/licenseck.py11
-rw-r--r--python/tidy/servo_tidy/tidy.py21
-rw-r--r--python/tidy/servo_tidy_tests/duplicated_package.lock21
-rw-r--r--python/tidy/servo_tidy_tests/modeline.txt5
-rw-r--r--python/tidy/servo_tidy_tests/rust_tidy.rs5
-rw-r--r--python/tidy/servo_tidy_tests/test_tidy.py50
-rw-r--r--python/tidy/setup.py2
7 files changed, 100 insertions, 15 deletions
diff --git a/python/tidy/servo_tidy/licenseck.py b/python/tidy/servo_tidy/licenseck.py
index 705faf8bcb6..a67713b4421 100644
--- a/python/tidy/servo_tidy/licenseck.py
+++ b/python/tidy/servo_tidy/licenseck.py
@@ -59,4 +59,15 @@ licenses = [
# except according to those terms.
""",
+"""\
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+"""
] # noqa: Indicate to flake8 that we do not want to check indentation here
diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py
index 206346675e2..6ddb72d416f 100644
--- a/python/tidy/servo_tidy/tidy.py
+++ b/python/tidy/servo_tidy/tidy.py
@@ -133,6 +133,14 @@ def check_license(file_name, lines):
yield (1, "incorrect license")
+def check_modeline(file_name, lines):
+ for idx, line in enumerate(lines[:5]):
+ if re.search('^.*[ \t](vi:|vim:|ex:)[ \t]', line):
+ yield (idx + 1, "vi modeline present")
+ elif re.search('-\*-.*-\*-', line, re.IGNORECASE):
+ yield (idx + 1, "emacs file variables present")
+
+
def check_length(file_name, idx, line):
if file_name.endswith(".lock") or file_name.endswith(".json"):
raise StopIteration
@@ -277,7 +285,7 @@ def check_toml(file_name, lines):
def check_rust(file_name, lines):
if not file_name.endswith(".rs") or \
- file_name.endswith("properties.mako.rs") or \
+ file_name.endswith(".mako.rs") or \
file_name.endswith(os.path.join("style", "build.rs")) or \
file_name.endswith(os.path.join("geckolib", "build.rs")) or \
file_name.endswith(os.path.join("unit", "style", "stylesheets.rs")):
@@ -378,6 +386,7 @@ def check_rust(file_name, lines):
(r": &Vec<", "use &[T] instead of &Vec<T>", no_filter),
# No benefit over using &str
(r": &String", "use &str instead of &String", no_filter),
+ (r"^&&", "operators should go at the end of the first line", no_filter),
]
for pattern, message, filter_func in regex_rules:
@@ -568,11 +577,12 @@ def check_spec(file_name, lines):
brace_count -= 1
-def collect_errors_for_files(files_to_check, checking_functions, line_checking_functions):
+def collect_errors_for_files(files_to_check, checking_functions, line_checking_functions, print_text=True):
(has_element, files_to_check) = is_iter_empty(files_to_check)
if not has_element:
raise StopIteration
- print '\rChecking files for tidiness...'
+ if print_text:
+ print '\rChecking files for tidiness...'
for filename in files_to_check:
with open(filename, "r") as f:
contents = f.read()
@@ -638,7 +648,7 @@ def scan(faster=False, progress=True):
# standard checks
files_to_check = filter_files('.', faster, progress)
checking_functions = (check_flake8, check_lock, check_webidl_spec, check_json)
- line_checking_functions = (check_license, check_by_line, check_toml, check_rust, check_spec)
+ line_checking_functions = (check_license, check_by_line, check_toml, check_rust, check_spec, check_modeline)
errors = collect_errors_for_files(files_to_check, checking_functions, line_checking_functions)
# wpt lint checks
wpt_lint_errors = check_wpt_lint_errors(get_wpt_files(faster, progress))
@@ -647,6 +657,7 @@ def scan(faster=False, progress=True):
error = None
for error in errors:
print "\r\033[94m{}\033[0m:\033[93m{}\033[0m: \033[91m{}\033[0m".format(*error)
+ print
if error is None:
- print "\n\033[92mtidy reported no errors.\033[0m"
+ print "\033[92mtidy reported no errors.\033[0m"
return int(error is not None)
diff --git a/python/tidy/servo_tidy_tests/duplicated_package.lock b/python/tidy/servo_tidy_tests/duplicated_package.lock
new file mode 100644
index 00000000000..77777fdd82c
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/duplicated_package.lock
@@ -0,0 +1,21 @@
+[root]
+name = "servo"
+version = "0.0.1"
+
+[[package]]
+name = "test"
+version = "0.4.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "test"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "test2"
+version = "0.1.0"
+source = "git+https://github.com/"
+dependencies = [
+ "test 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
+]
diff --git a/python/tidy/servo_tidy_tests/modeline.txt b/python/tidy/servo_tidy_tests/modeline.txt
new file mode 100644
index 00000000000..2a3416953ce
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/modeline.txt
@@ -0,0 +1,5 @@
+# vim: set noexpandtab:
+// vi: et:
+/* ex: et:
+anything -*-Lisp-*-
+ -*- mode: Lisp -*-
diff --git a/python/tidy/servo_tidy_tests/rust_tidy.rs b/python/tidy/servo_tidy_tests/rust_tidy.rs
index 680b527f679..580f9e2ea96 100644
--- a/python/tidy/servo_tidy_tests/rust_tidy.rs
+++ b/python/tidy/servo_tidy_tests/rust_tidy.rs
@@ -32,6 +32,9 @@ impl test {
}
fn test_fun2(y : &String, z : &Vec<f32>) -> f32 {
- 1
+ let x = true;
+ x
+ && x;
}
+
}
diff --git a/python/tidy/servo_tidy_tests/test_tidy.py b/python/tidy/servo_tidy_tests/test_tidy.py
index 031e0873a56..fca54fd66d9 100644
--- a/python/tidy/servo_tidy_tests/test_tidy.py
+++ b/python/tidy/servo_tidy_tests/test_tidy.py
@@ -19,28 +19,37 @@ def iterFile(name):
class CheckTidiness(unittest.TestCase):
+ def assertNoMoreErrors(self, errors):
+ with self.assertRaises(StopIteration):
+ errors.next()
+
def test_spaces_correctnes(self):
- errors = tidy.collect_errors_for_files(iterFile('wrong_space.rs'), [], [tidy.check_by_line])
+ errors = tidy.collect_errors_for_files(iterFile('wrong_space.rs'), [], [tidy.check_by_line], print_text=False)
self.assertEqual('trailing whitespace', errors.next()[2])
self.assertEqual('no newline at EOF', errors.next()[2])
self.assertEqual('tab on line', errors.next()[2])
self.assertEqual('CR on line', errors.next()[2])
+ self.assertEqual('no newline at EOF', errors.next()[2])
+ self.assertNoMoreErrors(errors)
def test_long_line(self):
- errors = tidy.collect_errors_for_files(iterFile('long_line.rs'), [], [tidy.check_by_line])
+ errors = tidy.collect_errors_for_files(iterFile('long_line.rs'), [], [tidy.check_by_line], print_text=False)
self.assertEqual('Line is longer than 120 characters', errors.next()[2])
+ self.assertNoMoreErrors(errors)
def test_whatwg_link(self):
- errors = tidy.collect_errors_for_files(iterFile('whatwg_link.rs'), [], [tidy.check_by_line])
+ errors = tidy.collect_errors_for_files(iterFile('whatwg_link.rs'), [], [tidy.check_by_line], print_text=False)
self.assertTrue('link to WHATWG may break in the future, use this format instead:' in errors.next()[2])
self.assertTrue('links to WHATWG single-page url, change to multi page:' in errors.next()[2])
+ self.assertNoMoreErrors(errors)
def test_licence(self):
- errors = tidy.collect_errors_for_files(iterFile('incorrect_license.rs'), [], [tidy.check_license])
+ errors = tidy.collect_errors_for_files(iterFile('incorrect_license.rs'), [], [tidy.check_license], print_text=False)
self.assertEqual('incorrect license', errors.next()[2])
+ self.assertNoMoreErrors(errors)
def test_rust(self):
- errors = tidy.collect_errors_for_files(iterFile('rust_tidy.rs'), [], [tidy.check_rust])
+ errors = tidy.collect_errors_for_files(iterFile('rust_tidy.rs'), [], [tidy.check_rust], print_text=False)
self.assertEqual('use statement spans multiple lines', errors.next()[2])
self.assertEqual('missing space before }', errors.next()[2])
self.assertTrue('use statement is not in alphabetical order' in errors.next()[2])
@@ -61,19 +70,44 @@ class CheckTidiness(unittest.TestCase):
self.assertEqual('extra space before :', errors.next()[2])
self.assertEqual('use &[T] instead of &Vec<T>', errors.next()[2])
self.assertEqual('use &str instead of &String', errors.next()[2])
+ self.assertEqual('operators should go at the end of the first line', errors.next()[2])
+ self.assertNoMoreErrors(errors)
def test_spec_link(self):
tidy.spec_base_path = base_path
- errors = tidy.collect_errors_for_files(iterFile('speclink.rs'), [], [tidy.check_spec])
+ errors = tidy.collect_errors_for_files(iterFile('speclink.rs'), [], [tidy.check_spec], print_text=False)
self.assertEqual('method declared in webidl is missing a comment with a specification link', errors.next()[2])
+ self.assertNoMoreErrors(errors)
def test_webidl(self):
- errors = tidy.collect_errors_for_files(iterFile('spec.webidl'), [tidy.check_webidl_spec], [])
+ errors = tidy.collect_errors_for_files(iterFile('spec.webidl'), [tidy.check_webidl_spec], [], print_text=False)
self.assertEqual('No specification link found.', errors.next()[2])
+ self.assertNoMoreErrors(errors)
def test_toml(self):
- errors = tidy.collect_errors_for_files(iterFile('test.toml'), [tidy.check_toml], [])
+ errors = tidy.collect_errors_for_files(iterFile('test.toml'), [tidy.check_toml], [], print_text=False)
self.assertEqual('found asterisk instead of minimum version number', errors.next()[2])
+ self.assertNoMoreErrors(errors)
+
+ def test_modeline(self):
+ errors = tidy.collect_errors_for_files(iterFile('modeline.txt'), [], [tidy.check_modeline], print_text=False)
+ self.assertEqual('vi modeline present', errors.next()[2])
+ self.assertEqual('vi modeline present', errors.next()[2])
+ self.assertEqual('vi modeline present', errors.next()[2])
+ self.assertEqual('emacs file variables present', errors.next()[2])
+ self.assertEqual('emacs file variables present', errors.next()[2])
+ self.assertNoMoreErrors(errors)
+
+ def test_lock(self):
+ errors = tidy.collect_errors_for_files(iterFile('duplicated_package.lock'), [tidy.check_lock], [], print_text=False)
+ msg = """duplicate versions for package "test"
+\t\033[93mfound dependency on version 0.4.9\033[0m
+\t\033[91mbut highest version is 0.5.1\033[0m
+\t\033[93mtry upgrading with\033[0m \033[96m./mach cargo-update -p test:0.4.9\033[0m
+\tThe following packages depend on version 0.4.9:
+\t\ttest2"""
+ self.assertEqual(msg, errors.next()[2])
+ self.assertNoMoreErrors(errors)
def do_tests():
diff --git a/python/tidy/setup.py b/python/tidy/setup.py
index 86aae654b3c..a1af7d88465 100644
--- a/python/tidy/setup.py
+++ b/python/tidy/setup.py
@@ -11,7 +11,7 @@ import os
from setuptools import setup, find_packages
-VERSION = '0.0.2'
+VERSION = '0.0.3'
install_requires = [
"flake8==2.4.1",