Skip to content

Commit fd1f1e3

Browse files
committed
fix(scripts): harden layer-order parsing and clarify doc-refs skip message
Address two Greptile P2 maintainability findings on the new gates: - check-layer-order.js: strip CSS comments before locating the @layer declaration so an `@layer` mention inside a file-header comment can't be mistaken for the real declaration (which would land the terminator search on a comment semicolon and silently extract the wrong layers). Added a regression test. - check-doc-refs.js: the success line unconditionally read "token-count claims match" even when token-index.json was absent and the count check was skipped (a local pre-build run). Now it says the check was skipped in that case, so the OK message never implies validation that didn't run. Full suite: 129 unit tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dr51QC66ZtLKW6S2CWbiWi
1 parent 9ab8085 commit fd1f1e3

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

scripts/check-doc-refs.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,13 @@ if (countFindings.length > 0) {
164164
if (failed) process.exit(1);
165165

166166
const tokenAllow = Object.values(allow).reduce((n, s) => n + s.size, 0);
167+
// Only claim the count check ran when token-index.json was actually present;
168+
// otherwise say it was skipped so a local pre-build run doesn't imply the
169+
// "N design tokens" prose was validated when it wasn't.
170+
const countNote = typeof tokenTotal === 'number'
171+
? 'token-count claims match'
172+
: 'token-count check skipped (docs/token-index.json absent — run `npm run build`)';
167173
console.log(
168174
`check:doc-refs OK — ${docs.length} hand-written docs scanned, ` +
169-
`all --sf-*/.sf- references live or allowlisted (${tokenAllow} allowlisted); ` +
170-
'token-count claims match.',
175+
`all --sf-*/.sf- references live or allowlisted (${tokenAllow} allowlisted); ${countNote}.`,
171176
);

scripts/check-layer-order.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121
import fs from 'node:fs';
2222
import path from 'node:path';
23+
import { stripComments } from './lib/parse.js';
2324

2425
const slashedRoot = process.env.SLASHED_ROOT?.trim();
2526
const ROOT = slashedRoot
@@ -41,7 +42,10 @@ const read = (rel) => {
4142
const layersIn = (text) => [...text.matchAll(/slashed\.([a-z]+)/g)].map((m) => m[1]);
4243

4344
// ── Source of truth: the @layer declaration in core/layers.css ───────────────
44-
const layersCss = read('core/layers.css');
45+
// Strip CSS comments first so an `@layer` that appears inside a file-header
46+
// comment (e.g. "/* keep @layer in sync with architecture.md */") can't be
47+
// mistaken for the real declaration.
48+
const layersCss = stripComments(read('core/layers.css'));
4549
const declStart = layersCss.indexOf('@layer');
4650
if (declStart === -1) fail('no @layer declaration found in core/layers.css.');
4751
const declEnd = layersCss.indexOf(';', declStart);

tests/check-layer-order.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ describe('check-layer-order failure cases', () => {
6767
assert.equal(r.status, 1, 'expected exit 1 for a wrong specificity ladder');
6868
assert.match(r.stderr, /Specificity ladder .* not the reverse/);
6969
});
70+
71+
test('ignores an @layer mention inside a comment before the real declaration', () => {
72+
// A file-header comment naming @layer must not be parsed as the declaration.
73+
const dir = buildFixture();
74+
fs.writeFileSync(
75+
path.join(dir, 'core', 'layers.css'),
76+
'/* keep @layer in sync with architecture.md; order matters */\n' +
77+
`@layer\n${LAYERS.map((l) => ` slashed.${l}`).join(',\n')};\n`,
78+
);
79+
const r = runGate(dir);
80+
assert.equal(r.status, 0, `comment @layer must be ignored:\n${r.stderr}`);
81+
});
7082
});
7183

7284
after(() => {

0 commit comments

Comments
 (0)