Skip to content

Commit 62a7511

Browse files
committed
biome fixes
1 parent 1d1cf96 commit 62a7511

File tree

11 files changed

+71
-58
lines changed

11 files changed

+71
-58
lines changed

src/bulk-labeling/plugin.js

+22-19
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,32 @@ LSI.on("entityCreate", (region) => {
77
if (window.BULK_REGIONS) return;
88

99
window.BULK_REGIONS = true;
10-
setTimeout(() => (window.BULK_REGIONS = false), 1000);
10+
setTimeout(() => {
11+
window.BULK_REGIONS = false;
12+
}, 1000);
1113

1214
setTimeout(() => {
1315
// Find all the text regions matching the selection
14-
region.object._value
15-
.matchAll(new RegExp(region.text, "gi"))
16-
.forEach((m) => {
17-
if (m.index === region.startOffset) return;
16+
const matches = Array.from(
17+
region.object._value.matchAll(new RegExp(region.text, "gi")),
18+
);
19+
for (const m of matches) {
20+
if (m.index === region.startOffset) continue;
1821

19-
// Include them in the results as new selections
20-
Htx.annotationStore.selected.createResult(
21-
{
22-
text: region.text,
23-
start: "/span[1]/text()[1]",
24-
startOffset: m.index,
25-
end: "/span[1]/text()[1]",
26-
endOffset: m.index + region.text.length,
27-
},
28-
{ labels: [...region.labeling.value.labels] },
29-
region.labeling.from_name,
30-
region.object,
31-
);
32-
});
22+
// Include them in the results as new selections
23+
Htx.annotationStore.selected.createResult(
24+
{
25+
text: region.text,
26+
start: "/span[1]/text()[1]",
27+
startOffset: m.index,
28+
end: "/span[1]/text()[1]",
29+
endOffset: m.index + region.text.length,
30+
},
31+
{ labels: [...region.labeling.value.labels] },
32+
region.labeling.from_name,
33+
region.object,
34+
);
35+
}
3336
Htx.annotationStore.selected.updateObjects();
3437
}, 100);
3538
});

