Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/rules/__tests__/form-control-has-label.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ makeRuleTester("form-control-has-label", rule, {
<div aria-hidden="true">
<input value="1" type="text" />
</div>
`
`,
"<b-form-input />"
],
invalid: ["<input type='text' />", "<textarea type='text'></textarea>"]
invalid: [
"<input type='text' />",
"<textarea type='text'></textarea>",
{
code: "<div><b-form-input /></div>",
options: [{ controlComponents: ["b-form-input"] }],
errors: [{ messageId: "default" }]
}
]
});
22 changes: 20 additions & 2 deletions src/rules/form-control-has-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,31 @@ const rule: Rule.RuleModule = {
default:
"Each form element must have a programmatically associated label element."
},
schema: []
schema: [
{
type: "object",
properties: {
controlComponents: {
type: "array",
items: {
type: "string"
},
uniqueItems: true
}
}
}
]
},
create(context) {
const { controlComponents: customControlComponents = [] } =
context.options[0] || {};

const controlComponents = ["input", "textarea", ...customControlComponents];

return defineTemplateBodyVisitor(context, {
VElement(node) {
const elementType = getElementType(node);
if (!["input", "textarea"].includes(elementType)) {
if (!controlComponents.includes(elementType)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/rules/tabindex-no-positive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const rule: Rule.RuleModule = {
VElement(node) {
const tabIndex = getLiteralAttributeValue(node, "tabindex");

if (tabIndex && +tabIndex > 0) {
if (tabIndex && Number(tabIndex) > 0) {
context.report({ node: node as any, messageId: "default" });
}
}
Expand Down