ci: avoid regex literals in typhon Jenkinsfile
This commit is contained in:
parent
b094123518
commit
d0143bfc71
29
Jenkinsfile
vendored
29
Jenkinsfile
vendored
@ -139,11 +139,11 @@ const sourceExts = new Set(['.ts', '.js', '.cjs', '.mjs', '.sh']);
|
||||
|
||||
function unescapeXml(value) {
|
||||
return String(value || '')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'")
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/&/g, '&');
|
||||
.split('"').join('"')
|
||||
.split(''').join("'")
|
||||
.split('<').join('<')
|
||||
.split('>').join('>')
|
||||
.split('&').join('&');
|
||||
}
|
||||
|
||||
function attr(attrs, name) {
|
||||
@ -174,7 +174,7 @@ function collectSourceFiles(rootDir) {
|
||||
}
|
||||
|
||||
function categoryForClassname(classname) {
|
||||
const normalized = String(classname || '').replace(/\\/g, '/');
|
||||
const normalized = String(classname || '').split('\\').join('/');
|
||||
const relative = normalized.includes('/tests/')
|
||||
? normalized.slice(normalized.indexOf('/tests/') + '/tests/'.length)
|
||||
: (normalized.startsWith('tests/') ? normalized.slice('tests/'.length) : normalized);
|
||||
@ -187,7 +187,7 @@ function categoryForClassname(classname) {
|
||||
|
||||
function parseTestCases(junit) {
|
||||
const cases = [];
|
||||
const re = /<testcase\b([^>]*)>([\s\S]*?)<\/testcase>|<testcase\b([^>]*)\/>/g;
|
||||
const re = new RegExp('<testcase\\b([^>]*)>([\\s\\S]*?)</testcase>|<testcase\\b([^>]*)/>', 'g');
|
||||
let match;
|
||||
while ((match = re.exec(junit)) !== null) {
|
||||
const attrs = match[1] || match[3] || '';
|
||||
@ -205,16 +205,16 @@ function parseTestCases(junit) {
|
||||
}
|
||||
|
||||
const junit = fs.existsSync(junitPath) ? fs.readFileSync(junitPath, 'utf8') : '';
|
||||
const tests = Number((junit.match(/tests="([0-9]+)"/) || [])[1] || 0);
|
||||
const failures = Number((junit.match(/failures="([0-9]+)"/) || [])[1] || 0);
|
||||
const errors = Number((junit.match(/errors="([0-9]+)"/) || [])[1] || (junit ? 0 : 1));
|
||||
const skipped = Number((junit.match(/skipped="([0-9]+)"/) || [])[1] || 0);
|
||||
const tests = Number((junit.match(new RegExp('tests="([0-9]+)"')) || [])[1] || 0);
|
||||
const failures = Number((junit.match(new RegExp('failures="([0-9]+)"')) || [])[1] || 0);
|
||||
const errors = Number((junit.match(new RegExp('errors="([0-9]+)"')) || [])[1] || (junit ? 0 : 1));
|
||||
const skipped = Number((junit.match(new RegExp('skipped="([0-9]+)"')) || [])[1] || 0);
|
||||
|
||||
const cov = fs.existsSync(coveragePath) ? JSON.parse(fs.readFileSync(coveragePath, 'utf8')) : { total: {} };
|
||||
const total = cov.total || {};
|
||||
const sourceFiles = sourceRoots.flatMap((root) => collectSourceFiles(root));
|
||||
const overLimitFiles = sourceFiles
|
||||
.map((file) => ({ file, lines: fs.readFileSync(file, 'utf8').split(/\r?\n/).length }))
|
||||
.map((file) => ({ file, lines: fs.readFileSync(file, 'utf8').split(new RegExp('\\r?\\n')).length }))
|
||||
.filter((item) => item.lines > 500);
|
||||
|
||||
const report = {
|
||||
@ -349,7 +349,10 @@ const sourceFilesTotal = Number(quality.hygiene?.sourceFilesTotal ?? 0);
|
||||
const sourceLinesOver500 = Number(quality.hygiene?.sourceLinesOver500 ?? 0);
|
||||
|
||||
function esc(value) {
|
||||
return String(value ?? '').replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n');
|
||||
return String(value ?? '')
|
||||
.split('\\').join('\\\\')
|
||||
.split('"').join('\\"')
|
||||
.split('\n').join('\\n');
|
||||
}
|
||||
|
||||
function labelString(labels) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user