Repository navigation
Adopt local quality-tooling standard - #49
Conversation
Roll the fleet quality-tooling standard onto annoteca: type-checked eslint (recommendedTypeChecked plus the curated sonarjs BUG allowlist), full strict tsconfig, husky pre-commit, knip, type-coverage, and Stryker. Prettier was already adopted. Add the template check-submission.mjs (with the as Window ban) and .coderabbit.yaml. Remove the legacy blanket ajv override (ajv resolves patched on its own; no scoped override) and add the qs floor Stryker's dep tree needs. OSV clean. Fix every finding the new tooling surfaces, verified by the test suite: - Widen the editorCallback and editor-menu params to MarkdownFileInfo so strictFunctionTypes accepts them; the downstream methods already take it. - Remove a dead always-false match.index check in the fence parser. - Rewrite three super-linear regexes (the opener escape, unescape, and reguard patterns, and the fence-line matcher) to linear equivalents. - Make the sync view lifecycle methods non-async and drop the pointless async on the composer submit path. - Extract IndexBackedListView for the shared list-view onOpen, plus shared test helpers, removing duplicate functions. - Clear knip: drop unused exports, and use the INDEX_ENTRY_CATEGORY constant in settings instead of an inline duplicate. No user-facing behavior change.
|
Warning Ignoring CodeRabbit configuration file changes. For security, only the configuration from the base branch is applied for open source repositories. 📝 WalkthroughSummary by CodeRabbit
WalkthroughThe pull request refines Markdown fence and opener parsing, consolidates editor and view lifecycle behavior, reduces public module surface, reuses shared settings and test helpers, and adds static analysis, mutation testing, type coverage, commit, and submission checks. ChangesCore code changes
Repository quality tooling
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Rolls a standardized local “quality tooling” stack onto Annoteca (type-aware ESLint, stricter TypeScript, submission checks, and optional analysis tools) and applies the resulting cleanup/refactors across the plugin to keep the codebase passing gates.
Changes:
- Adopt type-aware ESLint + curated sonarjs bug rules, and move TS config to
strictwith additional safety flags. - Add optional developer tooling (Husky pre-commit, Knip, type-coverage, Stryker) and supporting configs.
- Refactor a few modules to remove unused exports / unnecessary
asyncand deduplicate view logic.
Reviewed changes
Copilot reviewed 17 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| views.ts | Deduplicates shared list-view onOpen wiring and removes re-exports of view-utils helpers. |
| types.ts | Removes an unused exported type alias from the public surface. |
| tsconfig.json | Switches to strict and adds additional compiler safety flags. |
| stryker.config.mjs | Adds on-demand mutation testing configuration. |
| settings.ts | Reuses INDEX_ENTRY_CATEGORY and makes some helpers internal-only. |
| scripts/check-submission.mjs | Extends submission pre-checks (regex lookbehind + Window assertion ban) and clarifies rationale. |
| parser.ts | Rewrites opener-escape regex handling for linear behavior and tightens a dead guard in matchAll. |
| package.json | Adds scripts and dev tooling configuration (knip, type-coverage, Stryker, husky). |
| package-lock.json | Locks new dev-tool dependencies and updates transitive dependency graph. |
| knip.json | Adds Knip configuration scaffold. |
| imports.ts | Rewrites fence-line regex to avoid super-linear backtracking. |
| frontmatter-summary.ts | Makes internal constants non-exported. |
| eslint.config.mts | Enables type-aware ESLint presets and adds sonarjs bug-focused ruleset. |
| composer.ts | Removes unnecessary async on synchronous submit path and internalizes a helper. |
| .husky/pre-commit | Adds a deterministic local pre-commit gate script. |
| .gitignore | Ignores Stryker sandbox and mutation reports. |
| .coderabbit.yaml | Configures CodeRabbit review behavior for this repo. |
| tests/orphan-stars.test.ts | Deduplicates a minimal TFile stand-in helper across test cases. |
| tests/comment-service.test.ts | Deduplicates a shared “target comment” helper for multi-marker fixtures. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # Deterministic pre-commit gate. Blocks the commit if any check fails: | ||
| # - eslint (incl. type-aware no-unsafe-* and async-safety rules) | ||
| # - prettier --check | ||
| # - submission pre-checks | ||
| # - full type-check (tsc --noEmit) | ||
| # To fix formatting: npx prettier --write "**/*.ts" | ||
| npm run lint && npx tsc --noEmit |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@__tests__/orphan-stars.test.ts`:
- Around line 47-52: Move the shared tfile TFile test-double helper from
orphan-stars.test.ts into a non-test helper file under __tests__, export it
there, and import it into orphan-stars.test.ts. Preserve its current path and md
extension initialization and update all existing usages to use the imported
helper.
In @.husky/pre-commit:
- Around line 1-7: Change the executable permission of the .husky/pre-commit
hook from 100644 to 100755, leaving its lint and TypeScript commands unchanged
so Git runs the pre-commit checks.
In `@scripts/check-submission.mjs`:
- Around line 91-93: Update the submission scanning logic around WINDOW_ASSERT
and the code[index] lookup to detect Window assertions that span multiple
physical lines, while still ignoring comments. Normalize source by logical
statements/tokens or scan non-comment source across newlines, and report the
first original source line where the assertion begins using the existing
findings format.
- Around line 118-125: Update the comment above the built-bundle check to state
that the release flow runs lint before the build, while preserving that this
branch remains opportunistic because it does not execute after the build. Keep
the explanation that the source scan is the primary CI guard and avoid changing
the check’s behavior.
- Around line 50-52: Update the source preprocessing used before WINDOW_ASSERT
is applied so string and template-literal contents are masked while preserving
newline positions and code structure. Ensure withoutComments() or the
corresponding check path excludes literal text from the assertion scan, while
actual as Window casts remain detectable by the code-only checks near line 91.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 56f32489-4d5f-4ca2-bc7b-452230b05203
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (19)
.coderabbit.yaml.gitignore.husky/pre-commit__tests__/comment-service.test.ts__tests__/orphan-stars.test.tscomposer.tseslint.config.mtsfrontmatter-summary.tsimports.tsknip.jsonmain.tspackage.jsonparser.tsscripts/check-submission.mjssettings.tsstryker.config.mjstsconfig.jsontypes.tsviews.ts
| // Minimal in-memory TFile stand-in shared by the harnesses and cases below. | ||
| const tfile = (path: string): TFile => { | ||
| const f = new TFile(); | ||
| Object.assign(f, { path, extension: 'md' }); | ||
| return f; | ||
| }; |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Move the shared TFile test double out of this test file.
__tests__/orphan-stars.test.ts defines tfile as a shared test double. Move it to a non-*.test.ts helper under __tests__/, then import it here.
As per coding guidelines, shared test doubles must be placed in non-*.test.ts files under __tests__/.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@__tests__/orphan-stars.test.ts` around lines 47 - 52, Move the shared tfile
TFile test-double helper from orphan-stars.test.ts into a non-test helper file
under __tests__, export it there, and import it into orphan-stars.test.ts.
Preserve its current path and md extension initialization and update all
existing usages to use the imported helper.
Source: Coding guidelines
| # Deterministic pre-commit gate. Blocks the commit if any check fails: | ||
| # - eslint (incl. type-aware no-unsafe-* and async-safety rules) | ||
| # - prettier --check | ||
| # - submission pre-checks | ||
| # - full type-check (tsc --noEmit) | ||
| # To fix formatting: npx prettier --write "**/*.ts" | ||
| npm run lint && npx tsc --noEmit |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
mode="$(git ls-files --stage -- .husky/pre-commit | awk 'NR == 1 { print $1 }')"
if [ "$mode" != "100755" ]; then
printf 'Expected .husky/pre-commit to have mode 100755; found %s\n' "$mode"
exit 1
fiRepository: ckelsoe/obsidian-annoteca
Length of output: 224
Set the pre-commit hook to executable mode.
.husky/pre-commit is stored as 100644, so Git does not run it. Change the hook mode to 100755 to keep the lint and TypeScript gates enabled.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.husky/pre-commit around lines 1 - 7, Change the executable permission of
the .husky/pre-commit hook from 100644 to 100755, leaving its lint and
TypeScript commands unchanged so Git runs the pre-commit checks.
| const WINDOW_ASSERT = /\bas\s+(?:unknown\s+as\s+)?Window\b/; | ||
| const WINDOW_ASSERT_WHY = | ||
| "do not type-assert to Window (`as Window`); use Obsidian's activeWindow / activeDocument or proper typing instead."; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Files matching check-submission:\n'
fd -a 'check-submission\.mjs$' . || true
printf '\nGit status summary:\n'
git status --short
file="$(fd 'check-submission\.mjs$' . | head -n 1)"
if [ -n "${file:-}" ]; then
printf '\nLine count:\n'
wc -l "$file"
printf '\nOutline:\n'
ast-grep outline "$file" --view compact || true
printf '\nRelevant lines 1-110:\n'
sed -n '1,110p' "$file" | nl -ba
fi
printf '\nSearch WINDOW_ASSERT and comment stripper usages:\n'
rg -n "WINDOW_ASSERT|withoutComments|without[[:space:]']*(Comments|Strings|Literals)|test\\(code" . --glob '!node_modules' --glob '!dist' --glob '!build' || trueRepository: ckelsoe/obsidian-annoteca
Length of output: 538
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file="./scripts/check-submission.mjs"
printf 'Lines 1-170:\n'
awk '{printf "%4d\t%s\n", NR, $0}' "$file"
printf '\nRelevant WINDOW/line-check occurrences:\n'
grep -n -E "WINDOW_ASSERT|withoutComments|test\\(code|const code =|for \\(|match" "$file"Repository: ckelsoe/obsidian-annoteca
Length of output: 9612
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Behavioral probe of WINDOW_ASSERT with comment-stripped literals:\n'
node - <<'JS'
const source = `
let a = "convert this as Window";
let b = \`convert this as Window\`;
let c = 'convert this as Window';
let d = /* convert this as Window */ 1;
let e = value as Window;
let f = value as unknown as Window;
`;
const WINDOW_ASSERT = /\bas\s+(?:unknown\s+as\s+)?Window\b/;
function withoutComments(source) {
return source
.replace(/\/\*[\s\S]*?\*\//g, m => m.replace(/[^\n]/g, " "))
.split(/\r?\n/)
.map(line => line.replace(/\/\/.*$/, ""));
}
const code = withoutComments(source);
code.forEach((line, index) => {
if (WINDOW_ASSERT.test(line)) {
console.log(`${index + 1}: ${line.trim()}`);
}
});
JS
printf '\nCheck whether source repo has any current WINDOW_ASSERT false positives outside comments:\n'
node - <<'JS'
const { readdirSync, readFileSync } = require("node:fs");
const { execSync } = require("node:child_process");
const SKIP_DIRS = new Set(["node_modules", ".git", "dist", "build", "scripts"]);
const CODE_EXT = /\.(ts|mts|cts|tsx|js|mjs|cjs)$/;
const WINDOW_ASSERT = /\bas\s+(?:unknown\s+as\s+)?Window\b/;
function walk(dir) {
const paths = [];
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const path = `${dir}/${entry.name}`;
if (entry.isDirectory() && !SKIP_DIRS.has(entry.name)) paths.push(...walk(path));
if (entry.isFile() && CODE_EXT.test(entry.name)) paths.push(path);
}
return paths;
}
for (const file of walk(".")) {
try {
const source = readFileSync(file, "utf8");
const codeLines = source
.replace(/\/\*[\s\S]*?\*\//g, m => m.replace(/[^\n]/g, " "))
.split(/\r?\n/)
.map(line => line.replace(/\/\/.*$/, ""));
codeLines.forEach((line, index) => {
if (WINDOW_ASSERT.test(line)) {
console.log(`${file}:${index + 1}: ${line.trim()}`);
}
});
} catch {}
}
const files = walk(".");
console.log("scanned", files.length, "code files");
JSRepository: ckelsoe/obsidian-annoteca
Length of output: 520
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf 'Files matching check-submission:\n'
fd -a 'check-submission\.mjs$' . || true
printf '\nGit status summary:\n'
git status --short
file="$(fd 'check-submission\.mjs$' . | head -n 1)"
if [ -n "${file:-}" ]; then
printf '\nLine count:\n'
wc -l "$file"
printf '\nOutline:\n'
ast-grep outline "$file" --view expanded || true
printf '\nRelevant lines 1-110:\n'
sed -n '1,110p' "$file" | awk '{printf "%4d\t%s\n", NR, $0}'
fi
printf '\nSearch WINDOW_ASSERT and comment stripper usages:\n'
rg -n "WINDOW_ASSERT|withoutComments|without[[:space:]']*(Comments|Strings|Literals)|test\\(code" . --glob '!node_modules' --glob '!dist' --glob '!build' || trueRepository: ckelsoe/obsidian-annoteca
Length of output: 7948
Mask string literals before applying WINDOW_ASSERT.
withoutComments() keeps string and template-literal contents, so ordinary text such as "convert this as Window" can trigger this scan while the file has no as Window cast. Mask literals or parse tokens while preserving line positions so the code-only checks at line 91 do not reject valid source.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@scripts/check-submission.mjs` around lines 50 - 52, Update the source
preprocessing used before WINDOW_ASSERT is applied so string and
template-literal contents are masked while preserving newline positions and code
structure. Ensure withoutComments() or the corresponding check path excludes
literal text from the assertion scan, while actual as Window casts remain
detectable by the code-only checks near line 91.
| if (WINDOW_ASSERT.test(code[index] ?? "")) { | ||
| findings.push(`${where}: ${WINDOW_ASSERT_WHY}`); | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
rg -n -U '\bas\s+(?:unknown\s+as\s+)?\s*\n\s*Window\b' \
--glob '*.ts' \
--glob '*.tsx'Repository: ckelsoe/obsidian-annoteca
Length of output: 163
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo "== file outline/preview =="
wc -l scripts/check-submission.mjs
sed -n '1,150p' scripts/check-submission.mjs | cat -n
echo "== all WINDOW_ASSERT usage =="
rg -n "WINDOW_ASSERT|WINDOW_ASSERT_WHY|comment|lookbehind|jsesc|split\\(" scripts/check-submission.mjsRepository: ckelsoe/obsidian-annoteca
Length of output: 10626
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo "== package/test references mentioning Window assertion or submission check =="
rg -n "check-submission|WINDOW_ASSERT|lookbehind|lint:release|npm run lint|submission" .github scripts package.json 2>/dev/null || true
echo "== git status/stat =="
git diff --stat || true
git status --short || trueRepository: ckelsoe/obsidian-annoteca
Length of output: 4459
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
node - <<'JS'
const source =
`function f() {
const value = 1;
const x = value as unknown as
Window;
}
`;
const WINDOW_ASSERT = /\bas\s+(?:unknown\s+as\s+)?Window\b/;
const code = source
.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, " "))
.split(/\r?\n/)
.map((line) => line.replace(/\/\/.*$/, ""));
console.log(JSON.stringify({
perLineWindowFound: code.some((line) => WINDOW_ASSERT.test(line)),
perLineWindowMatches: code.map((line, i) => ({ index: i + 1, line, window: WINDOW_ASSERT.test(line) })),
fullSourceWindowFound: WINDOW_ASSERT.test(source),
line: code.length
}));
JSRepository: ckelsoe/obsidian-annoteca
Length of output: 550
Handle multiline Window assertions in the submission guard.
WINDOW_ASSERT runs on comment-stripped lines, so value as unknown as \| Window is not reported. Normalize source over logical statements/tokens or scan non-comment source through newlines, then report the first original line that starts the assertion.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@scripts/check-submission.mjs` around lines 91 - 93, Update the submission
scanning logic around WINDOW_ASSERT and the code[index] lookup to detect Window
assertions that span multiple physical lines, while still ignoring comments.
Normalize source by logical statements/tokens or scan non-comment source across
newlines, and report the first original source line where the assertion begins
using the existing findings format.
| // Opportunistic, and deliberately NOT the primary check: `main.js` is gitignored, | ||
| // so it is absent on a fresh checkout. In CI `npm run lint` runs before | ||
| // `npm run build`, and the release flow does not run lint at all, so in current | ||
| // automation this branch finds nothing; it fires only when lint runs after a | ||
| // build (e.g. locally). The source scan above is the guard that actually holds in | ||
| // CI; this adds the one thing sources cannot show, a DEPENDENCY that inlines a | ||
| // lookbehind into the bundle. Making automation scan the built bundle would mean | ||
| // reordering the workflows to run this after the build (a fleet-wide change). |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the release-flow description.
The comment says that the release flow does not run lint. .github/workflows/release.yml runs npm run lint at Lines [39]-[45]. State that release lint runs before the build. The bundle branch remains opportunistic because it does not run after the build.
Proposed wording
-// `npm run lint` runs before
-// `npm run build`, and the release flow does not run lint at all, so in current
+// `npm run lint` runs before
+// `npm run build` in both CI and the release flow, so in current📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Opportunistic, and deliberately NOT the primary check: `main.js` is gitignored, | |
| // so it is absent on a fresh checkout. In CI `npm run lint` runs before | |
| // `npm run build`, and the release flow does not run lint at all, so in current | |
| // automation this branch finds nothing; it fires only when lint runs after a | |
| // build (e.g. locally). The source scan above is the guard that actually holds in | |
| // CI; this adds the one thing sources cannot show, a DEPENDENCY that inlines a | |
| // lookbehind into the bundle. Making automation scan the built bundle would mean | |
| // reordering the workflows to run this after the build (a fleet-wide change). | |
| // Opportunistic, and deliberately NOT the primary check: `main.js` is gitignored, | |
| // so it is absent on a fresh checkout. In CI `npm run lint` runs before | |
| // `npm run build` in both CI and the release flow, so in current | |
| // automation this branch finds nothing; it fires only when lint runs after a | |
| // build (e.g. locally). The source scan above is the guard that actually holds in | |
| // CI; this adds the one thing sources cannot show, a DEPENDENCY that inlines a | |
| // lookbehind into the bundle. Making automation scan the built bundle would mean | |
| // reordering the workflows to run this after the build (a fleet-wide change). |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@scripts/check-submission.mjs` around lines 118 - 125, Update the comment
above the built-bundle check to state that the release flow runs lint before the
build, while preserving that this branch remains opportunistic because it does
not execute after the build. Keep the explanation that the source scan is the
primary CI guard and avoid changing the check’s behavior.
Dismissing per maintainer decision. CodeRabbit's code review found zero actionable findings; this CHANGES_REQUESTED is driven solely by the org-level Docstring Coverage pre-merge check (71.43 percent vs an 80 percent threshold), which counts JSDoc blocks and not the diff's extensive line comments. The docstring-coverage gate is being addressed in CodeRabbit config, not in this PR. CI check is green.
What
Rolls the local quality-tooling standard onto annoteca.
Tooling: type-checked eslint (
recommendedTypeChecked+ the curated sonarjs BUG allowlist), fullstricttsconfig withskipLibCheckandnoFallthroughCasesInSwitch, husky pre-commit, knip, type-coverage (atLeast: 99), and Stryker (npm run test:mutation, on demand). Prettier was already adopted. Adds the templatecheck-submission.mjs(with theas Windowban) and.coderabbit.yaml.Dependencies: removes the legacy blanket
ajvoverride (ajv resolves patched on its own; no scoped override) and adds theqs ^6.15.2floor Stryker's dep tree needs. OSV clean.Findings the tooling surfaced, all fixed and test-verified
editorCallback/editor-menuparams toMarkdownFileInfo, the wider type Obsidian actually passes. The downstream methods already accept it, so no call site narrows.match.index === undefinedguard in the fence parser (match.indexis always defined formatchAll).<!--opener escape/unescape/reguard patterns and the fence-line matcher to linear equivalents (atomic-group emulation for the fence). 288 parser + import tests confirm identical behavior.asyncon the composer submit path.IndexBackedListViewfor the shared list-viewonOpen, and sharedtfile/targettest helpers.exports, and used theINDEX_ENTRY_CATEGORYconstant insettings.tsinstead of an inline duplicate of it.Verification
eslint, prettier, check-submission, marketplace typecheck,
tsc --noEmit, 808 tests, type-coverage 99.96%, OSV clean. The husky hook blocks a bad commit. No user-facing behavior change, so no version bump.Follow-up (non-gate)
Stryker instruments cleanly with no ajv error, but its dry-run needs the jsdom test env wrapped in Stryker's coverage mixin before a mutation baseline runs. Same "baseline pending" state as icon-palette; tracked separately.