ember-template-lint
Version:
Linter for Ember or Handlebars templates.
34 lines (29 loc) • 1.02 kB
JavaScript
const AstNodeInfo = require('../helpers/ast-node-info');
const Rule = require('./base');
const ERROR_MESSAGE =
'The aria-hidden attribute should never be present on the <body> element, as it hides the entire document from assistive technology';
module.exports = class NoAriaHiddenBody extends Rule {
visitor() {
return {
ElementNode(node) {
let hasAriaHiddenBody =
node.tag === 'body' && AstNodeInfo.hasAttribute(node, 'aria-hidden');
if (hasAriaHiddenBody) {
if (this.mode === 'fix') {
node.attributes = node.attributes.filter((a) => a.name !== 'aria-hidden');
} else {
this.log({
message: ERROR_MESSAGE,
line: node.loc && node.loc.start.line,
column: node.loc && node.loc.start.column,
source: this.sourceForNode(node),
isFixable: true,
});
}
}
},
};
}
};
module.exports.ERROR_MESSAGE = ERROR_MESSAGE;
;