Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const toSeverity = (message: HtmlError) => {
if (message.type === 'info') {
if (message.subType === 'warning') {
return Severity.warning;
}
// "Otherwise, the message is taken to generally informative."
return Severity.information;
}
if (message.type === 'error') {
return Severity.error;
}
// Internal errors by the validator, io, etc.
return Severity.warning;
};
const toSeverity = (impact?: ImpactValue) => {
if (impact === 'minor') {
return Severity.hint;
}
if (impact === 'moderate' || impact === 'serious') {
return Severity.warning;
}
if (impact === 'critical') {
return Severity.error;
}
// In case axe adds a new `impact` that is not tracked above
return Severity.warning;
};
const onWarningSelected = useCallback(() => {
onChange(Severity.warning.toString());
}, [onChange]);
public async format(messages: Problem[], options: FormatterOptions = {}) {
debug('Formatting results');
const language: string = options.language!;
if (messages.length === 0) {
return;
}
const resources: _.Dictionary = _.groupBy(messages, 'resource');
const totals = {
[Severity.error.toString()]: 0,
[Severity.warning.toString()]: 0,
[Severity.information.toString()]: 0,
[Severity.hint.toString()]: 0
};
let result = _.reduce(resources, (total: string, msgs: Problem[], resource: string) => {
const sortedMessages: Problem[] = _.sortBy(msgs, ['location.line', 'location.column']);
const resourceString = chalk.cyan(`${cutString(resource, 80)}`);
const partialResult = _.reduce(sortedMessages, (subtotal: string, msg: Problem) => {
let partial: string;
const color = severityToColor(msg.severity);
const severity = color(getMessage(`capitalized${Severity[msg.severity].toString()}` as MessageName, language));
const location = msg.location;
totals[msg.severity.toString()]++;
if (sourceCode.length < 1024) {
debug(`Ignoring minification for script under 1KB: ${resource}`);
return;
}
debug(`Calculated improvementIndex for ${resource}: ${improvementIndex}`);
if (improvementIndex > threshold) {
context.report(
resource,
getMessage('shouldBeMinified', context.language),
{
element,
severity: Severity.warning
});
}
};
const report = ({ feature, formatFeature, isValue, node, unsupported }: ReportData) => {
const alternatives = formatAlternatives(context.language, unsupported, formatFeature);
const message = [
getMessage('featureNotSupported', context.language, [feature, joinBrowsers(unsupported)]),
...alternatives
].join(' ');
const codeSnippet = getCSSCodeSnippet(node);
const location = getCSSLocationFromNode(node, { isValue });
const severity = alternatives.length ? Severity.error : Severity.warning;
context.report(
resource,
message,
{
codeLanguage: 'css',
codeSnippet,
element,
location,
severity
});
};
const notifyError = (resource: string, error: any) => {
debug(`Error getting HTML checker result for ${resource}.`, error);
context.report(
resource,
getMessage('couldNotGetResult', context.language, [resource, error.toString()]),
{ severity: Severity.warning });
};
const checkIfPropertyValueIsUnderLimit = (resource: string, content: string | undefined, propertyName: string, shortNameLengthLimit: number, getLocation: JSONLocationFunction) => {
if (content && (ucs2.decode(content).length > shortNameLengthLimit)) {
const message = getMessage('shouldHavePropertyShort', context.language, [propertyName, shortNameLengthLimit.toString()]);
const location = getLocation(propertyName, { at: 'value' });
context.report(resource, message, { location, severity: Severity.warning });
return false;
}
return true;
};
const configReceived = (webpackConfigEvent: WebpackConfigParse) => {
const { config, resource } = webpackConfigEvent;
debug(`'parse::end::webpack-config' received`);
if (config.devtool && config.devtool.toString().includes('eval')) {
context.report(
resource,
getMessage('noEval', context.language, config.devtool.toString()),
{ severity: Severity.warning }
);
}
};
const filteredProblems = problems.filter((problem) => {
return problem.severity >= (userConfig.severityThreshold || Severity.warning);
});