Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
# Review once when a PR opens; do not re-review on every push. Batch fixes,
# then comment `@coderabbitai full review` to request the final pass.
# Release/metadata PRs (titled "Release ...") are skipped: they only bump the
# version + CHANGELOG, and the release workflow (attestation + scan) is their gate.
reviews:
auto_review:
enabled: true
auto_incremental_review: false
drafts: false
ignore_title_keywords:
- "Release"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
# npm
node_modules

# Stryker mutation-testing sandbox + reports
.stryker-tmp
reports/mutation

# Build output
main.js

Expand Down
7 changes: 7 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 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
Comment on lines +1 to +7
Comment on lines +1 to +7

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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
fi

Repository: 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.

21 changes: 9 additions & 12 deletions __tests__/comment-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ function firstComment(content: string) {
return c;
}

// Like firstComment but without the single-comment assertion: the damaged-marker
// blocks below parse fixtures that may hold more than one marker, so they take
// the first parsed comment and leave the count to the assertions in each case.
const target = (content: string) => {
const c = parseAll(content)[0];
if (!c) throw new Error('no comment parsed');
return c;
};

describe('resolveComment with delete-on-resolve off', () => {
it('keeps the marker and appends a [resolved ...] line', async () => {
const h = makeHarness(false);
Expand Down Expand Up @@ -1440,12 +1449,6 @@ describe('destructive verbs refuse a note with an unclosed opener', () => {
'Outro paragraph.',
].join('\n');

const target = (content: string) => {
const c = parseAll(content)[0];
if (!c) throw new Error('no comment parsed');
return c;
};

it('refuses to delete, and says why', async () => {
const h = makeHarnessWith(DAMAGED);
await h.service.deleteComment('note.md', target(h.content));
Expand Down Expand Up @@ -1550,12 +1553,6 @@ describe('a blocked write is not reported as a stale transition', () => {
'-->',
].join('\n');

const target = (content: string) => {
const c = parseAll(content)[0];
if (!c) throw new Error('no comment parsed');
return c;
};

it('resolve with delete-on-resolve says nothing about being already resolved', async () => {
const h = makeHarnessWith(DAMAGED, true);
await h.service.resolveComment('note.md', target(h.content));
Expand Down
22 changes: 7 additions & 15 deletions __tests__/orphan-stars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ interface PluginUnderTest {
const noteWith = (id: string) =>
`Prose. ${serialize({ id, category: 'clarify', body: 'why?' })}`;

// 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;
};
Comment on lines +47 to +52

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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


// A vault whose file list can grow after the latch is set, which is the whole
// point: sync, another device, or an assistant writing a note.
function makeHarness(initial: Record<string, string>) {
const files = new Map<string, string>(Object.entries(initial));
const saved: string[][] = [];
const tfile = (path: string): TFile => {
const f = new TFile();
Object.assign(f, { path, extension: 'md' });
return f;
};
const plugin = Object.create(
AnnotecaPlugin.prototype,
) as unknown as PluginUnderTest;
Expand Down Expand Up @@ -218,11 +220,6 @@ describe('runDriftCheck against a stale index', () => {
it('keeps the snapshot of a comment in a note that arrived after the scan', async () => {
const files = new Map<string, string>([['welcome.md', 'nothing here']]);
const reads: string[] = [];
const tfile = (path: string): TFile => {
const f = new TFile();
Object.assign(f, { path, extension: 'md' });
return f;
};
const plugin = Object.create(
AnnotecaPlugin.prototype,
) as unknown as DriftPlugin;
Expand Down Expand Up @@ -288,11 +285,6 @@ describe('runDriftCheck against a stale index', () => {
describe('indexUnseenFiles content source', () => {
it('indexes an unseen note from the editor buffer when one holds it', async () => {
const files = new Map<string, string>([['welcome.md', 'nothing here']]);
const tfile = (path: string): TFile => {
const f = new TFile();
Object.assign(f, { path, extension: 'md' });
return f;
};
const editorText = noteWith('typed001');
const plugin = Object.create(
AnnotecaPlugin.prototype,
Expand Down
6 changes: 3 additions & 3 deletions composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { createStackedRow } from './ui-helpers';
// file. Deliberately not VANISHED_MESSAGE: nothing has moved or been deleted,
// and "reopen the note" is the wrong instruction when the note is fine and the
// TAB is what changed.
export function wrongFileMessage(path: string): string {
function wrongFileMessage(path: string): string {
return `That tab no longer shows ${path}, so nothing was saved. Open the note again and retry.`;
}

Expand Down Expand Up @@ -248,7 +248,7 @@ export class ComposerForm {
)
) {
e.preventDefault();
void this.submit();
this.submit();
}
});

Expand Down Expand Up @@ -470,7 +470,7 @@ export class ComposerForm {
return enabled.some((c) => c.id === category);
}

private async submit(): Promise<void> {
private submit(): void {
const finalBody = this.composeFinalBody();
if (finalBody === '') {
new Notice('Comment body is empty.');
Expand Down
50 changes: 50 additions & 0 deletions eslint.config.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import tseslint from "typescript-eslint";
import obsidianmd from "eslint-plugin-obsidianmd";
import sonarjs from "eslint-plugin-sonarjs";
import globals from "globals";
import prettierConfig from "eslint-config-prettier";
import { globalIgnores } from "eslint/config";
Expand All @@ -23,21 +24,70 @@ export default tseslint.config(
},
},
},
// Type-aware baseline: recommended + the type-checked family (no-unsafe-*,
// no-floating-promises, no-misused-promises, await-thenable, no-base-to-string,
// etc.). Obsidian plugins are heavily async and traffic in untyped host
// globals; these catch unsafe-any and unhandled-promise bugs.
...tseslint.configs.recommendedTypeChecked,
...obsidianmd.configs.recommended,
{
files: ["**/*.ts"],
plugins: { sonarjs },
rules: {
"@typescript-eslint/require-await": "error",
// eslint-plugin-sonarjs: a curated BUG-detection allowlist, not the
// full recommended preset (whose style/metric rules are noise at
// scale). Every rule here flags a genuine logic defect. Two rules are
// intentionally excluded: no-async-constructor (false-positives on the
// Obsidian fluent-component pattern) and no-duplicated-branches (a
// duplication smell that floods on exhaustive dispatch switches).
"sonarjs/no-all-duplicated-branches": "error",
"sonarjs/no-identical-conditions": "error",
"sonarjs/no-identical-expressions": "error",
"sonarjs/no-identical-functions": "error",
"sonarjs/no-gratuitous-expressions": "error",
"sonarjs/no-redundant-assignments": "error",
"sonarjs/no-redundant-boolean": "error",
"sonarjs/no-element-overwrite": "error",
"sonarjs/no-collection-size-mischeck": "error",
"sonarjs/no-empty-collection": "error",
"sonarjs/no-unused-collection": "error",
"sonarjs/no-use-of-empty-return-value": "error",
"sonarjs/no-ignored-return": "error",
"sonarjs/different-types-comparison": "error",
"sonarjs/super-linear-regex": "error",
"sonarjs/no-inverted-boolean-check": "error",
"sonarjs/for-loop-increment-sign": "error",
"sonarjs/duplicates-in-character-class": "error",
"sonarjs/no-duplicate-in-composite": "error",
},
},
{
files: ["__tests__/**/*.ts"],
languageOptions: {
globals: {
...globals.jest,
},
},
rules: {
// Tests are not shipped or marketplace-scanned; fixtures and mocks
// legitimately traffic in `any`.
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/unbound-method": "off",
},
},
globalIgnores([
"node_modules",
"dist",
".stryker-tmp",
"main.js",
"scripts",
"esbuild.config.mjs",
"stryker.config.mjs",
"version-bump.mjs",
"versions.json",
"package.json",
Expand Down
8 changes: 4 additions & 4 deletions frontmatter-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import type { App, TFile } from 'obsidian';
import type { Comment } from './types';

export const FM_OPEN = 'annoteca_open';
export const FM_OLDEST_OPEN = 'annoteca_oldest_open';
export const FM_CATEGORIES = 'annoteca_categories';
export const FILECLASS_VALUE = 'annoteca';
const FM_OPEN = 'annoteca_open';
const FM_OLDEST_OPEN = 'annoteca_oldest_open';
const FM_CATEGORIES = 'annoteca_categories';
const FILECLASS_VALUE = 'annoteca';
// The class tag is opt-in, and its consumers are the Fileclass plugin and its
// predecessor Metadata Menu (same author), which read a `fileclass` property, so
// that is the default. Configurable for setups that use a different alias.
Expand Down
7 changes: 6 additions & 1 deletion imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ const HTML_COMMENT_RE = /<!--([\s\S]*?)-->/g;
// pattern used to write that as an absolute /\s{0,3}/, so a fence legally
// nested in a list item at four or more columns was not recognised as a fence
// at all and bulk convert rewrote the samples inside it.
const FENCE_LINE_RE = /^([ \t]*)(`{3,}|~{3,})(.*)$/;
// The fence run is matched inside a lookahead and then consumed via the `\2`
// backreference. That makes the run atomic: `` `{3,} `` grabs the whole run once
// and never gives characters back to the trailing `.*`, so the two quantifiers
// cannot backtrack against each other (the character class of `.` overlaps the
// fence char). Capture groups are unchanged: 1 = indent, 2 = fence run, 3 = rest.
const FENCE_LINE_RE = /^([ \t]*)(?=(`{3,}|~{3,}))\2(.*)$/;

// The block-quote markers opening a line, each with the one space of content it
// is allowed to swallow. What follows is the quote's CONTENT, and every indent
Expand Down
3 changes: 3 additions & 0 deletions knip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "https://unpkg.com/knip@6/schema.json"
}
Loading
Loading