html-element-attribute-missing
Ast Rule: html element
html-element-attribute-missing
// See https://doc.codiga.io/docs/rosie/ast/javascript/rosie-ast-javascript-htmlelement/
function visit(node, filename, code) {
// Check only <ul> elements
if(node.tag && node.tag.value === "ul") {
// check that we have attributes
if(node.attributes && node.attributes.length > 0){
if(node.attributes && node.attributes.filter(a => a.name && a.name.value && a.name.value === "aria-label").length === 0) {
const error = buildError(node.tag.start.line, node.tag.start.col, node.tag.end.line, node.tag.end.col, "should have aria-label", "CRITICAL", "SAFETY");
addError(error);
}
}
}
}
mycomponent.jsx
Expected test result: has error