Skip to content

Commit e74ed0e

Browse files
committed
refactor: reduce indentation, update oxlint rule
1 parent 5183caf commit e74ed0e

File tree

2 files changed

+76
-61
lines changed

2 files changed

+76
-61
lines changed

frontend/src/ts/test/test-ui.ts

Lines changed: 75 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,72 @@ export function setLigatures(isEnabled: boolean): void {
12591259
}
12601260
}
12611261

1262+
function buildWordLettersHTML(
1263+
charCount: number,
1264+
input: string,
1265+
corrected: string,
1266+
inputCharacters: string[],
1267+
wordCharacters: string[],
1268+
correctedCharacters: string[],
1269+
containsKorean: boolean
1270+
): string {
1271+
let out = "";
1272+
for (let c = 0; c < charCount; c++) {
1273+
let correctedChar;
1274+
try {
1275+
correctedChar = !containsKorean
1276+
? correctedCharacters[c]
1277+
: Hangul.assemble(corrected.split(""))[c];
1278+
} catch (e) {
1279+
correctedChar = undefined;
1280+
}
1281+
let extraCorrected = "";
1282+
const historyWord: string = !containsKorean
1283+
? corrected
1284+
: Hangul.assemble(corrected.split(""));
1285+
if (
1286+
c + 1 === charCount &&
1287+
historyWord !== undefined &&
1288+
historyWord.length > input.length
1289+
) {
1290+
extraCorrected = "extraCorrected";
1291+
}
1292+
if (Config.mode === "zen" || wordCharacters[c] !== undefined) {
1293+
if (Config.mode === "zen" || inputCharacters[c] === wordCharacters[c]) {
1294+
if (
1295+
correctedChar === inputCharacters[c] ||
1296+
correctedChar === undefined
1297+
) {
1298+
out += `<letter class="correct ${extraCorrected}">${inputCharacters[c]}</letter>`;
1299+
} else {
1300+
out +=
1301+
`<letter class="corrected ${extraCorrected}">` +
1302+
inputCharacters[c] +
1303+
"</letter>";
1304+
}
1305+
} else {
1306+
if (inputCharacters[c] === TestInput.input.current) {
1307+
out +=
1308+
`<letter class='correct ${extraCorrected}'>` +
1309+
wordCharacters[c] +
1310+
"</letter>";
1311+
} else if (inputCharacters[c] === undefined) {
1312+
out += "<letter>" + wordCharacters[c] + "</letter>";
1313+
} else {
1314+
out +=
1315+
`<letter class="incorrect ${extraCorrected}">` +
1316+
wordCharacters[c] +
1317+
"</letter>";
1318+
}
1319+
}
1320+
} else {
1321+
out +=
1322+
'<letter class="incorrect extra">' + inputCharacters[c] + "</letter>";
1323+
}
1324+
}
1325+
return out;
1326+
}
1327+
12621328
async function loadWordsHistory(): Promise<boolean> {
12631329
$("#resultWordsHistory .words").empty();
12641330
let wordsHTML = "";
@@ -1312,64 +1378,15 @@ async function loadWordsHistory(): Promise<boolean> {
13121378

13131379
if (corrected === undefined) throw new Error("empty corrected word");
13141380

1315-
for (let c = 0; c < loop; c++) {
1316-
let correctedChar;
1317-
try {
1318-
correctedChar = !containsKorean
1319-
? correctedCharacters[c]
1320-
: Hangul.assemble(corrected.split(""))[c];
1321-
} catch (e) {
1322-
correctedChar = undefined;
1323-
}
1324-
let extraCorrected = "";
1325-
const historyWord: string = !containsKorean
1326-
? corrected
1327-
: Hangul.assemble(corrected.split(""));
1328-
if (
1329-
c + 1 === loop &&
1330-
historyWord !== undefined &&
1331-
historyWord.length > input.length
1332-
) {
1333-
extraCorrected = "extraCorrected";
1334-
}
1335-
if (Config.mode === "zen" || wordCharacters[c] !== undefined) {
1336-
if (
1337-
Config.mode === "zen" ||
1338-
inputCharacters[c] === wordCharacters[c]
1339-
) {
1340-
if (
1341-
correctedChar === inputCharacters[c] ||
1342-
correctedChar === undefined
1343-
) {
1344-
wordEl += `<letter class="correct ${extraCorrected}">${inputCharacters[c]}</letter>`;
1345-
} else {
1346-
wordEl +=
1347-
`<letter class="corrected ${extraCorrected}">` +
1348-
inputCharacters[c] +
1349-
"</letter>";
1350-
}
1351-
} else {
1352-
if (inputCharacters[c] === TestInput.input.current) {
1353-
wordEl +=
1354-
`<letter class='correct ${extraCorrected}'>` +
1355-
wordCharacters[c] +
1356-
"</letter>";
1357-
} else if (inputCharacters[c] === undefined) {
1358-
wordEl += "<letter>" + wordCharacters[c] + "</letter>";
1359-
} else {
1360-
wordEl +=
1361-
`<letter class="incorrect ${extraCorrected}">` +
1362-
wordCharacters[c] +
1363-
"</letter>";
1364-
}
1365-
}
1366-
} else {
1367-
wordEl +=
1368-
'<letter class="incorrect extra">' +
1369-
inputCharacters[c] +
1370-
"</letter>";
1371-
}
1372-
}
1381+
wordEl += buildWordLettersHTML(
1382+
loop,
1383+
input,
1384+
corrected,
1385+
inputCharacters,
1386+
wordCharacters,
1387+
correctedCharacters,
1388+
containsKorean
1389+
);
13731390
wordEl += "</div>";
13741391
} catch (e) {
13751392
try {

packages/oxlint-config/index.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,10 @@
7979
"eqeqeq": "error",
8080
"ban-ts-comment": "error",
8181
"no-unassigned-vars": "error",
82-
83-
"todo-lowerthis": "off",
8482
"max-depth": [
8583
"error",
8684
{
87-
"max": 6
85+
"max": 5
8886
}
8987
],
9088

0 commit comments

Comments
 (0)