src/count-words-in-textarea/plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LSI.on("beforeSaveAnnotation", (store, annotation) => {
1515

1616
if (word_count > 10) {
1717
Htx.showModal(
18-
"Word count is " + word_count + ". Please reduce to 10 or less.",
18+
`Word count is ${word_count}. Please reduce to 10 or less.`,
1919
);
2020
dismissed = true;
2121
return false; // Block submission

src/llm-backend/data.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"data": {
3+
"text": "LLM backend"
4+
}
5+
}

src/llm-backend/plugin.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async function sendPrompt() {
5353
}
5454
const results = [];
5555

56-
const llmResponse = llmResponse["LLM_response"];
56+
const llmResponse = response.LLM_response;
5757
if (llmResponse) {
5858
const llmResult = {
5959
from_name: "response",
@@ -65,7 +65,7 @@ async function sendPrompt() {
6565
}
6666
// console.log("Response:" + llmResponse["LLM_response"]);
6767

68-
const category = llmResponse["Category"]?.category;
68+
const category = response.Category?.category;
6969
if (category?.length) {
7070
const attackResult = {
7171
from_name: "category",
@@ -77,7 +77,7 @@ async function sendPrompt() {
7777
// console.log("Category:" + category);
7878
}
7979

80-
const reasonText = llmResponse["Type"]?.reason;
80+
const reasonText = response.Type?.reason;
8181
if (reasonText) {
8282
const reasonResult = {
8383
from_name: "reason",

src/markdown-to-html/plugin.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ window.LSI = LSI;
66

77
await LSI.import("https://unpkg.com/showdown/dist/showdown.min.js");
88

9-
let sumBlock = document.querySelector(".lsf-richtext");
9+
const sumBlock = document.querySelector(".lsf-richtext");
1010

1111
if (sumBlock) {
12-
var converter = new showdown.Converter();
13-
var html = converter.makeHtml(LSI.task.data.chat_transcript);
12+
const converter = new showdown.Converter();
13+
const html = converter.makeHtml(LSI.task.data.chat_transcript);
1414
sumBlock.innerHTML = html;
1515
}

src/ner-text-span-overlap-validation/plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LSI.on("beforeSaveAnnotation", (store, annotation) => {
1515
// console.log(textRegions); // Print the filtered result
1616
textRegions.sort((a, b) => a.startOffset - b.startOffset);
1717

18-
let overlaps = [];
18+
const overlaps = [];
1919

2020
// Check for overlaps
2121
for (let i = 0; i < textRegions.length - 1; i++) {

src/pausing-annotator/plugin.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const RULES = {
2727
const MESSAGES = {
2828
timesInARow: ({ field }) => `Too many similar values for ${field}`,
2929
tooSimilar: ({ field }) => `Too similar values for ${field}`,
30-
tooFast: () => `Too fast annotations`,
30+
tooFast: () => "Too fast annotations",
3131
};
3232

3333
/**
@@ -115,23 +115,25 @@ LSI.on("submitAnnotation", async (_store, annotation) => {
115115
const results = annotation.serializeAnnotation();
116116
// { sentiment: "positive", comment: "good" }
117117
const values = {};
118-
fields.forEach((field) => {
118+
for (const field of fields) {
119119
const value = results.find((r) => r.from_name === field)?.value;
120120
if (!value) return;
121121
if (value.choices) values[field] = value.choices.join("|");
122122
else if (value.text) values[field] = value.text;
123-
});
123+
}
124124
let stats = [];
125125
try {
126126
stats = JSON.parse(localStorage.getItem(key)) ?? [];
127-
} catch (e) {}
127+
} catch (e) {
128+
// Ignore parse errors
129+
}
128130
stats.push({ values, created_at: Date.now() / 1000 });
129131

130132
for (const rule of RULES.global) {
131133
const result = rule(stats);
132134
if (result) {
133135
localStorage.setItem(key, "[]");
134-
pause(result);
136+
await pause(result);
135137
return;
136138
}
137139
}
@@ -148,9 +150,8 @@ LSI.on("submitAnnotation", async (_store, annotation) => {
148150
await pause(result);
149151
} catch (error) {
150152
Htx.showModal(error.message, "error");
151-
} finally {
152-
return false;
153153
}
154+
return;
154155
}
155156
}
156157
}

src/plotly/plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ await LSI.import(
77
"sha384-xuh4dD2xC9BZ4qOrUrLt8psbgevXF2v+K+FrXxV4MlJHnWKgnaKoh74vd/6Ik8uF",
88
);
99

10-
let data = LSI.task.data;
10+
const data = LSI.task.data;
1111
if (!window.Plotly || !data) {
1212
Htx.showModal("Plotly data not found in task", "error");
1313
}

src/redact-pii/plugin.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function fetchUserInfo() {
3030
function displayEl(sel) {
3131
const els = document.querySelectorAll(sel);
3232
if (els) {
33-
els.forEach(function (el, idx) {
33+
els.forEach((el, idx) => {
3434
el.style.display = "block";
3535
});
3636
}
@@ -41,7 +41,8 @@ function displayEl(sel) {
4141
* the annotator identity
4242
*/
4343
async function hidePII() {
44-
let user, role;
44+
let user;
45+
let role;
4546
try {
4647
const userInfo = await fetchUserInfo();
4748
user = userInfo.username || "Unknown";

src/spellcheck/plugin.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const WORD_REGEX = /\w+/g;
1313

1414
LSI.on("beforeSaveAnnotation", async (store, annotation) => {
1515
// Find all textareas with misspellings
16-
let misspelledAreas = annotation.results.filter(
16+
const misspelledAreas = annotation.results.filter(
1717
(r) =>
1818
r.type === "textarea" &&
1919
r.value.text.some((t) => {
20-
let words = t.match(WORD_REGEX) || []; // Extract words
20+
const words = t.match(WORD_REGEX) || []; // Extract words
2121
return words.some((word) => !dictionary.check(word));
2222
}),
2323
);
@@ -26,7 +26,7 @@ LSI.on("beforeSaveAnnotation", async (store, annotation) => {
2626
if (misspelledAreas.length === 0) return true;
2727

2828
// Collect all misspelled words
29-
let misspelledWords = [
29+
const misspelledWords = [
3030
...new Set(
3131
misspelledAreas.flatMap((area) =>
3232
area.value.text.flatMap((t) =>

validate-structure.mjs

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
import { existsSync, readFileSync, readdirSync } from "fs";
4-
import { join } from "path";
3+
import { existsSync, readFileSync, readdirSync } from "node:fs";
4+
import { join } from "node:path";
55

66
const ROOT_DIR = process.cwd();
77
const MANIFEST_FILE = join(ROOT_DIR, "manifest.json");
@@ -34,37 +34,40 @@ const validateStructure = () => {
3434

3535
const errors = [];
3636

37-
folders.forEach((folder) => {
37+
for (const folder of folders) {
3838
const pluginFile = join(PLUGINS_DIR, folder, PLUGIN_FILENAME);
3939
const viewFile = join(PLUGINS_DIR, folder, VIEW_FILENAME);
4040
const dataFile = join(PLUGINS_DIR, folder, DATA_FILENAME);
4141

42-
if (!existsSync(pluginFile))
42+
if (!existsSync(pluginFile)) {
4343
errors.push(`Missing ${PLUGIN_FILENAME} in "${folder}"`);
44-
if (!existsSync(viewFile))
44+
}
45+
if (!existsSync(viewFile)) {
4546
errors.push(`Missing ${VIEW_FILENAME} in "${folder}"`);
46-
if (!existsSync(dataFile))
47+
}
48+
if (!existsSync(dataFile)) {
4749
errors.push(`Missing ${DATA_FILENAME} in "${folder}"`);
50+
}
4851

4952
const manifestEntry = manifest.find((entry) => entry.path === folder);
5053

5154
if (!manifestEntry) {
5255
errors.push(`Folder "${folder}" is missing in manifest.json`);
53-
} else {
54-
if (
55-
!manifestEntry.title ||
56-
!manifestEntry.description ||
57-
typeof manifestEntry.private !== "boolean"
58-
) {
59-
errors.push(
60-
`Invalid manifest entry for "${folder}". It must have a title, description, private flag, and path.`,
61-
);
62-
}
56+
} else if (
57+
!manifestEntry.title ||
58+
!manifestEntry.description ||
59+
typeof manifestEntry.private !== "boolean"
60+
) {
61+
errors.push(
62+
`Invalid manifest entry for "${folder}". It must have a title, description, private flag, and path.`,
63+
);
6364
}
64-
});
65+
}
6566

6667
if (errors.length > 0) {
67-
errors.forEach((error) => console.error(error));
68+
for (const error of errors) {
69+
console.error(error);
70+
}
6871
process.exit(1);
6972
}
7073

0 commit comments

Comments
 (0)