diff --git a/src/rules/__tests__/form-control-has-label.test.ts b/src/rules/__tests__/form-control-has-label.test.ts index 25c1d0f..152282f 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: [ + "", + "", + { + code: "
", + options: [{ controlComponents: ["b-form-input"] }], + errors: [{ messageId: "default" }], + }, ], - invalid: ["", ""] }); diff --git a/src/rules/form-control-has-label.ts b/src/rules/form-control-has-label.ts index 770dfac..5800fcd 100644 --- a/src/rules/form-control-has-label.ts +++ b/src/rules/form-control-has-label.ts @@ -37,13 +37,31 @@ const rule: Rule.RuleModule = { messages: { default: "Each form element must have a programmatically associated label element." - } + }, + 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; }