diff --git a/lib/rules/swatchpicker-needs-labelling.ts b/lib/rules/swatchpicker-needs-labelling.ts index eeb163e..b581366 100644 --- a/lib/rules/swatchpicker-needs-labelling.ts +++ b/lib/rules/swatchpicker-needs-labelling.ts @@ -11,12 +11,15 @@ import { makeLabeledControlRule } from "../util/ruleFactory"; export default ESLintUtils.RuleCreator.withoutDocs( makeLabeledControlRule({ component: "SwatchPicker", + messageId: "noUnlabeledSwatchPicker", + description: "Accessibility: SwatchPicker must have an accessible name via aria-label, aria-labelledby, Field component, etc..", labelProps: ["aria-label"], allowFieldParent: true, - allowFor: false, + allowHtmlFor: false, allowLabelledBy: true, allowWrappingLabel: false, - messageId: "noUnlabeledSwatchPicker", - description: "Accessibility: SwatchPicker must have an accessible name via aria-label, aria-labelledby, Field component, etc.." + allowTooltipParent: false, + allowDescribedBy: false, + allowLabeledChild: false }) ); diff --git a/lib/util/hasLabeledChild.ts b/lib/util/hasLabeledChild.ts new file mode 100644 index 0000000..3743cfd --- /dev/null +++ b/lib/util/hasLabeledChild.ts @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { TSESLint, TSESTree } from "@typescript-eslint/utils"; + +// eslint-disable-next-line no-unused-vars +export const hasLabeledChild = (openingElement: TSESTree.JSXOpeningElement, context: TSESLint.RuleContext): boolean => { + // TODO: function not yet implemented + return false; +}; diff --git a/lib/util/ruleFactory.ts b/lib/util/ruleFactory.ts index fe5dda1..3b70bcc 100644 --- a/lib/util/ruleFactory.ts +++ b/lib/util/ruleFactory.ts @@ -3,86 +3,79 @@ import { TSESLint, TSESTree } from "@typescript-eslint/utils"; import { hasNonEmptyProp } from "./hasNonEmptyProp"; -import { hasAssociatedLabelViaAriaLabelledBy, isInsideLabelTag, hasAssociatedLabelViaHtmlFor } from "./labelUtils"; +import { + hasAssociatedLabelViaAriaLabelledBy, + isInsideLabelTag, + hasAssociatedLabelViaHtmlFor, + hasAssociatedLabelViaAriaDescribedby +} from "./labelUtils"; import { hasFieldParent } from "./hasFieldParent"; import { elementType } from "jsx-ast-utils"; import { JSXOpeningElement } from "estree-jsx"; +import { hasToolTipParent } from "./hasTooltipParent"; +import { hasLabeledChild } from "./hasLabeledChild"; export type LabeledControlConfig = { component: string | RegExp; - labelProps: string[]; // e.g. ["label", "aria-label"] - allowFieldParent: boolean; // e.g. - allowFor: boolean; // htmlFor - allowLabelledBy: boolean; // aria-labelledby - allowWrappingLabel: boolean; // messageId: string; description: string; + labelProps: string[]; // e.g. ["aria-label", "title", "label"] + /** Accept a parent wrapper as providing the label. */ + allowFieldParent: boolean; // default false + allowHtmlFor: boolean /** Accept