diff --git a/src/rules/__tests__/form-control-has-label.test.ts b/src/rules/__tests__/form-control-has-label.test.ts index 25c1d0f9..8210c09e 100644 --- a/src/rules/__tests__/form-control-has-label.test.ts +++ b/src/rules/__tests__/form-control-has-label.test.ts @@ -21,7 +21,16 @@ makeRuleTester("form-control-has-label", rule, { - ` + `, + "" ], - invalid: ["", ""] + invalid: [ + "", + "", + { + code: "
", + options: [{ controlComponents: ["b-form-input"] }], + errors: [{ messageId: "default" }] + } + ] }); diff --git a/src/rules/form-control-has-label.ts b/src/rules/form-control-has-label.ts index 037846c7..e406f20c 100644 --- a/src/rules/form-control-has-label.ts +++ b/src/rules/form-control-has-label.ts @@ -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; }