From 7bff57f87ce36f529f30c5c2f15fe94fb2b59559 Mon Sep 17 00:00:00 2001 From: Aleksey Khoroshilov Date: Wed, 30 Nov 2022 21:28:25 +0700 Subject: [PATCH] Add multiline comment license example to presubmit message. --- PRESUBMIT.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 043c221f1f1..b2e5422e3c6 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -74,9 +74,6 @@ def CheckLicense(input_api, output_api): 'year': current_year, } - assert new_file_license_re.search(expected_license_template) - assert existing_file_license_re.search(expected_license_template) - bad_new_files = [] bad_files = [] sources = lambda affected_file: input_api.FilterSourceFile( @@ -94,10 +91,23 @@ def CheckLicense(input_api, output_api): if not existing_file_license_re.search(contents): bad_files.append(f.LocalPath()) + splitted_expected_license_template = expected_license_template.replace( + "# ", "").split('\n') + multiline_comment_expected_license = ( + f'/* {splitted_expected_license_template[0]}\n' + f' * {splitted_expected_license_template[1]}\n' + f' * {splitted_expected_license_template[2]}\n' + f' * {splitted_expected_license_template[3]} */\n') + assert new_file_license_re.search(expected_license_template) + assert existing_file_license_re.search(expected_license_template) + assert new_file_license_re.search(multiline_comment_expected_license) + assert existing_file_license_re.search(multiline_comment_expected_license) + # Show this to simplify copy-paste when an invalid license is found. expected_license_message = ( f'Expected one of license headers:\n' f'{expected_license_template.replace("#", "//")}\n' + f'{multiline_comment_expected_license}\n' f'{expected_license_template}') result = []