Skip to content

Commit

Permalink
Make copyright checker more verbose
Browse files Browse the repository at this point in the history
Output the the line that failed the check in addition to what has been
found at the top of the file.
  • Loading branch information
ppenzin committed Apr 22, 2024
1 parent 1c26375 commit 889e20d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tools/StyleChecks/check_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@
pattern = '^.{1,5}%s$' % line
regexes.append(re.compile(pattern))

def report_incorrect(file_name, pairs):
def report_incorrect(file_name, pairs, fail_line):
# found a problem so report the problem to the caller and exit
print(file_name, "... does not contain a correct copyright notice.\n")
# print the relevant lines to help the reader find the problem
for (_, line) in pairs:
print(" ", line, end="")
print()
if (fail_line != ""):
print("Match failed at line:")
print(" ", fail_line, end="")
print()

linecount = 0
pairs = []
Expand All @@ -69,12 +73,12 @@ def report_incorrect(file_name, pairs):
line = line.rstrip()
matches = regex.match(line)
if not matches:
report_incorrect(file_name, pairs)
report_incorrect(file_name, pairs, line)
exit(1)

if linecount == 0:
# the file was empty (e.g. dummy.js) so no problem
exit(0)
elif linecount != len(regexes):
report_incorrect(file_name, pairs)
report_incorrect(file_name, pairs, "")
exit(1)

0 comments on commit 889e20d

Please sign in to comment.