aboutsummaryrefslogtreecommitdiffstats
path: root/python/tidy/servo_tidy
diff options
context:
space:
mode:
authorUK992 <urbankrajnc92@gmail.com>2016-08-09 16:14:43 +0200
committerUK992 <urbankrajnc92@gmail.com>2016-08-12 13:34:38 +0200
commit9a3b61abe1ad633ab723ca6cbb7180a4992ead5a (patch)
treea0f07d159fcfe8f5597338993ee526ede7bb06ec /python/tidy/servo_tidy
parent48ace17b5419a9795a13bded286e113e79d56905 (diff)
downloadservo-9a3b61abe1ad633ab723ca6cbb7180a4992ead5a.tar.gz
servo-9a3b61abe1ad633ab723ca6cbb7180a4992ead5a.zip
Check for blank line after shebang and grab actual comment block instead of hard-coded one
Diffstat (limited to 'python/tidy/servo_tidy')
-rw-r--r--python/tidy/servo_tidy/licenseck.py5
-rw-r--r--python/tidy/servo_tidy/tidy.py16
2 files changed, 13 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