Skip to content

Commit

Permalink
Merge pull request #19 from arkinmodi/special-comments
Browse files Browse the repository at this point in the history
make special comments extensible
  • Loading branch information
arkinmodi authored Mar 23, 2024
2 parents 40237af + f33d334 commit 3e4b029
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions add_license_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,25 @@ def update_license_header(
comment: BlockComment,
wrapped_license: list[str],
) -> list[str]:
if len(contents) > 0 and contents[0].startswith('#!'):
header_start_index = 1
else:
header_start_index = 0

# NOTE: "Special Comments" are comments that must appear at the top of the
# file (i.e., before the license header). Moving these comments to after
# the license header would break some form of functionality.
special_comments = (
'#!', # shebang
)

comment_start = wrapped_license[0].strip()
header_start_index = 0

while (
header_start_index < len(contents) and
not contents[header_start_index].startswith(comment_start)
header_start_index < len(contents) and (
any(
contents[header_start_index].startswith(sc)
for sc in special_comments
) or
not contents[header_start_index].startswith(comment_start)
)
):
header_start_index += 1

Expand Down

0 comments on commit 3e4b029

Please sign in to comment.