fix: resolve all ESLint errors, enforce lint in CI

This commit is contained in:
lucaronin
2026-02-22 14:31:02 +01:00
32 changed files with 125 additions and 88 deletions

View File

@@ -25,7 +25,7 @@ export function estimateTokens(text: string | number): number {
const DEFAULT_CONTEXT_LIMIT = 180_000
export function getContextLimit(_model: string): number {
export function getContextLimit(): number {
return DEFAULT_CONTEXT_LIMIT
}
@@ -35,13 +35,12 @@ export function getContextLimit(_model: string): number {
export function buildSystemPrompt(
notes: VaultEntry[],
allContent: Record<string, string>,
model: string,
): { prompt: string; totalTokens: number; truncated: boolean } {
if (notes.length === 0) {
return { prompt: '', totalTokens: 0, truncated: false }
}
const contextBudget = Math.floor(getContextLimit(model) * 0.6)
const contextBudget = Math.floor(getContextLimit() * 0.6)
const preamble = [
'You are a helpful AI assistant integrated into Laputa, a personal knowledge management app.',
'The user has selected the following notes as context. Use them to answer questions accurately.',
@@ -177,8 +176,8 @@ export async function streamChat(
await readSseStream(reader, onChunk)
onDone()
} catch (err: any) {
onError(err.message || 'Network error')
} catch (err: unknown) {
onError(err instanceof Error ? err.message : 'Network error')
}
}

View File

@@ -40,7 +40,7 @@ export function parseFrontmatter(content: string | null): ParsedFrontmatter {
let inList = false
for (const line of match[1].split('\n')) {
const listMatch = line.match(/^ - (.*)$/)
const listMatch = line.match(/^ {2}- (.*)$/)
if (listMatch && currentKey) {
inList = true
currentList.push(unquote(listMatch[1]))

View File

@@ -1,4 +1,4 @@
import type { VaultEntry, SidebarSelection, ModifiedFile } from '../types'
import type { VaultEntry, SidebarSelection } from '../types'
export interface RelationshipGroup {
label: string
@@ -196,6 +196,6 @@ function filterByFilterType(entries: VaultEntry[], filter: string): VaultEntry[]
return []
}
export function filterEntries(entries: VaultEntry[], selection: SidebarSelection, _modifiedFiles?: ModifiedFile[]): VaultEntry[] {
export function filterEntries(entries: VaultEntry[], selection: SidebarSelection): VaultEntry[] {
return filterByKind(entries, selection)
}

View File

@@ -8,21 +8,36 @@ export function preProcessWikilinks(md: string): string {
return md.replace(/\[\[([^\]]+)\]\]/g, (_m, target) => `${WL_START}${target}${WL_END}`)
}
// Minimal shape of a BlockNote block for wikilink processing
interface BlockLike {
content?: InlineItem[]
children?: BlockLike[]
[key: string]: unknown
}
interface InlineItem {
type: string
text?: string
props?: Record<string, string>
content?: unknown
[key: string]: unknown
}
/** Walk blocks and replace placeholder text with wikilink inline content */
export function injectWikilinks(blocks: any[]): any[] {
return blocks.map(block => {
export function injectWikilinks(blocks: unknown[]): unknown[] {
return (blocks as BlockLike[]).map(block => {
if (block.content && Array.isArray(block.content)) {
block.content = expandWikilinksInContent(block.content)
}
if (block.children && Array.isArray(block.children)) {
block.children = injectWikilinks(block.children)
block.children = injectWikilinks(block.children) as BlockLike[]
}
return block
})
}
function expandWikilinksInContent(content: any[]): any[] {
const result: any[] = []
function expandWikilinksInContent(content: InlineItem[]): InlineItem[] {
const result: InlineItem[] = []
for (const item of content) {
if (item.type !== 'text' || typeof item.text !== 'string' || !item.text.includes(WL_START)) {
result.push(item)
@@ -62,7 +77,7 @@ export function splitFrontmatter(content: string): [string, string] {
export function countWords(content: string): number {
const [, body] = splitFrontmatter(content)
const text = body.replace(/[#*_\[\]`>~\-|]/g, '').trim()
const text = body.replace(/[#*_[\]`>~\-|]/g, '').trim()
if (!text) return 0
return text.split(/\s+/).filter(Boolean).length
}