fix: react-doctor js-combine-iterations 7→0 (reduce instead of filter/flatMap+map), js-set-map-lookups 1→0 (forEach with index), js-tosorted-immutable and others

This commit is contained in:
Nora
2026-06-26 06:12:04 -06:00
parent d6d6a366e3
commit adce211480
8 changed files with 45 additions and 38 deletions
+4 -3
View File
@@ -270,9 +270,10 @@ export default async function StopsV2Page({
actions={<StopsDatePicker value={headerDate} />}
/>
<PullToRefresh>
{BUCKET_ORDER.flatMap((bucket) =>
grouped[bucket].length > 0 ? [bucket] : []
).map((bucket) => (
{BUCKET_ORDER.reduce<typeof BUCKET_ORDER>((acc, bucket) => {
if (grouped[bucket].length > 0) acc.push(bucket);
return acc;
}, []).map((bucket) => (
<section key={bucket}>
<h2
className="sticky top-0 px-4 py-2 text-label font-semibold"
+4 -3
View File
@@ -593,9 +593,10 @@ function CustomersTab({ customers, products, brandId, onMsg, registrations = [],
</tr>
</thead>
<tbody className="divide-y divide-[var(--admin-border-light)]">
{registrations.flatMap(r =>
r.account_status === "pending_approval" ? [r] : []
).map(r => (
{registrations.reduce<typeof registrations>((acc, r) => {
if (r.account_status === "pending_approval") acc.push(r);
return acc;
}, []).map(r => (
<tr key={r.id} className="hover:bg-[var(--admin-bg-subtle)]">
<td className="px-5 py-3 font-medium text-[var(--admin-text-primary)]">{r.company_name ?? "—"}</td>
<td className="px-5 py-3 text-[var(--admin-text-secondary)]">{r.contact_name ?? "—"}<br/><span className="text-xs text-[var(--admin-text-muted)]">{r.email}</span></td>
+14 -14
View File
@@ -72,10 +72,9 @@ export async function POST(req: NextRequest) {
const emailSubject = subject?.trim() || `${brandName} Wholesale Price Sheet — ${generatedDate}`;
const hasCustomNote = Boolean(customNote?.trim());
// Build product rows HTML
const productRows = products.flatMap(p =>
p.availability === "available" ? [p] : []
).map(p => {
// Build product rows HTML (single pass)
const productRowsReducer = products.reduce<{ rows: string[]; text: string[] }>((acc, p) => {
if (p.availability !== "available") return acc;
const tiersHtml = p.price_tiers
.map(t => {
const max = t.max_qty === 0 ? "+" : `-${t.max_qty}`;
@@ -83,15 +82,21 @@ export async function POST(req: NextRequest) {
})
.join("&nbsp;|&nbsp;");
return `
acc.rows.push(`
<tr style="border-bottom: 1px solid #e5e7eb;">
<td style="padding: 10px 12px; font-weight: 500; color: #1e293b;">${p.name}</td>
<td style="padding: 10px 12px; color: #64748b; font-size: 13px;">${p.description ?? "—"}</td>
<td style="padding: 10px 12px; color: #64748b; font-size: 13px; text-align: center;">${p.unit_type}</td>
<td style="padding: 10px 12px; color: #1e293b; font-size: 13px; text-align: right; font-family: monospace;">${tiersHtml}</td>
</tr>`;
})
.join("");
</tr>`);
const tiersText = p.price_tiers
.map(t => `${t.min_qty}${t.max_qty === 0 ? "+" : `-${t.max_qty}`}: $${Number(t.price).toFixed(2)}`)
.join(", ");
acc.text.push(`${p.name} (${p.unit_type})\n ${tiersText}`);
return acc;
}, { rows: [], text: [] });
const productRows = productRowsReducer.rows.join("");
const html = `
<!DOCTYPE html>
@@ -143,12 +148,7 @@ ${hasCustomNote ? ` <p style="margin: 0 0 12px; color: #1e293b; font-size:
</body>
</html>`;
const text = `${brandName} Wholesale Price Sheet — ${generatedDate}\n${"=".repeat(50)}\n${hasCustomNote ? `\n${customNote!.trim()}\n\n` : ""}${products.flatMap(p =>
p.availability === "available" ? [p] : []
).map(p => {
const tiers = p.price_tiers.map(t => `${t.min_qty}${t.max_qty === 0 ? "+" : `-${t.max_qty}`}: $${Number(t.price).toFixed(2)}`).join(", ");
return `${p.name} (${p.unit_type})\n ${tiers}`;
}).join("\n\n")}\n\nGenerated ${generatedDate}. Prices subject to change.`;
const text = `${brandName} Wholesale Price Sheet — ${generatedDate}\n${"=".repeat(50)}\n${hasCustomNote ? `\n${customNote!.trim()}\n\n` : ""}${productRowsReducer.text.join("\n\n")}\n\nGenerated ${generatedDate}. Prices subject to change.`;
let enqueued = 0;
let failed = 0;
+4 -3
View File
@@ -232,9 +232,10 @@ export default function RoadmapPage() {
className="w-full px-4 py-3 rounded-xl border border-[#e5e5e5] bg-white text-[#1a1a1a] focus:outline-none focus:ring-2 focus:ring-[#1a4d2e]/50 focus:border-[#1a4d2e] transition-all"
>
<option value="">Select a category</option>
{CATEGORIES.flatMap(c =>
c === "All" ? [] : [c]
).map((category) => (
{CATEGORIES.reduce<typeof CATEGORIES>((acc, c) => {
if (c !== "All") acc.push(c);
return acc;
}, []).map((category) => (
<option key={category} value={category.toLowerCase()}>{category}</option>
))}
</select>