Skip to content

Commit e480281

Browse files
authored
Merge pull request #622 from vue-a11y/updates
Updates
2 parents 4fed162 + fce67b1 commit e480281

11 files changed

+907
-1367
lines changed

Diff for: docs/accessible-emoji.md

-26
This file was deleted.

Diff for: docs/form-control-has-label.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ This rule takes one optional object argument of type object:
1616
"vuejs-accessibility/form-control-has-label": [
1717
"error",
1818
{
19-
"labelComponents": ["CustomLabel"]
19+
"labelComponents": ["CustomLabel"],
20+
"controlComponents": ["CustomInput"]
2021
}
2122
]
2223
}
@@ -25,6 +26,8 @@ This rule takes one optional object argument of type object:
2526

2627
For the `labelComponents` option, these strings determine which elements (**always including** `<label>`) should be checked for having the `for` prop. This is a good use case when you have a wrapper component that simply renders a `label` element.
2728

29+
For the `controlComponents` option, these strings determine which elements (**always including** `<input>`, `<textarea>` and `<select>`) should be checked for having an associated label. This is a good use case when you have a wrapper component that simply renders an input element.
30+
2831
### Succeed
2932

3033
```

Diff for: package.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,24 @@
2727
"eslint": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
2828
},
2929
"dependencies": {
30-
"aria-query": "^5.0.0",
30+
"aria-query": ">=5.0.0",
3131
"emoji-regex": "^10.0.0",
3232
"vue-eslint-parser": "^9.0.1"
3333
},
3434
"devDependencies": {
3535
"@types/aria-query": "^5.0.0",
3636
"@types/eslint-scope": "^3.7.2",
37-
"@types/eslint-visitor-keys": "^3.3.0",
38-
"@types/jest": "^27.0.0",
37+
"@types/jest": "^29.2.0",
3938
"@types/node": "^18.0.0",
4039
"@typescript-eslint/eslint-plugin": "^5.10.2",
4140
"@typescript-eslint/parser": "^5.10.2",
4241
"eslint": "^8.8.0",
4342
"eslint-plugin-eslint-plugin": "^5.0.0",
4443
"husky": "^8.0.1",
45-
"jest": "^27.4.5",
44+
"jest": "^29.2.2",
4645
"prettier": "^2.1.1",
4746
"pretty-quick": "^3.1.3",
48-
"ts-jest": "^27.1.2",
47+
"ts-jest": "^29.0.3",
4948
"ts-node": "^10.3.0",
5049
"typescript": "^4.5.4"
5150
},
@@ -79,9 +78,6 @@
7978
}
8079
},
8180
"jest": {
82-
"moduleNameMapper": {
83-
"@eslint/eslintrc/universal": "@eslint/eslintrc/dist/eslintrc-universal.cjs"
84-
},
8581
"preset": "ts-jest",
8682
"setupFilesAfterEnv": [
8783
"./jest.setup.ts"

Diff for: src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import recommended from "./configs/recommended";
22

3-
import accessibleEmoji from "./rules/accessible-emoji";
43
import altText from "./rules/alt-text";
54
import anchorHasContent from "./rules/anchor-has-content";
65
import ariaProps from "./rules/aria-props";
@@ -27,7 +26,6 @@ const plugin = {
2726
recommended
2827
},
2928
rules: {
30-
"accessible-emoji": accessibleEmoji,
3129
"alt-text": altText,
3230
"anchor-has-content": anchorHasContent,
3331
"aria-props": ariaProps,

Diff for: src/rules/__tests__/accessible-emoji.test.ts

-19
This file was deleted.

Diff for: src/rules/__tests__/form-control-has-label.test.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ makeRuleTester("form-control-has-label", rule, {
2525
{
2626
code: "<custom-label for='input'>text</custom-label><input type='text' id='input' />",
2727
options: [{ labelComponents: ["CustomLabel"] }]
28-
}
28+
},
29+
"<b-form-input />"
2930
],
3031
invalid: [
3132
"<input type='text' />",
3233
"<textarea type='text'></textarea>",
33-
"<custom-label for='input'>text</custom-label><input type='text' id='input' />"
34+
"<custom-label for='input'>text</custom-label><input type='text' id='input' />",
35+
{
36+
code: "<div><b-form-input /></div>",
37+
options: [{ controlComponents: ["b-form-input"] }],
38+
errors: [{ messageId: "default" }]
39+
}
3440
]
3541
});

Diff for: src/rules/accessible-emoji.ts

-46
This file was deleted.

Diff for: src/rules/form-control-has-label.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ const rule: Rule.RuleModule = {
6161
type: "string"
6262
},
6363
uniqueItems: true
64+
},
65+
controlComponents: {
66+
type: "array",
67+
items: {
68+
type: "string"
69+
},
70+
uniqueItems: true
6471
}
6572
}
6673
}
@@ -70,21 +77,23 @@ const rule: Rule.RuleModule = {
7077
return defineTemplateBodyVisitor(context, {
7178
VElement(node) {
7279
const options = context.options[0] || {};
73-
const elementType = getElementType(node);
80+
const controlComponents = [
81+
"input",
82+
"textarea",
83+
"select",
84+
...(options.controlComponents || [])
85+
];
7486

75-
if (!["input", "textarea", "select"].includes(elementType)) {
87+
const elementType = getElementType(node);
88+
if (!controlComponents.includes(elementType)) {
7689
return;
7790
}
7891

7992
if (elementType === "input") {
8093
const type = getElementAttributeValue(node, "type");
94+
const types = ["hidden", "button", "image", "submit", "reset"];
8195

82-
if (
83-
!type ||
84-
["hidden", "button", "image", "submit", "reset"].includes(
85-
type as any
86-
)
87-
) {
96+
if (!type || types.includes(type as any)) {
8897
return;
8998
}
9099
}

Diff for: src/rules/interactive-supports-focus.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Rule } from "eslint";
22
import type { AST } from "vue-eslint-parser";
3-
import { ARIARoleDefintionKey, dom, roles } from "aria-query";
3+
import { ARIARoleDefinitionKey, dom, roles } from "aria-query";
44

55
import {
66
defineTemplateBodyVisitor,
@@ -15,7 +15,7 @@ import {
1515
makeDocsURL
1616
} from "../utils";
1717

18-
const interactiveRoles: ARIARoleDefintionKey[] = [];
18+
const interactiveRoles: ARIARoleDefinitionKey[] = [];
1919

2020
for (const [role, definition] of roles.entries()) {
2121
if (
@@ -97,7 +97,7 @@ function hasTabIndex(node: AST.VElement) {
9797

9898
interface InteractiveSupportsFocus extends Rule.RuleModule {
9999
interactiveHandlers: string[];
100-
interactiveRoles: ARIARoleDefintionKey[];
100+
interactiveRoles: ARIARoleDefinitionKey[];
101101
}
102102

103103
const rule: InteractiveSupportsFocus = {

Diff for: src/rules/role-has-required-aria-props.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Rule } from "eslint";
22
import type { AST } from "vue-eslint-parser";
3-
import { ARIARoleDefintionKey, dom, roles } from "aria-query";
3+
import { ARIARoleDefinitionKey, dom, roles } from "aria-query";
44

55
import {
66
defineTemplateBodyVisitor,
@@ -14,7 +14,7 @@ function hasAttributes(node: AST.VElement, names: string[]) {
1414
return names.every((name) => getElementAttribute(node, name) !== null);
1515
}
1616

17-
function isAriaRoleDefinitionKey(role: any): role is ARIARoleDefintionKey {
17+
function isAriaRoleDefinitionKey(role: any): role is ARIARoleDefinitionKey {
1818
return roles.has(role);
1919
}
2020

0 commit comments

Comments
 (0)