-
-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathtemplate-no-accesskey-attribute.js
More file actions
54 lines (48 loc) · 1.64 KB
/
template-no-accesskey-attribute.js
File metadata and controls
54 lines (48 loc) · 1.64 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
46
47
48
49
50
51
52
53
54
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow `accesskey` attribute on HTML elements in templates',
category: 'Best Practices',
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-accesskey-attribute.md',
},
fixable: 'code',
schema: [],
messages: {
noAccesskey:
'No access key attribute allowed. Inconsistencies between keyboard shortcuts and keyboard comments used by screenreader and keyboard only users create a11y complications.',
},
},
create(context) {
const sourceCode = context.sourceCode;
return {
GlimmerElementNode(node) {
if (!node.attributes) {
return;
}
const accessKeyAttr = node.attributes.find(
(attr) =>
attr.type === 'GlimmerAttrNode' &&
attr.name &&
attr.name === 'accesskey'
);
if (accessKeyAttr) {
context.report({
node: accessKeyAttr,
messageId: 'noAccesskey',
fix(fixer) {
// Get the range of the attribute
const attrStart = accessKeyAttr.range[0];
const attrEnd = accessKeyAttr.range[1];
// Check if there's a space before the attribute that should be removed
const sourceText = sourceCode.getText();
const removeStart = attrStart > 0 && sourceText[attrStart - 1] === ' ' ? attrStart - 1 : attrStart;
return fixer.removeRange([removeStart, attrEnd]);
},
});
}
},
};
},
};