mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-05 16:34:00 +01:00
* fix(review): bare --base reads origin/<base> in review and ship bins; diff-scope matches auth as a word (GST-1036, GST-1065) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * changelog: fragment for GST-1036 and GST-1065 Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(diff-scope): a token that starts or ends with auth is an auth path; author* is not (review fix, GST-1065) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * fix(diff-scope): authoriz/authenticat mid-word and a leading oauth are auth paths (granted fix round, GST-1065) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * docs(review-policy): REVIEW_BASE line and SCOPE_AUTH word matching (GST-1036, GST-1065) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * diff-scope: fail-safe auth match; resolveBase never re-qualifies a remote-qualified base (GST-1065, GST-1036) Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> * Revert the resolveBase remote-prefix guard (regressed alice/base stacked bases); fringe case stays an open note Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> --------- Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
74 lines
4.8 KiB
TypeScript
Executable File
74 lines
4.8 KiB
TypeScript
Executable File
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
/**
|
|
* gstack-prose-lint — the AI tells a regular expression can decide, over the
|
|
* prose /ship writes (docs/troubleshooting.md#prose-lint-found).
|
|
*
|
|
* gstack-prose-lint <file>... [--unreleased | --base <ref> | --sections <a,b>] [--gate] [--json]
|
|
*
|
|
* Scans each file (fenced code, inline code, URLs, comments and quoted words excluded) and
|
|
* prints one `PROSE:` line per finding, then `PROSE_LINT: ok | found=<n> | none`.
|
|
* --unreleased reads only each file's `## [Unreleased]` CHANGELOG block,
|
|
* --base <ref> only the lines the working tree adds since the merge base with
|
|
* <ref>, and --sections <a,b> only the text under those `## ` headings (nothing
|
|
* to scan is `none`). Exit 0 unless --gate is set and something was found
|
|
* (exit 1); unreadable input is exit 2. Report-only everywhere else: a
|
|
* template, a doc or a README gets the report and keeps its em dashes.
|
|
* Logic: lib/prose-lint.ts. Called from /ship Steps 13 and 19 and the
|
|
* quality-gate workflow.
|
|
*/
|
|
import * as fs from 'node:fs';
|
|
import { EXIT, exitTableHelp } from '../lib/headless-artifacts';
|
|
import { baseArg } from '../lib/gate-diff/git';
|
|
import { lintFiles, renderProseLint } from '../lib/prose-lint';
|
|
import { resultLine } from '../lib/result-codes';
|
|
|
|
const HELP = `gstack-prose-lint — AI tells a regex can decide, over CHANGELOG entries and PR bodies (docs/troubleshooting.md#prose-lint-found)
|
|
|
|
<file>... files to scan; fenced code, inline code, URLs and HTML comments are skipped
|
|
--unreleased scan only each file's ## [Unreleased] CHANGELOG block (none present: PROSE_LINT: none)
|
|
--base <ref> scan only the lines the working tree adds to each file since the merge base with <ref>
|
|
--sections <a,b> scan only the text under these ## headings (the sections an author writes in a PR body)
|
|
--gate exit 1 when anything was found (default: report and exit 0)
|
|
--json findings as JSON instead of PROSE: lines
|
|
|
|
Rules: vocabulary, not-just-but, metaphor-noun, mid-sentence-colon, inline-header-list, arrow, dropped-article,
|
|
and unclosed-block (a fence or HTML comment left open hid the text after it). Quoted words are never read.
|
|
--sections with --gate exits 2 when a file has none of the headings, so a renamed heading cannot pass unread.
|
|
|
|
${exitTableHelp()}`;
|
|
|
|
function main(argv: string[]): number {
|
|
if (argv.length === 0 || argv.includes('--help') || argv.includes('-h')) { process.stdout.write(HELP + '\n'); return argv.length ? EXIT.ok : EXIT.usage; }
|
|
const flags = new Set<string>();
|
|
const files: string[] = [];
|
|
let base: string | undefined;
|
|
let sections: string[] | undefined;
|
|
for (let i = 0; i < argv.length; i++) {
|
|
const a = argv[i]!;
|
|
if (a === '--base') { base = argv[++i]; if (!base || base.startsWith('--')) { process.stderr.write('gstack-prose-lint: --base needs a ref\n'); return EXIT.usage; } }
|
|
else if (a === '--sections') { const v = argv[++i]; if (!v || v.startsWith('--')) { process.stderr.write('gstack-prose-lint: --sections needs a comma-separated list of headings\n'); return EXIT.usage; } sections = v.split(','); }
|
|
else if (['--unreleased', '--gate', '--json'].includes(a)) flags.add(a);
|
|
else if (a.startsWith('--')) { process.stderr.write(`gstack-prose-lint: unknown flag ${a}\n${HELP}\n`); return EXIT.usage; }
|
|
else files.push(a);
|
|
}
|
|
if (files.length === 0) { process.stderr.write('gstack-prose-lint: name at least one file\n'); return EXIT.usage; }
|
|
if ([base, sections, flags.has('--unreleased') || undefined].filter(Boolean).length > 1) { process.stderr.write('gstack-prose-lint: --unreleased, --base and --sections are different selections; pass one\n'); return EXIT.usage; }
|
|
for (const f of files) if (!fs.existsSync(f) || fs.statSync(f).isDirectory()) { process.stderr.write(`gstack-prose-lint: cannot read ${f}\n`); return EXIT.usage; }
|
|
let result;
|
|
try { result = lintFiles(files, { unreleased: flags.has('--unreleased'), base: base && baseArg('gstack-prose-lint', base, process.cwd()), sections }); }
|
|
catch (e: any) { process.stderr.write(`gstack-prose-lint: ${e.message}\n`); return EXIT.usage; }
|
|
if (sections && flags.has('--gate') && result.empty.length) {
|
|
process.stderr.write(`gstack-prose-lint: no "## <section>" heading from --sections in ${result.empty.join(', ')}; nothing would be gated\n`);
|
|
return EXIT.usage;
|
|
}
|
|
if (flags.has('--json')) process.stdout.write(JSON.stringify({ findings: result.findings, scanned: result.scanned, empty: result.empty }, null, 2) + '\n');
|
|
else process.stdout.write(renderProseLint(result));
|
|
if (result.findings.length && flags.has('--gate')) {
|
|
process.stderr.write(resultLine('gstack-prose-lint', 'PROSE_LINT_FOUND', `${result.findings.length} finding${result.findings.length === 1 ? '' : 's'}`) + '\n');
|
|
return EXIT.fail;
|
|
}
|
|
return EXIT.ok;
|
|
}
|
|
|
|
process.exit(main(process.argv.slice(2)));
|