Skip to content

Commit cff2379

Browse files
authored
fix(src): update the suggestion when headers are invalid (#20)
* docs(pyproject): update the version index * fix(src): update the suggestion when the headers are invalid * fix( src): repair error message
1 parent 78eb0f7 commit cff2379

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api"
44

55
[tool.poetry]
66
name = "validate-python-headers"
7-
version = "0.4.0.dev0"
7+
version = "0.5.0.dev0"
88
description = "Python header validator"
99
license = "Apache-2.0"
1010
authors = ["François-Guillaume Fernandez <fg-feedback@protonmail.com>"]

src/validate_headers.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,23 @@ def get_header_options(
5757

5858
# Header build
5959
year_options = [f"{current_year}"] + [f"{year}-{current_year}" for year in range(starting_year, current_year)]
60+
# last element is the example for the error message
61+
year_options.append(f"{current_year}" if starting_year == current_year else f"<FILE_CREATION_YEAR>-{current_year}")
6062
copyright_notices = [[f"# Copyright (C) {year_str}, {owner}.\n"] for year_str in year_options]
6163

62-
return [
63-
[*SHEBANG, BLANK_LINE, *copyright_notice, BLANK_LINE, *license_notice]
64-
for copyright_notice in copyright_notices
65-
for license_notice in license_notices
66-
] + [
67-
[*copyright_notice, BLANK_LINE, *license_notice]
68-
for copyright_notice in copyright_notices
69-
for license_notice in license_notices
70-
]
64+
return (
65+
[
66+
[*SHEBANG, BLANK_LINE, *copyright_notice, BLANK_LINE, *license_notice]
67+
for copyright_notice in copyright_notices[:-1]
68+
for license_notice in license_notices
69+
]
70+
+ [
71+
[*copyright_notice, BLANK_LINE, *license_notice]
72+
for copyright_notice in copyright_notices[:-1]
73+
for license_notice in license_notices
74+
]
75+
+ [[*copyright_notices[-1], BLANK_LINE, *license_notices[0]]]
76+
)
7177

7278

7379
def main(args) -> None:
@@ -89,7 +95,7 @@ def main(args) -> None:
8995
if source_path.name in ignored_files or any(folder in source_path.parents for folder in ignored_folders):
9096
continue
9197
# Parse header
92-
header_length = max(len(option) for option in header_options)
98+
header_length = max(len(option) for option in header_options[:-1])
9399
current_header = []
94100
with source_path.open() as f:
95101
for idx, line in enumerate(f):
@@ -99,7 +105,7 @@ def main(args) -> None:
99105
# Validate it
100106
if not any(
101107
"".join(current_header[: min(len(option), len(current_header))]) == "".join(option)
102-
for option in header_options
108+
for option in header_options[:-1]
103109
):
104110
invalid_files.append(source_path)
105111

0 commit comments

Comments
 (0)