Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const config: NetworkConfig | null = getConfiguration();
/* istanbul ignore if */
if (!config) {
return;
}
const loadTime = getBestCaseScenario(config);
debug(`Ideal load time: ${loadTime}s`);
if (typeof config.load === 'number') {
const severity = calculateSeverity(loadTime, config.load);
if (severity !== Severity.off) {
context.report(
resource,
getMessage(severity === Severity.hint ? 'toLoadAllResourcesLess' : 'toLoadAllResourcesMore', context.language, [config.id, loadTime.toFixed(1), (loadTime - config.load).toFixed(1), config.load.toString()]),
{ severity });
}
}
};
const reportLibrary = (library: Library, vulns: Vulnerability[], resource: string) => {
let vulnerabilities = vulns;
debug('Filtering vulnerabilities');
let maxSeverity = Severity.off;
vulnerabilities = vulnerabilities.filter((vulnerability) => {
const { severity } = vulnerability;
let fails = false;
maxSeverity = Math.max(maxSeverity, toSeverity(severity as SnykSeverity));
switch (minimumSeverity) {
case 'medium':
fails = severity === 'medium' || severity === 'high';
break;
case 'high':
fails = severity === 'high';
break;
// priority is low, so everything needs to be reported
default:
const calculateSeverity = (loadTime: number, configurationLoadTime: number): Severity => {
const percentage = (loadTime * 100) / configurationLoadTime;
if (percentage < 90) {
return Severity.off;
} else if (percentage < 100) {
return Severity.hint;
} else if (percentage < 150) {
return Severity.warning;
}
return Severity.error;
};