Fix 3-col calculator labelling and add lint
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
"start": "node build",
|
||||
"prepare": "svelte-kit sync || echo ''",
|
||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"lint:3col": "node scripts/lint-3col.mjs"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-node": "^5.5.4",
|
||||
|
||||
36
hdyc-svelte/scripts/lint-3col.mjs
Executable file
36
hdyc-svelte/scripts/lint-3col.mjs
Executable file
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env node
|
||||
import { readFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const file = path.resolve('src/lib/data/calculators.ts');
|
||||
const text = readFileSync(file, 'utf8');
|
||||
const start = text.indexOf('[');
|
||||
const end = text.indexOf('];', start);
|
||||
if (start === -1 || end === -1) {
|
||||
console.error('Unable to locate calculators array in calculators.ts');
|
||||
process.exit(1);
|
||||
}
|
||||
let arr = text.slice(start, end + 1).trim();
|
||||
arr = arr.replace(/,\s*\]$/, ']');
|
||||
let calculators;
|
||||
try {
|
||||
calculators = JSON.parse(arr);
|
||||
} catch (err) {
|
||||
console.error('Failed to parse calculators.ts as JSON:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const offenders = calculators.filter(c =>
|
||||
['3col', '3col-mul'].includes(c.type) &&
|
||||
c.name.toLowerCase().includes(' to ') &&
|
||||
(!c.labels?.in3 || c.labels.in3.toLowerCase() === 'result')
|
||||
);
|
||||
|
||||
if (offenders.length) {
|
||||
console.error(`3-col calculators with vague or missing output labels: ${offenders.length}`);
|
||||
offenders.slice(0, 20).forEach(c => console.error(`- ${c.slug}`));
|
||||
if (offenders.length > 20) console.error(`…and ${offenders.length - 20} more`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('3-col label lint passed.');
|
||||
@@ -11,7 +11,9 @@
|
||||
$: calc = data.calculator;
|
||||
$: related = data.related;
|
||||
$: pageTitle = `${calc.name} — ${SITE_NAME}`;
|
||||
$: pageDescription = `Convert ${calc.labels.in1} to ${calc.labels.in2} instantly with our free online calculator. Accurate bidirectional conversion with the exact formula shown.`;
|
||||
$: pageDescription = ['3col', '3col-mul'].includes(calc.type)
|
||||
? `Compute ${calc.labels.in3 ?? 'the derived value'} using ${calc.labels.in1} and ${calc.labels.in2}. Enter any two fields to solve the third.`
|
||||
: `Convert ${calc.labels.in1} to ${calc.labels.in2} instantly with our free online calculator. Accurate two-way conversion with the exact formula shown.`;
|
||||
$: seo = buildSeoMeta({
|
||||
title: pageTitle,
|
||||
description: pageDescription,
|
||||
|
||||
Reference in New Issue
Block a user