archivo del paquete→ .shtukbase/packages/std-conventional-commits/hooks/commit-msg.ts
hooks/commit-msg.ts
25 líneas, 1.1 KB.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // The commit-msg git hook: checks the message being committed against CC-R01..CC-R03. A norm in `enforce` mode
- // stops the commit; the others only print. Installed only by `shtuk run std-conventional-commits install-hook`.
- import { readFileSync } from 'node:fs';
- import { clean, config, ignored, lint, PKG } from '../checks/cclib.ts';
- import { norm } from '../checks/lib/std.ts';
- const file = process.argv[2];
- if (!file) {
- console.error('commit-msg: no message file');
- process.exit(0);
- }
- const message = clean(readFileSync(file, 'utf8'));
- const cfg = config();
- let stop = false;
- if (!ignored(message, cfg)) {
- for (const f of lint(message, cfg)) {
- const n = norm(PKG, f.rule, f.rule === 'CC-R03' ? 'observe' : 'enforce');
- if (!n.active) continue;
- const hard = n.mode === 'enforce';
- stop ||= hard;
- console.error(`${hard ? 'commit-msg' : 'commit-msg (warning)'}: ${f.rule}: ${f.text}`);
- }
- }
- if (stop) console.error('The message does not follow Conventional Commits 1.0.0: "type(scope)!: description". Fix it and commit again.');
- process.exit(stop ? 1 : 0);