Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { codeSnippet, element, severity = Severity.warning } = options;
let sourceCode: string | null = null;
let position = options.location || null;
if (element) {
// When element is provided, position is an offset in the content.
position = this.findProblemLocation(element, position);
sourceCode = getHTMLCodeSnippet(element);
}
/**
* By default all hints get configured with `default` so they can
* decide the severity of each report unless it's overriden by the
* user.
*/
const finalSeverity = this.severity !== Severity.default ?
this.severity :
severity;
/*
* If location is undefined or equal to null, `position` will be set as `{ column: -1, line: -1 }` later in `hint.report`.
* So pass the `location` on as it is.
*/
this.engine.report({
category: (this.meta && this.meta.docs && this.meta.docs.category) ? this.meta.docs.category : Category.other,
codeLanguage: options.codeLanguage,
hintId: this.id,
location: position || { column: -1, line: -1 },
message,
resource,
severity: finalSeverity,
const rules = Array.from(ruleToRegistration.keys());
const result = await run(context, { document, resource }, rules);
/* istanbul ignore next */
if (!result || !Array.isArray(result.violations)) {
throw new Error(`Unable to parse axe results ${result}`);
}
for (const violation of result.violations) {
for (const node of violation.nodes) {
const summary = getSummary(node);
const message = summary ? `${violation.help}: ${summary}` : violation.help;
const registration = ruleToRegistration.get(violation.id)!;
const element = getElement(context, node);
const severity = Severity[registration.options[violation.id]] === Severity.default ?
toSeverity(violation.impact) :
Severity[registration.options[violation.id]];
registration.context.report(resource, message, { element, severity });
}
}
});
};
public addProblem(problem: Problem) {
const hintId = problem.hintId;
let hint = this.getHintByName(hintId);
if (!hint) {
hint = new HintResult(hintId, Severity[problem.severity].toString(), this.url, this.isScanner);
this.hints.push(hint);
}
if (problem.severity !== Severity.off && problem.severity !== Severity.default) {
this.hintsCount++;
}
hint.addProblem(problem);
}
}