Skip to content

Commit ee1aca8

Browse files
committedJan 27, 2021
modify header_src to remove redundant headers
1 parent ccdd29a commit ee1aca8

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed
 

‎tasks/header_src.js

+11-16
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,33 @@ function updateHeadersInSrcAndLibFiles() {
2828
throw new Error(file + ' : has no header information.');
2929
}
3030

31-
// if header and license are the same, do nothing
32-
if(isCorrect(header)) return;
33-
34-
// if header and license only differ by date, update header
35-
else if(hasWrongDate(header)) {
31+
// if header and license are the same remove the header!
32+
if(isRedundant(header)) {
3633
var codeLines = code.split('\n');
3734

3835
codeLines.splice(header.loc.start.line - 1, header.loc.end.line);
3936

40-
var newCode = licenseSrc + '\n' + codeLines.join('\n');
37+
var i;
38+
for(i = 0; i < codeLines.length; i++) {
39+
if(codeLines[i]) {
40+
break;
41+
}
42+
}
43+
44+
var newCode = codeLines.splice(i).join('\n');
4145

4246
common.writeFile(file, newCode);
43-
} else {
44-
// otherwise, throw an error
45-
throw new Error(file + ' : has wrong header information.');
4647
}
4748
});
4849
});
4950
});
5051

51-
function isCorrect(header) {
52+
function isRedundant(header) {
5253
return (
5354
header.value.replace(/\s+$/gm, '') ===
5455
licenseStr.replace(/\s+$/gm, '')
5556
);
5657
}
57-
58-
function hasWrongDate(header) {
59-
var regex = /Copyright 20[0-9][0-9]-20[0-9][0-9]/g;
60-
61-
return (header.value.replace(regex, '') === licenseStr.replace(regex, ''));
62-
}
6358
}
6459

6560
updateHeadersInSrcAndLibFiles();

0 commit comments

Comments
 (0)
Please sign in to comment.