@angular-eslint/eslint-plugin-template 22.3.0 → 22.3.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ declare const _default: {
|
|
|
22
22
|
"button-has-type": import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./rules/button-has-type").MessageIds, import("./rules/button-has-type").Options, import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
23
23
|
name: string;
|
|
24
24
|
};
|
|
25
|
-
"click-events-have-key-events": import("@typescript-eslint/utils/ts-eslint").RuleModule<"
|
|
25
|
+
"click-events-have-key-events": import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./rules/click-events-have-key-events").MessageIds, import("./rules/click-events-have-key-events").Options, import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
26
26
|
name: string;
|
|
27
27
|
};
|
|
28
28
|
"conditional-complexity": import("@typescript-eslint/utils/ts-eslint").RuleModule<"conditionalComplexity", import("./rules/conditional-complexity").Options, import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export type Options = [
|
|
2
2
|
{
|
|
3
3
|
readonly ignoreWithDirectives?: string[];
|
|
4
|
+
readonly requireKeyCode?: boolean;
|
|
5
|
+
readonly allowedKeyCodes?: string[];
|
|
4
6
|
}
|
|
5
7
|
];
|
|
6
|
-
export type MessageIds = 'clickEventsHaveKeyEvents';
|
|
8
|
+
export type MessageIds = 'clickEventsHaveKeyEvents' | 'clickEventsHaveKeyCode' | 'clickEventsHaveAllowedKeyCode';
|
|
7
9
|
export declare const RULE_NAME = "click-events-have-key-events";
|
|
8
|
-
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<
|
|
10
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
9
11
|
name: string;
|
|
10
12
|
};
|
|
11
13
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"click-events-have-key-events.d.ts","sourceRoot":"","sources":["../../src/rules/click-events-have-key-events.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"click-events-have-key-events.d.ts","sourceRoot":"","sources":["../../src/rules/click-events-have-key-events.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;QACzC,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;QAClC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;KACrC;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAClB,0BAA0B,GAC1B,wBAAwB,GACxB,+BAA+B,CAAC;AACpC,eAAO,MAAM,SAAS,iCAAiC,CAAC;;;;AASxD,wBA+HG;AAyCH,eAAO,MAAM,mBAAmB;;CAG/B,CAAC"}
|
|
@@ -11,7 +11,10 @@ const get_attribute_value_1 = require("../utils/get-attribute-value");
|
|
|
11
11
|
exports.RULE_NAME = 'click-events-have-key-events';
|
|
12
12
|
const DEFAULT_OPTIONS = {
|
|
13
13
|
ignoreWithDirectives: [],
|
|
14
|
+
requireKeyCode: false,
|
|
15
|
+
allowedKeyCodes: [],
|
|
14
16
|
};
|
|
17
|
+
const KEY_EVENTS = ['keyup', 'keydown', 'keypress'];
|
|
15
18
|
exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
16
19
|
name: exports.RULE_NAME,
|
|
17
20
|
meta: {
|
|
@@ -29,16 +32,31 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
29
32
|
uniqueItems: true,
|
|
30
33
|
default: DEFAULT_OPTIONS.ignoreWithDirectives,
|
|
31
34
|
},
|
|
35
|
+
requireKeyCode: {
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
description: 'Require key events to specify a key via a pseudo-event, e.g. `(keydown.enter)`. A bare `(keydown)` will not satisfy the rule.',
|
|
38
|
+
default: DEFAULT_OPTIONS.requireKeyCode,
|
|
39
|
+
},
|
|
40
|
+
allowedKeyCodes: {
|
|
41
|
+
type: 'array',
|
|
42
|
+
items: { type: 'string' },
|
|
43
|
+
uniqueItems: true,
|
|
44
|
+
description: 'Only key events whose key (the last segment of the pseudo-event, e.g. `enter` in `(keydown.shift.enter)`) is in this list satisfy the rule. Implies `requireKeyCode`.',
|
|
45
|
+
default: DEFAULT_OPTIONS.allowedKeyCodes,
|
|
46
|
+
},
|
|
32
47
|
},
|
|
33
48
|
additionalProperties: false,
|
|
34
49
|
},
|
|
35
50
|
],
|
|
36
51
|
messages: {
|
|
37
52
|
clickEventsHaveKeyEvents: 'click must be accompanied by either keyup, keydown or keypress event for accessibility.',
|
|
53
|
+
clickEventsHaveKeyCode: 'click must be accompanied by a keyup, keydown or keypress event that specifies a key (e.g. `(keydown.enter)`) for accessibility.',
|
|
54
|
+
clickEventsHaveAllowedKeyCode: 'click must be accompanied by a keyup, keydown or keypress event for one of the allowed keys ({{allowedKeyCodes}}) for accessibility.',
|
|
38
55
|
},
|
|
39
56
|
defaultOptions: [DEFAULT_OPTIONS],
|
|
40
57
|
},
|
|
41
|
-
create(context, [{ ignoreWithDirectives }]) {
|
|
58
|
+
create(context, [{ ignoreWithDirectives, requireKeyCode, allowedKeyCodes }]) {
|
|
59
|
+
const normalizedAllowedKeyCodes = (allowedKeyCodes ?? []).map((keyCode) => keyCode.toLowerCase());
|
|
42
60
|
return {
|
|
43
61
|
Element(node) {
|
|
44
62
|
if (!(0, get_dom_elements_1.getDomElements)().has(node.name.toLowerCase())) {
|
|
@@ -56,28 +74,71 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
56
74
|
if (role === 'button') {
|
|
57
75
|
return;
|
|
58
76
|
}
|
|
59
|
-
let hasClick = false, hasKeyEvent = false;
|
|
77
|
+
let hasClick = false, hasKeyEvent = false, hasSatisfyingKeyEvent = false;
|
|
60
78
|
for (const output of node.outputs) {
|
|
61
79
|
hasClick = hasClick || output.name === 'click';
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
if (!isKeyEvent(output)) {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
hasKeyEvent = true;
|
|
84
|
+
const keyCode = getKeyCode(output);
|
|
85
|
+
if (normalizedAllowedKeyCodes.length > 0) {
|
|
86
|
+
hasSatisfyingKeyEvent =
|
|
87
|
+
hasSatisfyingKeyEvent ||
|
|
88
|
+
(keyCode !== undefined &&
|
|
89
|
+
normalizedAllowedKeyCodes.includes(keyCode));
|
|
90
|
+
}
|
|
91
|
+
else if (requireKeyCode) {
|
|
92
|
+
hasSatisfyingKeyEvent =
|
|
93
|
+
hasSatisfyingKeyEvent || keyCode !== undefined;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
hasSatisfyingKeyEvent = true;
|
|
97
|
+
}
|
|
67
98
|
}
|
|
68
|
-
if (!hasClick ||
|
|
99
|
+
if (!hasClick || hasSatisfyingKeyEvent) {
|
|
69
100
|
return;
|
|
70
101
|
}
|
|
71
102
|
const parserServices = (0, utils_1.getTemplateParserServices)(context);
|
|
72
103
|
const loc = parserServices.convertNodeSourceSpanToLoc(node.sourceSpan);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
104
|
+
if (!hasKeyEvent) {
|
|
105
|
+
context.report({
|
|
106
|
+
loc,
|
|
107
|
+
messageId: 'clickEventsHaveKeyEvents',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else if (normalizedAllowedKeyCodes.length > 0) {
|
|
111
|
+
context.report({
|
|
112
|
+
loc,
|
|
113
|
+
messageId: 'clickEventsHaveAllowedKeyCode',
|
|
114
|
+
data: { allowedKeyCodes: normalizedAllowedKeyCodes.join(', ') },
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
context.report({
|
|
119
|
+
loc,
|
|
120
|
+
messageId: 'clickEventsHaveKeyCode',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
77
123
|
},
|
|
78
124
|
};
|
|
79
125
|
},
|
|
80
126
|
});
|
|
127
|
+
function isKeyEvent({ name }) {
|
|
128
|
+
return KEY_EVENTS.some((keyEvent) => name === keyEvent || name.startsWith(`${keyEvent}.`));
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Returns the key targeted by a key pseudo-event, e.g. `enter` for
|
|
132
|
+
* `(keydown.shift.enter)`, or `undefined` for a bare `(keydown)`.
|
|
133
|
+
*/
|
|
134
|
+
function getKeyCode({ name }) {
|
|
135
|
+
const segments = name.split('.');
|
|
136
|
+
if (segments.length < 2) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
const keyCode = segments[segments.length - 1].toLowerCase();
|
|
140
|
+
return keyCode.length > 0 ? keyCode : undefined;
|
|
141
|
+
}
|
|
81
142
|
function isIgnored(ignoreWithDirectives, { inputs, attributes }) {
|
|
82
143
|
if (ignoreWithDirectives && ignoreWithDirectives.length > 0) {
|
|
83
144
|
for (const input of inputs) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin-template",
|
|
3
|
-
"version": "22.3.
|
|
3
|
+
"version": "22.3.1-alpha.1",
|
|
4
4
|
"description": "ESLint plugin for Angular Templates",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@angular-eslint/bundled-angular-compiler": "22.3.
|
|
23
|
-
"@angular-eslint/utils": "22.3.
|
|
22
|
+
"@angular-eslint/bundled-angular-compiler": "22.3.1-alpha.1",
|
|
23
|
+
"@angular-eslint/utils": "22.3.1-alpha.1",
|
|
24
24
|
"aria-query": "5.3.2",
|
|
25
25
|
"axobject-query": "4.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@angular-eslint/test-utils": "22.3.
|
|
28
|
+
"@angular-eslint/test-utils": "22.3.1-alpha.1",
|
|
29
29
|
"@types/aria-query": "5.0.4"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@angular-eslint/template-parser": "22.3.
|
|
32
|
+
"@angular-eslint/template-parser": "22.3.1-alpha.1",
|
|
33
33
|
"@typescript-eslint/types": "^8.0.0",
|
|
34
34
|
"@typescript-eslint/utils": "^8.0.0",
|
|
35
35
|
"eslint": "^9.0.0 || ^10.0.0",
|