-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy patharia_attribute_deprecated.ts
More file actions
71 lines (66 loc) · 3.27 KB
/
aria_attribute_deprecated.ts
File metadata and controls
71 lines (66 loc) · 3.27 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/******************************************************************************
Copyright:: 2022- IBM, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*****************************************************************************/
import { Rule, RuleResult, RuleFail, RuleContext, RuleContextHierarchy } from "../api/IRule";
import { eRulePolicy, eToolkitLevel } from "../api/IRule";
import { AriaUtil } from "../util/AriaUtil";
export const aria_attribute_deprecated: Rule = {
id: "aria_attribute_deprecated",
context: "dom:*",
help: {
"en-US": {
// "pass": "aria_attribute_deprecated.html",
"fail_aria_role": "aria_attribute_deprecated.html",
"fail_aria_attr": "aria_attribute_deprecated.html",
"fail_role_attr": "aria_attribute_deprecated.html",
"group": "aria_attribute_deprecated.html"
}
},
messages: {
"en-US": {
// "pass": "The ARIA roles and attribute are used per specification",
"fail_aria_role": "The ARIA role \"{0}\" is deprecated in the ARIA specification",
"fail_aria_attr": "The ARIA attributes \"{0}\" are deprecated in the ARIA specification",
"fail_role_attr": "The ARIA attributes \"{0}\" are deprecated for the role \"{1}\" in the ARIA specification",
"group": "No deprecated ARIA role or attribute should be used"
}
},
rulesets: [{
"id": ["IBM_Accessibility", "IBM_Accessibility_next"],
"num": ["ARIA"],
"level": eRulePolicy.RECOMMENDATION,
"toolkitLevel": eToolkitLevel.LEVEL_THREE
}],
act: [],
run: (context: RuleContext, options?: {}, contextHierarchies?: RuleContextHierarchy): RuleResult | RuleResult[] => {
const ruleContext = context["dom"].node as Element;
let ret = [];
const deprecatedRoles = AriaUtil.getDeprecatedAriaRoles(ruleContext);
if (deprecatedRoles && deprecatedRoles.length > 0) {
for (let i = 0; i < deprecatedRoles.length; i++)
ret.push(RuleFail('fail_aria_role', [deprecatedRoles[i]]));
}
const deprecatedAttributes = AriaUtil.getDeprecatedAriaAttributes(ruleContext);
if (deprecatedAttributes && deprecatedAttributes.length > 0) {
for (let i = 0; i < deprecatedAttributes.length; i++) {
// "role":"any", "attribute":ariaAttrs[i]}
if (deprecatedAttributes[i].role === 'any')
ret.push(RuleFail('fail_aria_attr', [deprecatedAttributes[i].attribute]));
else
ret.push(RuleFail('fail_role_attr', [deprecatedAttributes[i].attribute, deprecatedAttributes[i].role]));
}
}
if (ret.length > 0)
return ret;
return null;
}
}