21
21
StrPattern = re .Pattern
22
22
23
23
CURRENT_YEAR = str (datetime .datetime .now ().year )
24
+ COPYRIGHT_EMPTY_LINE_RE = re .compile (r"^((?:#[^\n]*\n)+)([^\n#\"\'])" )
25
+ COPYRIGHT_EMPTY_LINE_SUB = r"\1\n\2"
24
26
25
27
26
28
def main () -> None :
@@ -32,6 +34,11 @@ def main() -> None:
32
34
args_parser .add_argument (
33
35
"--required" , action = "store_true" , help = "The copyright is required"
34
36
)
37
+ args_parser .add_argument (
38
+ "--fill-empty-line" ,
39
+ action = "store_true" ,
40
+ help = "Empty line needed between copyright and code" ,
41
+ )
35
42
args_parser .add_argument (
36
43
"--verbose" , "-v" , action = "store_true" , help = "Verbose mode"
37
44
)
@@ -130,6 +137,7 @@ def main() -> None:
130
137
file_name ,
131
138
args .required ,
132
139
args .verbose ,
140
+ args .fill_empty_line ,
133
141
)
134
142
if not file_success :
135
143
success = False
@@ -155,6 +163,7 @@ def update_file(
155
163
filename : str = "<unknown>" ,
156
164
required : bool = False ,
157
165
verbose : bool = False ,
166
+ fill_empty_line : bool = False ,
158
167
current_year : str = CURRENT_YEAR ,
159
168
) -> Tuple [bool , str ]:
160
169
"""Update the copyright header of the file content."""
@@ -176,6 +185,11 @@ def update_file(
176
185
)
177
186
178
187
if two_date_match .group ("to" ) in (last_year , current_year ):
188
+ copyright_space_match = COPYRIGHT_EMPTY_LINE_RE .search (content )
189
+ if fill_empty_line and copyright_space_match :
190
+ return False , COPYRIGHT_EMPTY_LINE_RE .sub (
191
+ COPYRIGHT_EMPTY_LINE_SUB , content
192
+ )
179
193
return True , content
180
194
181
195
return False , two_date_re .sub (
@@ -190,6 +204,11 @@ def update_file(
190
204
copyright_year = one_date_match .group ("year" )
191
205
192
206
if copyright_year == last_year :
207
+ copyright_space_match = COPYRIGHT_EMPTY_LINE_RE .search (content )
208
+ if fill_empty_line and copyright_space_match :
209
+ return False , COPYRIGHT_EMPTY_LINE_RE .sub (
210
+ COPYRIGHT_EMPTY_LINE_SUB , content
211
+ )
193
212
return True , content
194
213
195
214
return False , one_date_re .sub (
0 commit comments