Skip to content

Fix empty-note threshold, drop dead orphan-link code, dedupe byte formatting#91

Merged
rogerdigital merged 3 commits into
mainfrom
fix/scanner-bugs
Jun 27, 2026
Merged

Fix empty-note threshold, drop dead orphan-link code, dedupe byte formatting#91
rogerdigital merged 3 commits into
mainfrom
fix/scanner-bugs

Conversation

@rogerdigital

Copy link
Copy Markdown
Owner

Summary

Three fixes found while auditing the codebase for obvious issues. lint / build / test (163 passing) all green; split into one commit per logical change.

1. emptyNoteWordThreshold setting had no effect (functional bug)

The empty-notes scanner only checked for zero-length content and never read ctx.emptyNoteWordThreshold, so the settings slider did nothing — only completely empty notes were ever flagged.

  • New pure helper countWords() with CJK-aware counting: each Han / Hiragana / Katakana / Hangul character counts as one word (CJK text has no word separators), Latin/other text splits on whitespace, mixed content sums correctly. Without this the threshold is meaningless on Chinese vaults.
  • Judgment changed to countWords(body) <= ctx.emptyNoteWordThreshold.
  • Non-empty short notes now get a stub-specific message ("only has N words") and a wordCount evidence field.
  • Added regression tests including one that toggles the threshold and asserts the setting actually changes behavior — this is the direct guard against the original bug.

2. Dead resolvedLinks fast path in orphan-attachments

The optimization cast resolvedLinks values to string and checked typeof === "string", but Obsidian stores link counts there as number, so the branch never executed. It also couldn't work as intended: resolvedLinks only tracks markdown-to-markdown references and cannot resolve attachment link targets to disk paths. Removed the dead branch; every link already falls through to resolveVaultLinkTargets, so behavior is unchanged.

3. Duplicated formatBytes helpers

render-issues.ts and markdown-export.ts each carried a near-identical local formatBytes, while utils/format.ts already exports formatSize for the same purpose. Removed both copies and routed all byte formatting through the shared helper.

Validation

  • npm run lint
  • npm run lint:obsidian-warnings
  • npm run build
  • npm test ✅ 163/163

… word count

The threshold setting was dead — the scanner only checked for zero-length
content and never read ctx.emptyNoteWordThreshold, so the slider had no
effect. Count words with a CJK-aware counter (each Han/kana/hangul char
counts as one word; Latin text splits on whitespace) so the threshold
works for both Chinese and English notes. Short non-empty notes now get a
stub-specific message and a wordCount evidence field.
The optimization cast resolvedLinks values to string and checked
typeof === "string", but Obsidian stores link counts there as numbers,
so the branch never ran. resolvedLinks also only tracks markdown-to-markdown
references and cannot resolve attachment link targets anyway. Drop the dead
branch; every link already falls through to resolveVaultLinkTargets, so
behavior is unchanged.
render-issues.ts and markdown-export.ts each carried a near-identical
local formatBytes while utils/format.ts already exports formatSize for
the same purpose. Remove both copies and route all byte formatting
through the shared helper.
@rogerdigital
rogerdigital merged commit 934368e into main Jun 27, 2026
1 check passed
@rogerdigital
rogerdigital deleted the fix/scanner-bugs branch June 27, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant