aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/tidy/servo_tidy/tidy.py3
-rw-r--r--python/tidy/servo_tidy_tests/empty_file.rs0
-rw-r--r--python/tidy/servo_tidy_tests/test_tidy.py5
3 files changed, 8 insertions, 0 deletions
diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py
index de3f83b84bd..340a3cd1a83 100644
--- a/python/tidy/servo_tidy/tidy.py
+++ b/python/tidy/servo_tidy/tidy.py
@@ -739,6 +739,9 @@ def collect_errors_for_files(files_to_check, checking_functions, line_checking_f
continue
with open(filename, "r") as f:
contents = f.read()
+ if not contents.strip():
+ yield filename, 0, "file is empty"
+ continue
for check in checking_functions:
for error in check(filename, contents):
# the result will be: `(filename, line, message)`
diff --git a/python/tidy/servo_tidy_tests/empty_file.rs b/python/tidy/servo_tidy_tests/empty_file.rs
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/empty_file.rs
diff --git a/python/tidy/servo_tidy_tests/test_tidy.py b/python/tidy/servo_tidy_tests/test_tidy.py
index 746783d1759..c35e4b533d1 100644
--- a/python/tidy/servo_tidy_tests/test_tidy.py
+++ b/python/tidy/servo_tidy_tests/test_tidy.py
@@ -39,6 +39,11 @@ class CheckTidiness(unittest.TestCase):
self.assertEqual('no newline at EOF', errors.next()[2])
self.assertNoMoreErrors(errors)
+ def test_empty_file(self):
+ errors = tidy.collect_errors_for_files(iterFile('empty_file.rs'), [], [tidy.check_by_line], print_text=False)
+ self.assertEqual('file is empty', 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], print_text=False)
self.assertEqual('Line is longer than 120 characters', errors.next()[2])