Skip to content

Commit

Permalink
chore(rules): fix htmlcs rules map
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Mar 9, 2024
1 parent 3b0f0ef commit 4f1e2ca
Show file tree
Hide file tree
Showing 6 changed files with 362 additions and 677 deletions.
19 changes: 18 additions & 1 deletion kayle/builder/build-htmlcs-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { lstatSync, readdirSync, readFileSync } from "fs";
import { join, parse as pathParse } from "path";
import { parse } from "acorn";
import { simple } from "acorn-walk";
import { generate } from "escodegen";
import type { ParamList } from "./build-types";

const paramList: ParamList[] = [];
Expand Down Expand Up @@ -30,18 +31,34 @@ const processFile = (filePath) => {
// @ts-ignore
node.callee.property.name === "addMessage"
) {
const params = node.arguments.map((arg) => {
const params = node.arguments.map((arg, index) => {
if (arg.type === "Literal") {
return arg.value;
}
if (arg.type === "Identifier") {
return arg.name;
}

if (arg.type === "MemberExpression") {
// @ts-ignore
return arg.property.name?.toLowerCase();
}

if (
index === 2 &&
arg.type === "CallExpression" &&
// @ts-ignore
arg.callee?.object?.object?.name === "_global" &&
// @ts-ignore
arg.callee?.object?.property?.name === "HTMLCS" &&
// @ts-ignore
arg.callee?.property?.name === "getTranslation"
) {
if (arg.arguments.length) {
return generate(arg).replace("_global.", "");
}
}

return null;
});

Expand Down
2 changes: 1 addition & 1 deletion kayle/builder/build-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import type { Rule } from "./build-types";
Buffer.from(
await format(
`/* ${DNE} */\nexport const htmlcsRules = ${JSON.stringify(
fast_htmlcs_rules,
fast_htmlcs_rules.filter((r) => r.description),
)};`,
pConfig,
),
Expand Down
22 changes: 17 additions & 5 deletions kayle/builder/htmlcs-rule-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,31 @@ export const htmlcsRuleMap = (rule: ParamList) => {
];

// TODO: PATCH RULES FROM INLINE TRANSLATIONS
const inlineTranslation =
rule[2] && rule[2].startsWith("HTMLCS.getTranslation");

const description =
(inlineTranslation && eval(rule[2])) ||
rule[2] ||
window.HTMLCS.getTranslation(`${rule[4]}_${rule[3]}`) ||
window.HTMLCS.getTranslation(`${rule[4]}${rule[3]}`) ||
"";

const baseRule = `${rule[4]}${directRuleAssignments.includes(rule[3]) ? "." : "_"}${rule[3]}`;
const baseRuleId =
section508 || !description ? rule[3] || baseRule : baseRule;

const inlineRule = inlineTranslation
? rule[2].replace("HTMLCS.getTranslation(", "").replace(")", "")
: "";

const ruleId = inlineTranslation
? inlineRule.substring(1, inlineRule.length - 1)
: baseRuleId;

return {
ruleId:
section508 || !description
? rule[3]
: `${rule[4]}${directRuleAssignments.includes(rule[3]) ? "." : "_"}${rule[3]}`,
description: description,
ruleId,
description,
helpUrl: section508
? []
: helpLinks.map((r) => concatWcagLink(r.split(".")[0])),
Expand Down
Loading

0 comments on commit 4f1e2ca

Please sign in to comment.