Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('logs info', () => {
violationLogger(logger)({ severity: DiagnosticSeverity.Information, message: 'Test' });
expect(logger.error).not.toHaveBeenCalled();
expect(logger.warn).not.toHaveBeenCalled();
expect(logger.info).toHaveBeenCalledWith({ name: 'VALIDATOR' }, 'Violation: Test');
});
});
if (newRule === 'recommended') {
return existingRule.recommended !== false ? existingSeverity : -1;
}
if (newRule === 'all') {
return existingSeverity;
}
return getSeverityForRule(newRule, existingSeverity);
}
const SEVERITY_MAP: Dictionary = {
error: DiagnosticSeverity.Error,
warn: DiagnosticSeverity.Warning,
info: DiagnosticSeverity.Information,
hint: DiagnosticSeverity.Hint,
off: -1,
};
export function getDiagnosticSeverity(
severity: DiagnosticSeverity | HumanReadableDiagnosticSeverity,
): SpectralDiagnosticSeverity {
if (Number.isNaN(Number(severity))) {
return SEVERITY_MAP[severity];
}
return Number(severity);
}
* @returns {string} The original word with an s on the end if count is not one.
*/
function pluralize(word: string, count: number): string {
return count === 1 ? word : `${word}s`;
}
function formatRange(range?: IRange): string {
if (!range) return '';
return ` ${range.start.line + 1}:${range.start.character + 1}`;
}
const SEVERITY_COLORS = {
[DiagnosticSeverity.Error]: 'red',
[DiagnosticSeverity.Warning]: 'yellow',
[DiagnosticSeverity.Information]: 'blue',
[DiagnosticSeverity.Hint]: 'white',
};
function getColorForSeverity(severity: DiagnosticSeverity) {
return SEVERITY_COLORS[severity];
}
function getMessageType(severity: DiagnosticSeverity) {
const color = getColorForSeverity(severity);
switch (severity) {
case DiagnosticSeverity.Error:
return chalk[color]('error');
case DiagnosticSeverity.Warning:
return chalk[color]('warning');
case DiagnosticSeverity.Information:
Object.keys(groupedResults).map((path, index) => {
const pathResults = groupedResults[path];
const {
[DiagnosticSeverity.Error]: errors,
[DiagnosticSeverity.Warning]: warnings,
[DiagnosticSeverity.Information]: infos,
[DiagnosticSeverity.Hint]: hints,
} = groupBySeverity(pathResults);
errorCount += errors.length;
warningCount += warnings.length;
infoCount += infos.length;
hintCount += hints.length;
output += `${chalk.underline(path)}\n`;
const pathTableData = sortResults(pathResults).map((result: IRuleResult) => [
formatRange(result.range),
getMessageType(result.severity),
result.code !== undefined ? result.code : '',
result.message,
]);