Commit 417cea83 by PLN (Algolia)

refactor: lint core moves to lib, package entry exports catalog + lint

parent c9f7076d
......@@ -17,7 +17,7 @@
import fs from 'fs';
import path from 'path';
import { CATALOG, CATALOG_VERSION, BUDGETS } from '../lib/catalog.mjs';
import { CATALOG_VERSION, lint, bodyOf } from '../lib/index.mjs';
const TEXT_EXT = /\.(md|txt|mdx)$/i;
......@@ -34,37 +34,6 @@ function collect(target, files) {
console.error(`buvard: no file or directory for "${target}"`);
}
/** Body = everything after the frontmatter fence (frontmatter is data, not prose). */
export function bodyOf(text) {
const parts = text.split('---');
return parts.length >= 3 && text.startsWith('---') ? parts.slice(2).join('---').trim() : text.trim();
}
export function lint(text) {
const words = text.split(/\s+/).filter(Boolean).length;
const hits = [];
let score = 100;
for (const [id, w, , , re] of CATALOG) {
for (const m of text.matchAll(re)) {
hits.push({ id, w, at: excerpt(text, m.index) });
score -= w;
}
}
for (const { re, perWords, floor, id, weight } of BUDGETS) {
const budget = Math.max(floor, Math.floor(words / perWords));
const n = (text.match(re) || []).length;
for (let i = budget; i < n; i++) {
hits.push({ id: `budget ${id} (>${budget}/${words} mots)`, w: weight, at: `occurrence ${i + 1}` });
score -= weight;
}
}
return { words, hits, score: Math.max(0, score) };
}
function excerpt(text, index) {
return '…' + text.slice(Math.max(0, index - 38), index + 52).replace(/\s+/g, ' ') + '…';
}
function main(argv) {
const json = argv.includes('--json');
const targets = argv.filter((a) => !a.startsWith('--'));
......
/** buvard package entry — the catalog, the budgets, and the lint core. */
export { CATALOG, CATALOG_VERSION, BUDGETS } from './catalog.mjs';
export { lint, bodyOf } from './lint.mjs';
/**
* buvard lint core — score a text against the catalog.
*
* Scoring starts at 100; each hit costs its weight (lexique 5, structure 8,
* servile 10); punctuation charges per occurrence past the budget: one tiret
* cadratin per 500 words, one exclamation per 1000. Every hit is a review
* candidate, not a verdict — the author's voice always wins.
*/
import { CATALOG, BUDGETS } from './catalog.mjs';
/** Body = everything after the frontmatter fence (frontmatter is data, not prose). */
export function bodyOf(text) {
const parts = text.split('---');
return parts.length >= 3 && text.startsWith('---') ? parts.slice(2).join('---').trim() : text.trim();
}
function excerpt(text, index) {
return '…' + text.slice(Math.max(0, index - 38), index + 52).replace(/\s+/g, ' ') + '…';
}
export function lint(text) {
const words = text.split(/\s+/).filter(Boolean).length;
const hits = [];
let score = 100;
for (const [id, w, , , re] of CATALOG) {
for (const m of text.matchAll(re)) {
hits.push({ id, w, at: excerpt(text, m.index) });
score -= w;
}
}
for (const { re, perWords, floor, id, weight } of BUDGETS) {
const budget = Math.max(floor, Math.floor(words / perWords));
const n = (text.match(re) || []).length;
for (let i = budget; i < n; i++) {
hits.push({ id: `budget ${id} (>${budget}/${words} mots)`, w: weight, at: `occurrence ${i + 1}` });
score -= weight;
}
}
return { words, hits, score: Math.max(0, score) };
}
......@@ -4,7 +4,7 @@
"description": "buvard — l'anti-slop qui tache. Blotting paper for AI-flavored prose: a weighted multi-score linter for French and English slop patterns.",
"type": "module",
"bin": { "buvard": "bin/buvard.js" },
"main": "lib/catalog.mjs",
"main": "lib/index.mjs",
"files": ["bin", "lib", "docs", "AGENTS.md", "SKILL.md", "README.md", "LICENSE"],
"scripts": { "test": "node --test test/" },
"keywords": ["slop", "linter", "prose", "french", "writing", "ai-writing", "style"],
......
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { lint, bodyOf } from '../bin/buvard.js';
import { lint, bodyOf } from '../lib/index.mjs';
test('clean prose scores 100', () => {
const r = lint("J'ai réparé le montage smb. Le mot de passe vivait dans le trousseau.");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment