From 6e2d2dd8852f0dfa1efebd69e49722c40daf913b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 27 Jun 2024 09:14:14 +0200 Subject: [PATCH] manually fix eslint violations --- src/app.ts | 32 +++++++++++++------------- src/rules/aria-valid-attr-value.ts | 7 ++++-- src/scanner.ts | 2 ++ src/utils.ts | 36 ++++++++++++++++++------------ 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/app.ts b/src/app.ts index b8dc166..62e35ee 100644 --- a/src/app.ts +++ b/src/app.ts @@ -9,24 +9,22 @@ async function ready(): Promise { }); } -(async function () { - await ready(); +await ready(); - const startTime = performance.now(); - const errors = await scan(document.body); - const endTime = performance.now(); +const startTime = performance.now(); +const errors = await scan(document.body); +const endTime = performance.now(); - for (const accessbilityError of errors) { - accessbilityError.element.setAttribute("style", "border: 5px solid red;"); - console.log( - accessbilityError.text, - accessbilityError.element, - accessbilityError.url, - ); - } +for (const accessbilityError of errors) { + accessbilityError.element.setAttribute("style", "border: 5px solid red;"); console.log( - `Took ${(endTime - startTime).toPrecision( - 2, - )}ms to execute accessbility scans`, + accessbilityError.text, + accessbilityError.element, + accessbilityError.url, ); -})(); +} +console.log( + `Took ${(endTime - startTime).toPrecision( + 2, + )}ms to execute accessbility scans`, +); diff --git a/src/rules/aria-valid-attr-value.ts b/src/rules/aria-valid-attr-value.ts index 0492891..e0b5a8c 100644 --- a/src/rules/aria-valid-attr-value.ts +++ b/src/rules/aria-valid-attr-value.ts @@ -65,9 +65,12 @@ function valid(element: Element, attribute: string, info: Info) { return false; } return true; - } else if (info.type === "decimal" && !isNaN(Number.parseFloat(value))) { + } else if ( + info.type === "decimal" && + !Number.isNaN(Number.parseFloat(value)) + ) { return true; - } else if (info.type === "int" && !isNaN(Number.parseInt(value))) { + } else if (info.type === "int" && !Number.isNaN(Number.parseInt(value))) { if (info.minValue != undefined) { return info.minValue <= Number.parseInt(value); } diff --git a/src/scanner.ts b/src/scanner.ts index 34d0a62..72e9ca7 100644 --- a/src/scanner.ts +++ b/src/scanner.ts @@ -50,9 +50,11 @@ export async function requestIdleScan( return new Promise((resolve) => { requestIdleCallback(async function executeScan(deadline: IdleDeadline) { while ( + // eslint-disable-next-line tscompat/tscompat (deadline.timeRemaining() > 0 || deadline.didTimeout) && rules.length > 0 ) { + // eslint-disable-next-line tscompat/tscompat logger.log(deadline.timeRemaining(), deadline.didTimeout); const rule = rules.shift()!; logger.log(`Executing ${rule.name}`); diff --git a/src/utils.ts b/src/utils.ts index 7cdee17..f7ff94f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -25,8 +25,7 @@ export function labelReadableText(label: HTMLElement): boolean { if (!label?.textContent?.trim()) return false; // NOTE: This is expensive and we should look into ways to not do this any more. - const hasDisplayNone = - window.getComputedStyle(label, null).display === "none"; + const hasDisplayNone = window.getComputedStyle(label).display === "none"; if (hasDisplayNone) return false; const copiedNode = label.cloneNode(true) as Element; @@ -42,15 +41,19 @@ type Container = HTMLElement | Element | Document | ShadowRoot; export function querySelector( selector: string, container: Container, - options = { depth: Number.POSITIVE_INFINITY }, -): T | null { - const els = querySelectorAll(selector, container, options); + options, +): T | undefined { + const els = querySelectorAll( + selector, + container, + options || { depth: Number.POSITIVE_INFINITY }, + ); if (Array.isArray(els) && els.length > 0) { return els[0]; } - return null; + return undefined; } /** @@ -68,9 +71,12 @@ export function querySelector( export function querySelectorAll( selector: string, container: Container, - options = { depth: Number.POSITIVE_INFINITY }, + options, ): T[] { - const elements = getAllElementsAndShadowRoots(container, options); + const elements = getAllElementsAndShadowRoots( + container, + options || { depth: Number.POSITIVE_INFINITY }, + ); const queriedElements = elements.flatMap((element) => [ ...element.querySelectorAll(selector), @@ -80,22 +86,24 @@ export function querySelectorAll( // This could probably get really slow and memory intensive in large DOMs, // maybe an infinite generator in the future? -export function getAllElementsAndShadowRoots( - container: Container, - options = { depth: Number.POSITIVE_INFINITY }, -) { +export function getAllElementsAndShadowRoots(container: Container, options) { const selector = "*"; - return recurse(container, selector, options); + return recurse( + container, + selector, + options || { depth: Number.POSITIVE_INFINITY }, + ); } function recurse( container: Container, selector: string, - options = { depth: Number.POSITIVE_INFINITY }, + options, elementsToProcess: Array = [], elements: Array = [], currentDepth = 1, ) { + options = options || { depth: Number.POSITIVE_INFINITY }; // if "document" is passed in, it will also pick up "" causing the query to run twice. if (container instanceof Document) { container = container.documentElement;