diff --git a/electron/properties/selectorUsage.ts b/electron/properties/selectorUsage.ts index 07719ac28..6f9ad4c56 100644 --- a/electron/properties/selectorUsage.ts +++ b/electron/properties/selectorUsage.ts @@ -189,15 +189,14 @@ function hitsFor(region: StyleRegion, sheet: AstroSheet | undefined, scans: Proj return hits; } -// A locked stylesheet (or one in a locked folder) is a library meant to sit -// unused until needed: a selector the proof finds unused there is `kept`, so -// every cleanup — the panel's, the delete offer and `style:removeSelectors` -// itself, which re-runs this check — leaves it alone. Other verdicts stand: -// "used" and "can't tell" are never removed anyway. +// An explicit stylesheet lock is the user's decision to retain its selectors. +// Surface that decision as `kept` even when outside data prevents an unused +// proof: uncertainty must not hide the lock in the panel. Used and untracked +// selectors retain their verdicts because they do not need retention protection. function lockedVerdict(verdict: SelectorVerdict, sheet: { readonly locked: boolean }): SelectorVerdict { if (sheet.locked) { - if (verdict.kind === 'unused') { - assert(verdict.names.length > 0, 'lockedVerdict: an unused selector names what is missing'); + if (verdict.kind === 'unused' || verdict.kind === 'unknown') { + assert(verdict.names.length > 0, 'lockedVerdict: a protected selector names what is missing'); return { kind: 'kept', names: verdict.names }; } return verdict; diff --git a/test/electron/properties/selectorUsage.test.ts b/test/electron/properties/selectorUsage.test.ts index 8a02ec275..dae2961a8 100644 --- a/test/electron/properties/selectorUsage.test.ts +++ b/test/electron/properties/selectorUsage.test.ts @@ -203,6 +203,36 @@ test('a locked stylesheet or folder keeps its unused selectors out of every clea assert.equal(fs.readFileSync(path.join(root, 'src/styles/patterns.css'), 'utf8'), ''); }); +test('explicit stylesheet and folder locks take priority over outside-HTML uncertainty', async () => { + const patterns = '.pattern-unused { color: red }\n.pattern-used { color: blue }\nh1 { color: green }\n'; + const root = project({ + 'src/styles/patterns.css': patterns, + 'src/lumos/utilities.css': '.utility-unused { color: red }\n', + 'src/styles/unlocked.css': '.unlocked-unused { color: red }\n', + 'src/pages/index.astro': '---\nimport { content } from \'../lib/content\';\n---\n