Skip to content

Commit

Permalink
chore(rules): fix import rules target path
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Mar 11, 2024
1 parent e6783b3 commit 269fc3f
Show file tree
Hide file tree
Showing 47 changed files with 107 additions and 1,434 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
2 changes: 1 addition & 1 deletion kayle/builder/build-htmlcs-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const processFile = (filePath, paramList: ParamList[]) => {

if (!guide) {
guide = code.match(
/(_global\.HTMLCS_WCAG2AAA_Sniffs_)([A-Za-z0-9_]+)/,
/(_global\.HTMLCS_WCAG2AAA_Sniffs_)([A-Za-z0-9_]+)/
);
if (guide && guide[2]) {
const end = guide[2].length - 23;
Expand Down
48 changes: 31 additions & 17 deletions kayle/builder/build-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import type { Rule } from "./build-types";
origin: "https://www.example.com",
language,
},
true,
true
);

await Promise.all([
Expand All @@ -54,7 +54,7 @@ import type { Rule } from "./build-types";
content: `window.htmlcsRuleMap = ${htmlcsRuleMap.toString()};`,
}),
page.exposeFunction("pushHtmlcsRule", (t: Rule[]) =>
fast_htmlcs_rules.push(...t),
fast_htmlcs_rules.push(...t)
),
page.exposeFunction("pushAxeRule", (t: Rule) => fast_axe_rules.push(t)),
]);
Expand All @@ -76,32 +76,42 @@ import type { Rule } from "./build-types";

const DNE = "THIS FILE WAS CREATED DYNAMICALLY - DO NOT EDIT";

const rs = new Set();

await writeFile(
`./lib/rules/${language}/htmlcs-rules.ts`,
Buffer.from(
await format(
`/* ${DNE} */\nexport const htmlcsRules = ${JSON.stringify(
fast_htmlcs_rules
.filter((r) => r.description)
.sort((a, b) => a.ruleId.localeCompare(b.ruleId)),
.filter((r) => {
if (rs.has(r.ruleId)) {
return false;
}
rs.add(r.ruleId);
return r.description;
})
.sort((a, b) => a.ruleId.localeCompare(b.ruleId))
)};`,
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.sort((a, b) => a.ruleId.localeCompare(b.ruleId)),
fast_axe_rules.sort((a, b) => a.ruleId.localeCompare(b.ruleId))
)};`,
pConfig,
),
pConfig
)
),
"utf8",
"utf8"
);

await page.close({
Expand All @@ -110,7 +120,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 @@ -130,9 +140,13 @@ import type { Rule } from "./build-types";
};
// import rule list with locales
export const importRules = async (locale: ${localesList.map((l) => `"${l}"`).join(" | ")}, runner: "htmlcs" | "axe"): Promise<Rule[]> => {
export const importRules = async (locale: ${localesList
.map((l) => `"${l}"`)
.join(
" | "
)}, runner: "htmlcs" | "axe", baseDir?: "string"): Promise<Rule[]> => {
const rules = await import(` +
"`./${locale.replace('-', '_')}/${runner === 'htmlcs' ? 'htmlcs' : 'axe'}-rules`" +
"`${baseDir || './'}${locale.replace('-', '_')}/${runner === 'htmlcs' ? 'htmlcs' : 'axe'}-rules`" +
`` +
`);
Expand All @@ -153,10 +167,10 @@ import type { Rule } from "./build-types";
${runnerImports}
`,
pConfig,
),
pConfig
)
),
"utf8",
"utf8"
);

await browser.close();
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 269fc3f

Please sign in to comment.