forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-link-href-attributes.js
More file actions
45 lines (41 loc) · 1.24 KB
/
template-link-href-attributes.js
File metadata and controls
45 lines (41 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'require href attribute on link elements',
category: 'Accessibility',
strictGjs: true,
strictGts: true,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-link-href-attributes.md',
},
fixable: null,
schema: [],
messages: {
missingHref:
'<a> elements must have an href attribute. Use <button> for clickable elements that are not links.',
},
},
create(context) {
return {
GlimmerElementNode(node) {
if (node.tag !== 'a') {
return;
}
const hasHref = node.attributes?.some((attr) => attr.name === 'href');
if (!hasHref) {
// Exception: <a> with both role and aria-disabled doesn't need href
const hasRole = node.attributes?.some((attr) => attr.name === 'role');
const hasAriaDisabled = node.attributes?.some((attr) => attr.name === 'aria-disabled');
if (hasRole && hasAriaDisabled) {
return;
}
context.report({
node,
messageId: 'missingHref',
});
}
},
};
},
};