aboutsummaryrefslogtreecommitdiffstats
path: root/python/tidy
diff options
context:
space:
mode:
Diffstat (limited to 'python/tidy')
-rw-r--r--python/tidy/servo_tidy/licenseck.py5
-rw-r--r--python/tidy/servo_tidy/tidy.py16
-rw-r--r--python/tidy/servo_tidy_tests/shebang_license.py4
-rw-r--r--python/tidy/servo_tidy_tests/test_tidy.py5
4 files changed, 22 insertions, 8 deletions
diff --git a/python/tidy/servo_tidy/licenseck.py b/python/tidy/servo_tidy/licenseck.py
index a9fe9077f21..a4953e6eabb 100644
--- a/python/tidy/servo_tidy/licenseck.py
+++ b/python/tidy/servo_tidy/licenseck.py
@@ -7,11 +7,6 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.
-# when wrapped to 80 chars, the longest license is 10 lines.
-# TODO actually grab whatever commented block is before the second blank line
-# of the file instead of hard-coding this.
-MAX_LICENSE_LINESPAN = 12
-
MPL = """\
This Source Code Form is subject to the terms of the Mozilla Public \
License, v. 2.0. If a copy of the MPL was not distributed with this \
diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py
index fac5f8e7063..93b5d8f6452 100644
--- a/python/tidy/servo_tidy/tidy.py
+++ b/python/tidy/servo_tidy/tidy.py
@@ -163,13 +163,23 @@ def licensed_apache(header):
def check_license(file_name, lines):
if any(file_name.endswith(ext) for ext in (".toml", ".lock", ".json")):
raise StopIteration
- block = min(len(lines), licenseck.MAX_LICENSE_LINESPAN)
+
+ if lines[0].startswith("#!") and lines[1].strip():
+ yield (1, "missing blank line after shebang")
+
+ blank_lines = 0
+ max_blank_lines = 2 if lines[0].startswith("#!") else 1
license_block = []
- for l in lines[:block]:
+
+ for l in lines:
l = l.rstrip('\n')
+ if not l.strip():
+ blank_lines += 1
+ if blank_lines >= max_blank_lines:
+ break
line = uncomment(l)
if line is not None:
- license_block += [line]
+ license_block.append(line)
contents = " ".join(license_block)
valid_license = licensed_mpl(contents) or licensed_apache(contents)
acknowledged_bad_license = "xfail-license" in contents
diff --git a/python/tidy/servo_tidy_tests/shebang_license.py b/python/tidy/servo_tidy_tests/shebang_license.py
new file mode 100644
index 00000000000..0499f3a93f9
--- /dev/null
+++ b/python/tidy/servo_tidy_tests/shebang_license.py
@@ -0,0 +1,4 @@
+#!/usr/bin/env python
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
diff --git a/python/tidy/servo_tidy_tests/test_tidy.py b/python/tidy/servo_tidy_tests/test_tidy.py
index 888c0faf693..bb1cb8ce61c 100644
--- a/python/tidy/servo_tidy_tests/test_tidy.py
+++ b/python/tidy/servo_tidy_tests/test_tidy.py
@@ -48,6 +48,11 @@ class CheckTidiness(unittest.TestCase):
self.assertEqual('incorrect license', errors.next()[2])
self.assertNoMoreErrors(errors)
+ def test_shebang_license(self):
+ errors = tidy.collect_errors_for_files(iterFile('shebang_license.py'), [], [tidy.check_license], print_text=False)
+ self.assertEqual('missing blank line after shebang', errors.next()[2])
+ self.assertNoMoreErrors(errors)
+
def test_shell(self):
errors = tidy.collect_errors_for_files(iterFile('shell_tidy.sh'), [], [tidy.check_shell], print_text=False)
self.assertEqual('script does not have shebang "#!/usr/bin/env bash"', errors.next()[2])