Skip to content

Commit

Permalink
chore(rules): fix htmlcs rule builder base
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Mar 9, 2024
1 parent 87c25db commit 9c99361
Show file tree
Hide file tree
Showing 68 changed files with 141,607 additions and 113,977 deletions.
2 changes: 1 addition & 1 deletion kayle/bench/fast_axecore-playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function launchBench() {
unit: "OPS/S",
value: 1000 / avg,
},
])
]),
);
}

Expand Down
2 changes: 1 addition & 1 deletion kayle/bench/fast_htmlcs-playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function launchBench() {
unit: "OPS/S",
value: 1000 / avg,
},
])
]),
);
}

Expand Down
2 changes: 1 addition & 1 deletion kayle/builder/build-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ window.addEventListener("kayle_send", async (event) => {

writeFileSync(
`${ext}/content-script.js`,
`${extensionRunner}\n${extensionAxe}\n${extensionHtmlcs}\n${extensionRawEnd}`
`${extensionRunner}\n${extensionAxe}\n${extensionHtmlcs}\n${extensionRawEnd}`,
);

const extensionManifest = `{
Expand Down
13 changes: 13 additions & 0 deletions kayle/builder/build-htmlcs-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const processFile = (filePath) => {
const code = readFileSync(filePath, "utf8");
const ast = parse(code, { sourceType: "script", ecmaVersion: 2020 });

let guide: RegExpMatchArray | null = null;

simple(ast, {
CallExpression(node) {
if (
Expand Down Expand Up @@ -64,6 +66,17 @@ const processFile = (filePath) => {

params.push(pathParse(filePath).name);

// run regex on first match
if (!guide) {
guide = code.match(
/(_global\.HTMLCS_WCAG2AAA_Sniffs_)([A-Za-z0-9_]+)/,
);
}

if (guide && guide[2]) {
params.push(guide[2]);
}

paramList.push(params as ParamList);
}
},
Expand Down
30 changes: 15 additions & 15 deletions kayle/builder/build-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import type { Rule } from "./build-types";
origin: "https://www.example.com",
language,
},
true
true,
);

const paramList = await processParams();
Expand All @@ -48,11 +48,11 @@ import type { Rule } from "./build-types";
});

await page.exposeFunction("pushHtmlcsRule", (t: Rule) =>
fast_htmlcs_rules.push(t)
fast_htmlcs_rules.push(t),
);

await page.exposeFunction("pushAxeRule", (t: Rule) =>
fast_axe_rules.push(t)
fast_axe_rules.push(t),
);

await page.evaluate(() => {
Expand All @@ -77,25 +77,25 @@ import type { Rule } from "./build-types";
Buffer.from(
await format(
`/* ${DNE} */\nexport const htmlcsRules = ${JSON.stringify(
fast_htmlcs_rules.filter((r) => r.description)
fast_htmlcs_rules.filter((r) => r.description),
)};`,
pConfig
)
pConfig,
),
),
"utf8"
"utf8",
);

await writeFile(
`./lib/rules/${language}/axe-rules.ts`,
Buffer.from(
await format(
`/* ${DNE} */\nexport const axeRules = ${JSON.stringify(
fast_axe_rules
fast_axe_rules,
)};`,
pConfig
)
pConfig,
),
),
"utf8"
"utf8",
);

await page.close({
Expand All @@ -104,7 +104,7 @@ import type { Rule } from "./build-types";
};

const localesList: string[] = Array.from(
new Set(htmlcsLocales.concat(axeLocales))
new Set(htmlcsLocales.concat(axeLocales)),
);

localesList.push("en");
Expand All @@ -121,10 +121,10 @@ import type { Rule } from "./build-types";
export { htmlcsRules as htmlcsRules${l.toUpperCase()} } from "./${l}/htmlcs-rules";`;
})
.join(""),
pConfig
)
pConfig,
),
),
"utf8"
"utf8",
);

await browser.close();
Expand Down
4 changes: 3 additions & 1 deletion kayle/builder/htmlcs-rule-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export const htmlcsRuleMap = (rule: ParamList) => {
: baseRuleId;

return {
ruleId,
ruleId: rule[5]
? `${rule[5].replace("_Guideline", ".Guideline")}.${ruleId}`
: ruleId,
description,
helpUrl: section508
? []
Expand Down
22 changes: 11 additions & 11 deletions kayle/lib/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ export const actions = [
target.dispatchEvent(
new Event("input", {
bubbles: true,
})
}),
);

return Promise.resolve();
},
selector,
value
value,
);
} catch (error) {
throw new Error(`${failedActionElement} "${selector}"`);
Expand Down Expand Up @@ -91,7 +91,7 @@ export const actions = [
target.dispatchEvent(
new Event("input", {
bubbles: true,
})
}),
);
return Promise.resolve();
}, selector);
Expand All @@ -117,12 +117,12 @@ export const actions = [
target.dispatchEvent(
new Event("change", {
bubbles: true,
})
}),
);
return Promise.resolve();
},
selector,
checked
checked,
);
} catch (error) {
throw new Error(`${failedActionElement} "${selector}"`);
Expand Down Expand Up @@ -176,7 +176,7 @@ export const actions = [
{},
property,
expectedValue,
negated
negated,
);
},
},
Expand Down Expand Up @@ -216,7 +216,7 @@ export const actions = [
polling: 200,
},
selector,
state
state,
);
},
},
Expand Down Expand Up @@ -244,11 +244,11 @@ export const actions = [
},
{
once: true,
}
},
);
},
selector,
eventType
eventType,
);

