Skip to content

Commit

Permalink
modify header_src to remove redundant headers
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Jan 27, 2021
1 parent ccdd29a commit ee1aca8
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions tasks/header_src.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,33 @@ function updateHeadersInSrcAndLibFiles() {
throw new Error(file + ' : has no header information.');
}

// if header and license are the same, do nothing
if(isCorrect(header)) return;

// if header and license only differ by date, update header
else if(hasWrongDate(header)) {
// if header and license are the same remove the header!
if(isRedundant(header)) {
var codeLines = code.split('\n');

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

var newCode = licenseSrc + '\n' + codeLines.join('\n');
var i;
for(i = 0; i < codeLines.length; i++) {
if(codeLines[i]) {
break;
}
}

var newCode = codeLines.splice(i).join('\n');

common.writeFile(file, newCode);
} else {
// otherwise, throw an error
throw new Error(file + ' : has wrong header information.');
}
});
});
});

function isCorrect(header) {
function isRedundant(header) {
return (
header.value.replace(/\s+$/gm, '') ===
licenseStr.replace(/\s+$/gm, '')
);
}

function hasWrongDate(header) {
var regex = /Copyright 20[0-9][0-9]-20[0-9][0-9]/g;

return (header.value.replace(regex, '') === licenseStr.replace(regex, ''));
}
}

updateHeadersInSrcAndLibFiles();

0 comments on commit ee1aca8

Please sign in to comment.