Skip to content

Commit

Permalink
removed console log statements
Browse files Browse the repository at this point in the history
  • Loading branch information
aubreyquinn committed Nov 8, 2024
1 parent a7b7c4c commit 3b3b8d0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 54 deletions.
6 changes: 0 additions & 6 deletions lib/rules/input-components-require-accessible-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ const rule = ESLintUtils.RuleCreator.withoutDocs({
return;
}

console.log("aria-label::: ", hasNonEmptyProp(node.attributes, "aria-label"));
console.log("hasFieldParent::: ", hasFieldParent(context));
console.log("isInsideLabelTag::: ", isInsideLabelTag(context));
console.log("hasAssociatedLabelViaHtmlFor::: ", hasAssociatedLabelViaHtmlFor(node, context));
console.log("hasAssociatedLabelViaAriaLabelledBy::: ", hasAssociatedLabelViaAriaLabelledBy(node, context));

// wrapped in Label tag, labelled with htmlFor, labelled with aria-labelledby
if (
hasNonEmptyProp(node.attributes, "aria-label") ||
Expand Down
16 changes: 6 additions & 10 deletions lib/util/labelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const hasLabelWithHtmlForId = (idValue: string, context: TSESLint.RuleContext<st
return false;
}
const sourceCode = context.getSourceCode();
console.log("sourceCode", sourceCode.getText()); // Optional debugging

const regex = /<(Label|label)[^>]*htmlFor[^>]*=["{']([^"'{}]*)["'}]/gi;
const regex = /<(Label|label)[^>]*\bid\b\s*=\s*["{']([^"'{}]*)["'}]/gi;

let match;
while ((match = regex.exec(sourceCode.text)) !== null) {
// `match[2]` contains the `htmlFor` attribute value
Expand All @@ -66,9 +66,9 @@ const hasLabelWithHtmlId = (idValue: string, context: TSESLint.RuleContext<strin
return false;
}
const sourceCode = context.getSourceCode();
console.log("sourceCode", sourceCode.getText());

const regex = /<(Label|label)[^>]*id[^>]*=["{']([^"'{}]*)["'}]/gi;
const regex = /<(Label|label)[^>]*\bid\b\s*=\s*["{']([^"'{}]*)["'}]/gi;

let match;
while ((match = regex.exec(sourceCode.text)) !== null) {
// match[2] should contain the id value
Expand All @@ -93,10 +93,10 @@ const hasOtherElementWithHtmlId = (idValue: string, context: TSESLint.RuleContex
return false;
}
const sourceCode: string = context.getSourceCode().text;
console.log("sourceCode", sourceCode); // For debugging, if needed

// Adjusted regex pattern for elements with `id` attribute
const regex = /<(div|span|p|h[1-6])[^>]*id[^>]*=["{']([^"'{}]*)["'}]/gi;
const regex = /<(div|span|p|h[1-6])[^>]*\bid\b\s*=\s*["{']([^"'{}]*)["'}]/gi;

