mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Auto merge of #13107 - UK992:tidy, r=Wafflespeanut
Tidy: Handle empty files Fix index error ``list index out of range``, when file is empty. r? @Wafflespeanut --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13107) <!-- Reviewable:end -->
This commit is contained in:
commit
c3ce9f2c90
4 changed files with 8 additions and 1 deletions
|
@ -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)`
|
||||
|
|
0
python/tidy/servo_tidy_tests/empty_file.rs
Normal file
0
python/tidy/servo_tidy_tests/empty_file.rs
Normal file
|
@ -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])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue