Skip to content

Commit 3b3b8d0

Browse files
committed
removed console log statements
1 parent a7b7c4c commit 3b3b8d0

File tree

3 files changed

+43
-54
lines changed

3 files changed

+43
-54
lines changed

lib/rules/input-components-require-accessible-name.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ const rule = ESLintUtils.RuleCreator.withoutDocs({
4242
return;
4343
}
4444

45-
console.log("aria-label::: ", hasNonEmptyProp(node.attributes, "aria-label"));
46-
console.log("hasFieldParent::: ", hasFieldParent(context));
47-
console.log("isInsideLabelTag::: ", isInsideLabelTag(context));
48-
console.log("hasAssociatedLabelViaHtmlFor::: ", hasAssociatedLabelViaHtmlFor(node, context));
49-
console.log("hasAssociatedLabelViaAriaLabelledBy::: ", hasAssociatedLabelViaAriaLabelledBy(node, context));
50-
5145
// wrapped in Label tag, labelled with htmlFor, labelled with aria-labelledby
5246
if (
5347
hasNonEmptyProp(node.attributes, "aria-label") ||

lib/util/labelUtils.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ const hasLabelWithHtmlForId = (idValue: string, context: TSESLint.RuleContext<st
4040
return false;
4141
}
4242
const sourceCode = context.getSourceCode();
43-
console.log("sourceCode", sourceCode.getText()); // Optional debugging
4443

45-
const regex = /<(Label|label)[^>]*htmlFor[^>]*=["{']([^"'{}]*)["'}]/gi;
44+
const regex = /<(Label|label)[^>]*\bid\b\s*=\s*["{']([^"'{}]*)["'}]/gi;
45+
4646
let match;
4747
while ((match = regex.exec(sourceCode.text)) !== null) {
4848
// `match[2]` contains the `htmlFor` attribute value
@@ -66,9 +66,9 @@ const hasLabelWithHtmlId = (idValue: string, context: TSESLint.RuleContext<strin
6666
return false;
6767
}
6868
const sourceCode = context.getSourceCode();
69-
console.log("sourceCode", sourceCode.getText());
7069

71-
const regex = /<(Label|label)[^>]*id[^>]*=["{']([^"'{}]*)["'}]/gi;
70+
const regex = /<(Label|label)[^>]*\bid\b\s*=\s*["{']([^"'{}]*)["'}]/gi;
71+
7272
let match;
7373
while ((match = regex.exec(sourceCode.text)) !== null) {
7474
// match[2] should contain the id value
@@ -93,10 +93,10 @@ const hasOtherElementWithHtmlId = (idValue: string, context: TSESLint.RuleContex
9393
return false;
9494
}
9595
const sourceCode: string = context.getSourceCode().text;
96-
console.log("sourceCode", sourceCode); // For debugging, if needed
9796

9897
// Adjusted regex pattern for elements with `id` attribute
99-
const regex = /<(div|span|p|h[1-6])[^>]*id[^>]*=["{']([^"'{}]*)["'}]/gi;
98+
const regex = /<(div|span|p|h[1-6])[^>]*\bid\b\s*=\s*["{']([^"'{}]*)["'}]/gi;
99+
100100
let match;
101101
while ((match = regex.exec(sourceCode)) !== null) {
102102
// `match[2]` contains the `id` value in each matched element
@@ -121,7 +121,6 @@ const hasAssociatedLabelViaAriaLabelledBy = (
121121
context: TSESLint.RuleContext<string, unknown[]>
122122
): boolean => {
123123
const _hasAriaLabelledBy = hasNonEmptyProp(openingElement.attributes, "aria-labelledby");
124-
console.log(" --- _hasAriaLabelledBy::", _hasAriaLabelledBy);
125124
const prop = getProp(openingElement.attributes as unknown as JSXOpeningElement["attributes"], "aria-labelledby");
126125

127126
// Check if the prop exists before passing it to getPropValue
@@ -133,10 +132,7 @@ const hasAssociatedLabelViaAriaLabelledBy = (
133132
}
134133

135134
const hasHtmlId = hasLabelWithHtmlId(idValue, context);
136-
console.log(" --- hasHtmlId::", hasHtmlId);
137-
138135
const hasElementWithHtmlId = hasOtherElementWithHtmlId(idValue, context);
139-
console.log(" --- hasElementWithHtmlId:::", hasElementWithHtmlId);
140136

141137
return _hasAriaLabelledBy && (hasHtmlId || hasElementWithHtmlId);
142138
};

tests/lib/rules/input-components-require-accessible-name.test.ts

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,40 @@ function generateTestCases(labelComponent: string, componentName: string) {
3131
function generateTestCasesLabel(labelComponent: string, componentName: string) {
3232
return {
3333
valid: [
34-
// `<><${labelComponent} htmlFor="some-id">Some Label</${labelComponent}><${componentName} id="some-id"/></>`,
35-
// `<><${labelComponent} id="test-span">Some Label</${labelComponent}><${componentName} id="some-id" aria-labelledby="test-span"/></>`,
36-
// `<${labelComponent}>test</${labelComponent}>`,
37-
// `<${labelComponent}>test<${componentName} /></${labelComponent}>`,
38-
// `<${labelComponent}>test<SomeNesting><${componentName} /></SomeNesting></${labelComponent}>`,
39-
// `<Field label="this is my label"><${componentName} /></Field>`,
40-
// `<${componentName} aria-label="this is my component" />`,
34+
`<><${labelComponent} htmlFor="some-id">Some Label</${labelComponent}><${componentName} id="some-id"/></>`,
35+
`<><${labelComponent} id="test-span">Some Label</${labelComponent}><${componentName} id="some-id" aria-labelledby="test-span"/></>`,
36+
`<${labelComponent}>test</${labelComponent}>`,
37+
`<${labelComponent}>test<${componentName} /></${labelComponent}>`,
38+
`<${labelComponent}>test<SomeNesting><${componentName} /></SomeNesting></${labelComponent}>`,
39+
`<Field label="this is my label"><${componentName} /></Field>`,
40+
`<${componentName} aria-label="this is my component" />`,
4141
`<><${labelComponent} id="paragraph_label-2">type here</${labelComponent}><${componentName} aria-labelledby="paragraph_label-2"></${componentName}><${labelComponent} id="paragraph_label-3">type here</${labelComponent}><${componentName} aria-labelledby="paragraph_label-3"></${componentName}></>`
4242
],
4343
invalid: [
44-
// {
45-
// code: `<><${componentName}/></>`,
46-
// errors: [{ messageId: "missingLabelOnInput" }]
47-
// },
48-
// {
49-
// code: `<><${labelComponent}/><${componentName}/></>`,
50-
// errors: [{ messageId: "missingLabelOnInput" }]
51-
// },
52-
// {
53-
// code: `<><${labelComponent} htmlFor="id"/><${componentName} /></>`,
54-
// errors: [{ messageId: "missingLabelOnInput" }]
55-
// },
56-
// {
57-
// code: `<${componentName} id="some-id"/>`,
58-
// errors: [{ messageId: "missingLabelOnInput" }]
59-
// },
60-
// {
61-
// code: `<><${labelComponent}>Some Label</${labelComponent}><${componentName} id="some-id"/></>`,
62-
// errors: [{ messageId: "missingLabelOnInput" }]
63-
// },
64-
// {
65-
// code: `<><Field></Field><${componentName} id="some-id"/></>`,
66-
// errors: [{ messageId: "missingLabelOnInput" }]
67-
// }
44+
{
45+
code: `<><${componentName}/></>`,
46+
errors: [{ messageId: "missingLabelOnInput" }]
47+
},
48+
{
49+
code: `<><${labelComponent}/><${componentName}/></>`,
50+
errors: [{ messageId: "missingLabelOnInput" }]
51+
},
52+
{
53+
code: `<><${labelComponent} htmlFor="id"/><${componentName} /></>`,
54+
errors: [{ messageId: "missingLabelOnInput" }]
55+
},
56+
{
57+
code: `<${componentName} id="some-id"/>`,
58+
errors: [{ messageId: "missingLabelOnInput" }]
59+
},
60+
{
61+
code: `<><${labelComponent}>Some Label</${labelComponent}><${componentName} id="some-id"/></>`,
62+
errors: [{ messageId: "missingLabelOnInput" }]
63+
},
64+
{
65+
code: `<><Field></Field><${componentName} id="some-id"/></>`,
66+
errors: [{ messageId: "missingLabelOnInput" }]
67+
}
6868
]
6969
};
7070
}
@@ -73,15 +73,14 @@ function generateAllTestCases() {
7373
const testSets: any[] = [];
7474

7575
// For each input-based component, generate test cases
76-
["Input"].forEach(components => {
77-
// applicableComponents.forEach(components => {
78-
// elementsUsedAsLabels.forEach(labels => {
79-
// testSets.push(generateTestCases(labels, components));
80-
// });
76+
77+
applicableComponents.forEach(components => {
78+
elementsUsedAsLabels.forEach(labels => {
79+
testSets.push(generateTestCases(labels, components));
80+
});
8181

8282
// Also generate test cases for each native DOM element
83-
["Label"].forEach(labels => {
84-
// labelBasedComponents.forEach(labels => {
83+
labelBasedComponents.forEach(labels => {
8584
testSets.push(generateTestCasesLabel(labels, components));
8685
});
8786
});

0 commit comments

Comments
 (0)