let match;
while ((match = regex.exec(sourceCode)) !== null) {
// `match[2]` contains the `id` value in each matched element
Expand All @@ -121,7 +121,6 @@ const hasAssociatedLabelViaAriaLabelledBy = (
context: TSESLint.RuleContext<string, unknown[]>
): boolean => {
const _hasAriaLabelledBy = hasNonEmptyProp(openingElement.attributes, "aria-labelledby");
console.log(" --- _hasAriaLabelledBy::", _hasAriaLabelledBy);
const prop = getProp(openingElement.attributes as unknown as JSXOpeningElement["attributes"], "aria-labelledby");

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

const hasHtmlId = hasLabelWithHtmlId(idValue, context);
console.log(" --- hasHtmlId::", hasHtmlId);

const hasElementWithHtmlId = hasOtherElementWithHtmlId(idValue, context);
console.log(" --- hasElementWithHtmlId:::", hasElementWithHtmlId);

return _hasAriaLabelledBy && (hasHtmlId || hasElementWithHtmlId);
};
Expand Down
75 changes: 37 additions & 38 deletions tests/lib/rules/input-components-require-accessible-name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,40 @@ function generateTestCases(labelComponent: string, componentName: string) {
function generateTestCasesLabel(labelComponent: string, componentName: string) {
return {
valid: [
// `<><${labelComponent} htmlFor="some-id">Some Label</${labelComponent}><${componentName} id="some-id"/></>`,
// `<><${labelComponent} id="test-span">Some Label</${labelComponent}><${componentName} id="some-id" aria-labelledby="test-span"/></>`,
// `<${labelComponent}>test</${labelComponent}>`,
// `<${labelComponent}>test<${componentName} /></${labelComponent}>`,
// `<${labelComponent}>test<SomeNesting><${componentName} /></SomeNesting></${labelComponent}>`,
// `<Field label="this is my label"><${componentName} /></Field>`,
// `<${componentName} aria-label="this is my component" />`,
`<><${labelComponent} htmlFor="some-id">Some Label</${labelComponent}><${componentName} id="some-id"/></>`,
`<><${labelComponent} id="test-span">Some Label</${labelComponent}><${componentName} id="some-id" aria-labelledby="test-span"/></>`,
`<${labelComponent}>test</${labelComponent}>`,
`<${labelComponent}>test<${componentName} /></${labelComponent}>`,
`<${labelComponent}>test<SomeNesting><${componentName} /></SomeNesting></${labelComponent}>`,
`<Field label="this is my label"><${componentName} /></Field>`,
`<${componentName} aria-label="this is my component" />`,
`<><${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}></>`
],
invalid: [
// {
// code: `<><${componentName}/></>`,
// errors: [{ messageId: "missingLabelOnInput" }]
// },
// {
// code: `<><${labelComponent}/><${componentName}/></>`,
// errors: [{ messageId: "missingLabelOnInput" }]
// },
// {
// code: `<><${labelComponent} htmlFor="id"/><${componentName} /></>`,
// errors: [{ messageId: "missingLabelOnInput" }]
// },
// {
// code: `<${componentName} id="some-id"/>`,
// errors: [{ messageId: "missingLabelOnInput" }]
// },
// {
// code: `<><${labelComponent}>Some Label</${labelComponent}><${componentName} id="some-id"/></>`,
// errors: [{ messageId: "missingLabelOnInput" }]
// },
// {
// code: `<><Field></Field><${componentName} id="some-id"/></>`,
// errors: [{ messageId: "missingLabelOnInput" }]
// }
{
code: `<><${componentName}/></>`,
errors: [{ messageId: "missingLabelOnInput" }]
},
{
code: `<><${labelComponent}/><${componentName}/></>`,
errors: [{ messageId: "missingLabelOnInput" }]
},
{
code: `<><${labelComponent} htmlFor="id"/><${componentName} /></>`,
errors: [{ messageId: "missingLabelOnInput" }]
},
{
code: `<${componentName} id="some-id"/>`,
errors: [{ messageId: "missingLabelOnInput" }]
},
{
code: `<><${labelComponent}>Some Label</${labelComponent}><${componentName} id="some-id"/></>`,
errors: [{ messageId: "missingLabelOnInput" }]
},
{
code: `<><Field></Field><${componentName} id="some-id"/></>`,
errors: [{ messageId: "missingLabelOnInput" }]
}
]
};
}
Expand All @@ -73,15 +73,14 @@ function generateAllTestCases() {
const testSets: any[] = [];

// For each input-based component, generate test cases
["Input"].forEach(components => {
// applicableComponents.forEach(components => {
// elementsUsedAsLabels.forEach(labels => {
// testSets.push(generateTestCases(labels, components));
// });

applicableComponents.forEach(components => {
elementsUsedAsLabels.forEach(labels => {
testSets.push(generateTestCases(labels, components));
});

// Also generate test cases for each native DOM element
["Label"].forEach(labels => {
// labelBasedComponents.forEach(labels => {
labelBasedComponents.forEach(labels => {
testSets.push(generateTestCasesLabel(labels, components));
});
});
Expand Down

0 comments on commit 3b3b8d0

Please sign in to comment.