Skip to content

Commit 94cb84f

Browse files
Address Review comments with regards to lint
1 parent 32d7d3f commit 94cb84f

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/util/labelUtils.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import { elementType } from "jsx-ast-utils";
55
import { getPropValue } from "jsx-ast-utils";
66
import { getProp } from "jsx-ast-utils";
7-
import { hasNonEmptyProp } from "./hasNonEmptyProp";
87
import { TSESLint } from "@typescript-eslint/utils";
98
import { JSXOpeningElement } from "estree-jsx";
109
import { TSESTree } from "@typescript-eslint/utils";
@@ -133,7 +132,9 @@ const hasAssociatedAriaText = (
133132
const varName = expr.name as string;
134133
const src = getSourceText(context);
135134
const labelMatch = new RegExp(`<(?:Label|label)[^>]*\\bid\\s*=\\s*\\{\\s*${escapeForRegExp(varName)}\\s*\\}`, "i").test(src);
136-
const otherMatch = new RegExp(`<(?:div|span|p|h[1-6])[^>]*\\bid\\s*=\\s*\\{\\s*${escapeForRegExp(varName)}\\s*\\}`, "i").test(src);
135+
const otherMatch = new RegExp(`<(?:div|span|p|h[1-6])[^>]*\\bid\\s*=\\s*\\{\\s*${escapeForRegExp(varName)}\\s*\\}`, "i").test(
136+
src
137+
);
137138
return labelMatch || otherMatch;
138139
}
139140
}
@@ -142,11 +143,15 @@ const hasAssociatedAriaText = (
142143
};
143144

144145
/* thin wrappers kept for compatibility with existing callers */
145-
const hasAssociatedLabelViaAriaLabelledBy = (openingElement: TSESTree.JSXOpeningElement, context: TSESLint.RuleContext<string, unknown[]>) =>
146-
hasAssociatedAriaText(openingElement, context, "aria-labelledby");
146+
const hasAssociatedLabelViaAriaLabelledBy = (
147+
openingElement: TSESTree.JSXOpeningElement,
148+
context: TSESLint.RuleContext<string, unknown[]>
149+
) => hasAssociatedAriaText(openingElement, context, "aria-labelledby");
147150

148-
const hasAssociatedLabelViaAriaDescribedby = (openingElement: TSESTree.JSXOpeningElement, context: TSESLint.RuleContext<string, unknown[]>) =>
149-
hasAssociatedAriaText(openingElement, context, "aria-describedby");
151+
const hasAssociatedLabelViaAriaDescribedby = (
152+
openingElement: TSESTree.JSXOpeningElement,
153+
context: TSESLint.RuleContext<string, unknown[]>
154+
) => hasAssociatedAriaText(openingElement, context, "aria-describedby");
150155

151156
/**
152157
* htmlFor / id relationship helper for controls (string + identifier fallback)

tests/lib/rules/utils/labelUtils.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ describe("labelUtils", () => {
100100
});
101101

102102
test("returns true if aria-labelledby references an existing label element without duplicates (literal)", () => {
103-
const customContext = mockContext("<Label id='existing-label-id'>Test Label</Label><Label id='existing-label-id-2'>Test Label</Label>");
103+
const customContext = mockContext(
104+
"<Label id='existing-label-id'>Test Label</Label><Label id='existing-label-id-2'>Test Label</Label>"
105+
);
104106
openingElement.attributes = [createJSXAttributeLiteral("aria-labelledby", "existing-label-id")];
105107
const result = hasAssociatedLabelViaAriaLabelledBy(openingElement, customContext);
106108
expect(result).toBe(true);

0 commit comments

Comments
 (0)