Skip to content

Conversation

@mudcube
Copy link
Contributor

@mudcube mudcube commented Jan 29, 2026

Summary

This PR strengthens the codebase's type safety and code quality by enforcing stricter TypeScript rules, eliminating unsafe type assertions, and fixing regex patterns that could cause performance issues.

Key Changes

TypeScript & Type Safety

  • Upgraded ESLint rules to STRICT mode: Changed @typescript-eslint/explicit-function-return-type and @typescript-eslint/no-explicit-any from warn to error
  • Eliminated unsafe as any assertions: Replaced all as any casts with proper type annotations throughout the codebase
    • site/src/routes/docs/+layout.server.ts: Changed to as { message: string }
    • site/src/routes/docs/[...slug]/+page.server.ts: Multiple instances updated with proper error types
    • src/lib/generators/api-docs.ts: Replaced with nullish coalescing operator
  • Improved null safety: Replaced non-null assertions (!) with optional chaining and nullish coalescing where appropriate
    • packages/docs-engine-cli/src/link-checker.ts: Refactored cache lookup to avoid non-null assertion
    • src/lib/generators/api-docs.test.ts: Used nullish coalescing for safe access

Code Quality & Security

  • Added security rules configuration: Configured eslint-plugin-security rules with intentional exceptions for safe patterns
    • Disabled detect-object-injection for typed objects with validated keys
    • Disabled detect-non-literal-regexp for intentional search functionality
    • Set detect-unsafe-regex to warn for manual review
  • Fixed regex catastrophic backtracking:
    • packages/docs-engine-cli/src/link-extractor.ts: Simplified HTML link regex to avoid nested quantifiers
    • src/lib/generators/parsers/env-parser.ts: Replaced nested \s* with single \s in variable matching pattern

Type System Improvements

  • Consolidated type definitions: Moved inline types to proper interfaces
    • src/lib/generators/generic-generator.ts: Moved all types from types.ts into the main file with full documentation
    • src/lib/generators/parsers/sql-parser.ts: Added SqlColumn and SqlTable interfaces for clarity
    • src/lib/components/ScreenshotImage.svelte: Defined ScreenshotImageProps inline
  • Removed stub type files: Deleted src/lib/components/types.ts and src/lib/generators/parsers/types.ts, consolidating exports
  • Updated type imports: Fixed import paths to use proper navigation utilities instead of component-level types

Dependencies

  • Updated @types/node from ^25.0.10 to ^25.1.0
  • Updated svelte from ^5.48.2 to ^5.48.5
  • Updated happy-dom from ^20.3.9 to ^20.4.0
  • Removed deprecated @types/dompurify (dompurify provides its own types)
  • Updated @rollup/rollup-linux-arm64-gnu from 4.53.2 to 4.57.0
  • Reorganized optional dependencies in package.json for clarity

Documentation

  • Updated docs index: Changed "Installation" link to "Quick Start" for better UX

Implementation Details

  • All type assertions now use proper TypeScript inference or explicit type annotations
  • Error handling improved with specific error type definitions instead of generic any
  • Regex patterns reviewed and optimized to prevent ReDoS vulnerabilities
  • Type safety maintained throughout while improving code clarity and maintainability

https://claude.ai/code/session_01N5cEyCdZeuFrMLbqeeDqM7

- Make ESLint stricter: convert warnings to errors for explicit-any and
  explicit-function-return-type rules
- Replace 60+ explicit `any` types with proper typed interfaces
- Add missing return types to functions across the codebase
- Fix unsafe regex patterns to prevent ReDoS vulnerabilities
- Replace non-null assertions with optional chaining/nullish coalescing
- Fix broken link in docs/index.md (README.md#installation → #quick-start)
- Update packages: svelte 5.48.5, happy-dom 20.4.0, @types/node 25.1.0,
  @sveltejs/kit 2.50.1
- Remove deprecated @types/dompurify (dompurify includes own types now)
- Fix Vitest 4 deprecation: move poolOptions to top-level vmThreads config
- Disable security/detect-object-injection (false positives on typed objects)
- Disable security/detect-non-literal-regexp (intentional for search)

All 541 tests pass. Build succeeds with 0 errors.
Only 5 remaining warnings are intentional @html tags (sanitized with DOMPurify).

https://claude.ai/code/session_01N5cEyCdZeuFrMLbqeeDqM7
Move all types from centralized types.ts files to the code that uses them:

Components:
- ScreenshotImageProps → ScreenshotImage.svelte
- Remove unused prop interfaces (DocsSidebarProps, DocsHubProps, etc.)
- Import DocsSection directly from navigation utils

Generators:
- CategoryRule, EnrichmentRule, MarkdownTemplate, ParserConfig,
  GeneratorConfig, GeneratorStats, GeneratorResult → generic-generator.ts
- ParsedItem, Parser → parsers/index.ts
- Fix ParsedItem from `any` to `Record<string, unknown>`

Server:
- ScreenshotRequest, ScreenshotResponse → screenshot-service.ts
- DocPage, DocsLoader, MarkdownRenderer → server/index.ts

Deleted files:
- src/lib/components/types.ts
- src/lib/generators/types.ts
- src/lib/generators/parsers/types.ts
- src/lib/server/types.ts

https://claude.ai/code/session_01N5cEyCdZeuFrMLbqeeDqM7
@mudcube mudcube merged commit 6ea5648 into main Jan 29, 2026
2 of 3 checks passed
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.

3 participants