Skip to content

Commit

Permalink
tidy check for vim and emacs modelines.
Browse files Browse the repository at this point in the history
See #10719.
  • Loading branch information
zwn committed Apr 21, 2016
1 parent 4556228 commit b6b8ac6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
10 changes: 9 additions & 1 deletion python/tidy/servo_tidy/tidy.py
Expand Up @@ -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
Expand Down Expand Up @@ -638,7 +646,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))
Expand Down
5 changes: 5 additions & 0 deletions python/tidy/servo_tidy_tests/modeline.txt
@@ -0,0 +1,5 @@
# vim: set noexpandtab:
// vi: et:
/* ex: et:
anything -*-Lisp-*-
-*- mode: Lisp -*-
8 changes: 8 additions & 0 deletions python/tidy/servo_tidy_tests/test_tidy.py
Expand Up @@ -75,6 +75,14 @@ def test_toml(self):
errors = tidy.collect_errors_for_files(iterFile('test.toml'), [tidy.check_toml], [])
self.assertEqual('found asterisk instead of minimum version number', errors.next()[2])

def test_modeline(self):
errors = tidy.collect_errors_for_files(iterFile('modeline.txt'), [], [tidy.check_modeline])
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])


def do_tests():
suite = unittest.TestLoader().loadTestsFromTestCase(CheckTidiness)
Expand Down

0 comments on commit b6b8ac6

Please sign in to comment.