Skip to content

Commit 4444885

Browse files
claude[bot]claude
andauthored
refactor(devx): check-registry-log-declared consumes js-comment-mask's maskComments instead of a private wrapper (#15595)
* refactor(devx): check-registry-log-declared consumes js-comment-mask's maskComments instead of a private wrapper (#15561) The local `maskComments` was `blank(source, scanSource(source).comment)` — character-for-character the module's own export — so it was a private wrapper, not a second scanner. Import the export and delete the wrapper; every call site is unchanged. `maskCode` stays local (the module publishes no comments+literals projection yet) and its docblock now says so: it composes `scanSource`'s `comment` and `literal` flags through `blank` and carries no scanning logic of its own. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk * test(devx): pin both directions of the code mask in check-registry-log-declared's self-test (#15561) The existing prose row pins the COMMENT direction for S2 only. This row adds the code mask's other direction: a signal spelled inside a string literal or a comment must not select, and the same spelling in real code still must. Two packages in one case, so a mask that stopped blanking either span shows up as a second selected package rather than as a silent widening of the population. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012zGPuVVX3deAx9LdjK8jCk --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4e4d79d commit 4444885

1 file changed

Lines changed: 40 additions & 10 deletions

File tree

scripts/check-registry-log-declared.mjs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync,
127127
import { dirname, join, resolve, sep } from 'node:path';
128128
import { tmpdir } from 'node:os';
129129
import { fileURLToPath } from 'node:url';
130-
import { blank, scanSource } from './js-comment-mask.mjs';
130+
import { blank, maskComments, scanSource } from './js-comment-mask.mjs';
131131
import { isEntrypoint } from './invoked-as.mjs';
132132
import { workspacePackageDirs } from './check-console-intercept-disarm.mjs';
133133

@@ -178,19 +178,21 @@ const REMEDY = ` // #13517: quiet the registry's per-item registration chatte
178178
// default. Enforced by scripts/check-registry-log-declared.mjs.
179179
env: { OS_REGISTRY_LOG: 'warn' },`;
180180

181-
/** Comments blanked, offsets kept. Import specifiers survive — S2/S3 need them. */
182-
function maskComments(source) {
183-
return blank(source, scanSource(source).comment);
184-
}
185-
186181
/**
187182
* Comments AND string/template/regex content blanked, offsets kept. Used where
188183
* the signal is a bare CODE position (`new SchemaRegistry(`, a property key), so
189184
* a spelling inside prose or a template literal can never satisfy it.
190185
*
191-
* Both masks preserve offsets, so a range brace-matched on the code mask indexes
192-
* the comment mask identically — which is how the level VALUE (a string, blanked
193-
* by this mask) is read out of a block located with it.
186+
* It COMPOSES the shared scanner — `scanSource`'s `comment` and `literal` flags
187+
* OR-ed through `blank` — and carries no scanning logic of its own; it stays
188+
* local only because `js-comment-mask.mjs` publishes no comments+literals
189+
* projection yet, and hoisting one waits on a follow-up card.
190+
*
191+
* The imported `maskComments` (comments blanked, string/template/regex content
192+
* INTACT — S2/S3 read import specifiers out of it) and this mask both preserve
193+
* offsets, so a range brace-matched on the code mask indexes the comment mask
194+
* identically — which is how the level VALUE (a string, blanked by this mask)
195+
* is read out of a block located with it.
194196
*/
195197
function maskCode(source) {
196198
const { comment, literal } = scanSource(source);
@@ -563,6 +565,7 @@ const SELF_TEST_BATTERIES = Object.freeze({
563565
'a package that never runs vitest is ignored entirely': 1,
564566
'prose naming the key does not satisfy the check': 1,
565567
'prose naming bootStack does not SELECT the package (the packages/cli shape)': 1,
568+
'a code signal spelled only in a string or a comment does not SELECT': 1,
566569
'a level the engine does not recognise is RED': 1,
567570
'the key outside any env block does not count': 1,
568571
'S2: importing bootStack from @objectstack/verify selects': 1,
@@ -578,7 +581,7 @@ const SELF_TEST_BATTERIES = Object.freeze({
578581
// zeroing it, so the roster's own size is pinned too. This pin is also half of
579582
// the duplicate-label refusal: two rows sharing a label collapse to ONE key in
580583
// the literal above, so the roster falls below this number.
581-
const SELF_TEST_BATTERY_FLOOR = 15;
584+
const SELF_TEST_BATTERY_FLOOR = 16;
582585

583586
// The key an assertion is filed under when a row carries no label. It is not a
584587
// declared battery, so it reds by the same set difference rather than silently
@@ -657,6 +660,33 @@ function selfTest() {
657660
expectFindings: 0,
658661
expectSelected: 0,
659662
},
663+
{
664+
// The other direction of the row above, for the CODE mask: a signal
665+
// spelled inside a string literal or a comment must not select, and the
666+
// same spelling in real code still must. Package `a` carries both
667+
// non-code spellings, package `b` the code one, so a mask that stopped
668+
// blanking either span shows up as a SECOND selected package rather than
669+
// as a silent widening of the population.
670+
name: 'a code signal spelled only in a string or a comment does not SELECT',
671+
packages: {
672+
a: {
673+
'package.json': TEST_MANIFEST,
674+
'test/x.test.ts':
675+
`// new SchemaRegistry() is what this file describes; bootStack too.\n`
676+
+ `/* const described = new SchemaRegistry(); */\n`
677+
+ `export const doc = 'new SchemaRegistry() quoted, and bootStack, never called';\n`,
678+
'vitest.config.ts': `export default { test: { globals: true } };\n`,
679+
},
680+
b: {
681+
'package.json': TEST_MANIFEST,
682+
'test/x.test.ts': BOOTS,
683+
'vitest.config.ts': `export default { test: { globals: true } };\n`,
684+
},
685+
},
686+
expectFindings: 1,
687+
expectSelected: 1,
688+
expectText: 'S1 constructs a SchemaRegistry',
689+
},
660690
{
661691
name: 'a level the engine does not recognise is RED',
662692
packages: {

0 commit comments

Comments
 (0)