await page.waitForFunction(
Expand All @@ -263,7 +263,7 @@ export const actions = [
},
{
polling: 200,
}
},
);
} catch (error) {
throw new Error(`${failedActionElement} "${selector}"`);
Expand All @@ -283,7 +283,7 @@ export const actions = [
*/
export async function runAction(browser, page, options, act, customActions?) {
const action = (customActions ?? actions).find((item) =>
item.match.test(act)
item.match.test(act),
);

if (!action) {
Expand Down
8 changes: 4 additions & 4 deletions kayle/lib/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function autoKayle(
cb?: ((result: Audit) => Promise<void>) | ((result: Audit) => void);
} = {},
ignoreSet?: Set<String>,
_results?: Audit[]
_results?: Audit[],
): Promise<Audit[]> {
if (!write) {
const { writeFile } = await import("fs/promises");
Expand Down Expand Up @@ -51,7 +51,7 @@ export async function autoKayle(
if (o.store) {
await write(
`${o.store}/${encodeURIComponent(o.page.url())}`,
await o.page.content()
await o.page.content(),
);
}

Expand Down Expand Up @@ -84,7 +84,7 @@ export async function autoKayle(
origin: link,
},
ignoreSet,
_results
_results,
);
})
.catch((e) => {
Expand All @@ -94,7 +94,7 @@ export async function autoKayle(
console.error(e);
}
});
})
}),
);

return _results;
Expand Down
10 changes: 5 additions & 5 deletions kayle/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type BrowserContext = {
newCDPSession?(page: Partial<Page> | Frame): Partial<CDPSession>;
overridePermissions?(
origin: string,
permissions: Permission[]
permissions: Permission[],
): Promise<void>;
};

Expand Down Expand Up @@ -89,7 +89,7 @@ type Page = {
_routes?: { url: string }[];
route(
path: string,
intercept: (config: any, next: any) => Promise<void> | Promise<boolean>
intercept: (config: any, next: any) => Promise<void> | Promise<boolean>,
): Promise<void>;
setRequestInterception?(enable?: boolean): Promise<void>;
listenerCount?(name: string): number;
Expand All @@ -99,19 +99,19 @@ type Page = {
| Function
| {
default: Function;
}
},
): Promise<void>;
addInitScript?(script: { content?: string }): Promise<void>;
evaluateOnNewDocument?<
Params extends unknown[],
Func extends (...args: Params) => unknown = (...args: Params) => unknown
Func extends (...args: Params) => unknown = (...args: Params) => unknown,
>(
pageFunction: Func | string,
...args: Params
): Promise<{ identifier: string }>;
evaluate<
Params extends unknown[],
Func extends EvaluateFunc<Params> = EvaluateFunc<Params>
Func extends EvaluateFunc<Params> = EvaluateFunc<Params>,
>(
pageFunction: Func | string,
...args: Params
Expand Down
16 changes: 8 additions & 8 deletions kayle/lib/kayle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const audit = async (config: RunnerConfig): Promise<Audit> => {
origin: config.origin,
language: config.language,
clip: config.clip,
}
},
);
};

Expand Down Expand Up @@ -61,7 +61,7 @@ const injectRunners = async (config: RunnerConfig) => {
return await Promise.allSettled([
config.page.evaluate(runnersJavascript["kayle"]),
...config.runners.map((r) =>
config.page.evaluate(getRunner(config.language, r))
config.page.evaluate(getRunner(config.language, r)),
),
]);
}
Expand All @@ -77,7 +77,7 @@ export const auditExtension = async (config: RunnerConfig): Promise<Audit> => {
}

window.addEventListener("kayle_receive", (event: CustomEvent) =>
resolve(event.detail.data)
resolve(event.detail.data),
);

window.dispatchEvent(
Expand All @@ -86,7 +86,7 @@ export const auditExtension = async (config: RunnerConfig): Promise<Audit> => {
name: "kayle",
options: runOptions,
},
})
}),
);
});
},
Expand All @@ -100,7 +100,7 @@ export const auditExtension = async (config: RunnerConfig): Promise<Audit> => {
origin: config.origin,
language: config.language,
clip: config.clip,
}
},
);
};

Expand All @@ -121,7 +121,7 @@ const auditPageInnate = async (config: RunnerConf, results: Audit) => {
const innateAudit: InnateIssue[] = await kayle_innate.audit(
html,
css,
config.clip
config.clip,
);

for (const innateIssue of innateAudit) {
Expand Down Expand Up @@ -163,7 +163,7 @@ const auditPageInnate = async (config: RunnerConf, results: Audit) => {
*/
export const kayle = async (
o: RunnerConf = {},
preventClose?: boolean
preventClose?: boolean,
): Promise<Audit> => {
const watcher = new Watcher();
const navigate = o.page.url() === "about:blank" && (o.origin || o.html);
Expand Down Expand Up @@ -212,7 +212,7 @@ export const kayle = async (
}

return item;
})
}),
);
}

Expand Down
Loading

0 comments on commit 9c99361

Please sign in to comment.