From 7c2ac4bf28af1523218a1c9cf1d8dd242004e6ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Hoyer?= Date: Mon, 24 Jan 2022 21:47:32 -0300 Subject: [PATCH 1/2] :sparkles: Allow custom form controls in form-control-has-label Closes #373 --- .../__tests__/form-control-has-label.test.ts | 13 +++++++++-- src/rules/form-control-has-label.ts | 22 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) 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; } From 2f327e6e89ca04482025fc8fb499af9659e2dbdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Hoyer?= Date: Mon, 24 Jan 2022 22:05:49 -0300 Subject: [PATCH 2/2] :recycle: Remove hacky/illegal Number conversion Also typescript doesn't recognize this technique --- src/rules/tabindex-no-positive.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/tabindex-no-positive.ts b/src/rules/tabindex-no-positive.ts index 68a992ec..6e0f5550 100644 --- a/src/rules/tabindex-no-positive.ts +++ b/src/rules/tabindex-no-positive.ts @@ -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" }); } }